mark extension types as immutable#5023
mark extension types as immutable#5023da-woods merged 4 commits intocython:masterfrom maxbachmann:immutable
Conversation
|
This leads e.g. to the following issue: I will add a test for this later today. |
|
Ah I probably didn't mean to rely on the mutability. I basically just enabled all the CPython dataclasses tests that seemed to pass. However, Cython dataclasses aren't Python dataclasses so they're allowed to differ in places. I'll revert the specific tests that rely on it. I wasn't sure if immutability should be considered a feature or a side effect (i.e. whether there was a harm in leave things mutable). However, if you can cause segfaults with it so easily then we should definitely keep it. |
|
The dataclass test is easily disabled. The second failing test is to do with setting I think a I think proceed with this PR because we will want to make these immutable again, but fixing up the cases where we(/I) accidentally used mutability won't be instant. |
|
Link 1 #5026 |
via an additional decorator for cdef classes. Closes cython#5027 and removes blocker for cython#5023
|
#5030 solves the remaining blocker for this. It is adding a feature though so I'll be patient and let it be reviewed properly. |
|
@scoder I'd quite like to get this in the next release. It's been a bug for a while but it seems like something to fix before people start relying on the wrong behaviour. It could do with a test - I'll have a go at writing one later today. It's blocked by #5030 (but there's other options if you don't like that - in the short-term just to disable the tests) |
Registering cdef classes with collections.abs.sequence only works to set the type flag if cdef classes are mutable. Unfortunately we want them to be immutable since it's possible to corrupt memory with mutable cdef classes (#5023). Therefore, add a Cython directive for marking cdef classes as a sequence, but only allow it in utility code for now. This is a cutdown version of #5030 - I don't want to add new public features without consensus, but I do want to merge the fix for mutable classes. Therefore I'm adding the feature privately for now.
|
Closing/reopening to rerun tests |
|
Thanks @maxbachmann |
Since python/cpython#25520 types are automatically marked as immutable if they are static.
While we still have the
Py_TPFLAGS_HEAPTYPEhack in place we need to manually mark our types as immutable.