New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get some minimal cdef classes working with Py_LIMITED_API
#5617
Get some minimal cdef classes working with Py_LIMITED_API
#5617
Conversation
Py_LIMITED_API
Py_LIMITED_API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me overall.
@@ -6582,6 +6585,8 @@ def attribute_is_likely_method(attr): | |||
code.putln("%s = 1;" % arg_offset_cname) | |||
code.putln("}") | |||
code.putln("}") | |||
code.putln("#endif") # CYTHON_UNPACK_METHODS | |||
# TODO may need to deal with unused variables in the #else case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's why I used a simple if
statement instead of #if
. At least we're not creating section specific temps here, so it should be possible to fake the variable usage.
Cython/Compiler/ModuleNode.py
Outdated
code.putln("#if !CYTHON_USE_TYPE_SLOTS && !CYTHON_COMPILING_IN_PYPY") | ||
# Asking for PyType_GetSlot(..., Py_tp_free) seems to cause an error in pypy | ||
code.putln("freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free);") | ||
code.putln("if (tp_free) tp_free(o);") | ||
code.putln("#else") | ||
code.putln("(*Py_TYPE(o)->tp_free)(o);") | ||
code.putln("#endif") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to spell both implementations, here and above, in the same order. I'd reverse the conditions here, not above. It seems more natural to spell out the specific cases followed by the generic fallback.
Cython/Utility/ModuleSetupCode.c
Outdated
#define CYTHON_USE_TP_FINALIZE 1 | ||
#define CYTHON_USE_TP_FINALIZE 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm … does this not work with PyType_GetSlot()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's PyObject_CallFinalizerFromDealloc
. I don't think we can easily replace that using the tools in the limited API, but I'll add an explanatory comment here so it's at least clear what's missing.
1ff67d3 Comments from review
The second part of your change would be clearer if you moved the CYTHON_AVOID_BORROWED_REFS case first. Then it would align nicely with the DECREF condition (and avoid harder to follow this-but-not-that conditions).
|
Nice! |
(A good chunk of these changes are actually to do with the auto-generated pickling functions for an empty class)