Repository navigation
RFC: restrict cosmology extension modules to CPython's Limited API - #18261
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
👋 Thank you for your draft pull request! Do you know that you can use |
|
Build seems completely broken on CI but somehow works on my machine, talk about a disapointment... let me see what's gone wrong |
|
Looks like I broke runtime when I fixed build time 🙈 |
| Py_INCREF(self); | ||
| return self; | ||
| } | ||
| return PyMethod_New(self, obj); |
There was a problem hiding this comment.
It is possible to replace this. I'd use Cython's implementation as a starting point https://github.com/cython/cython/blob/dba606bc50e90dbaf37850779d1f84f1c0a22c7a/Cython/Utility/ObjectHandling.c#L2977
Essentially we look-up the method type in types.MethodType, cache it (for speed) and then call it as a Python object.
I think you do need to provide this code, however you really don't want this code to actually be called - it's very slow.
What you want to do (in addition) is to set the Py_TPFLAGS_METHOD_DESCRIPTOR type-flag on the type. This means that Python can usually avoid going through the __get__ code. I don't think you'll have to change your call code at all - just set the flag.
The Limited API code is probably bad enough here to be worth keeping the old version and guarding it with #if !defined(Py_LIMITED_API)
There was a problem hiding this comment.
Cython does some opaque stuff in its utility code that I think you're struggling to see through. I can give more detailed instructions (i.e. the exact code where it needs to be) later today if that helps.
There was a problem hiding this comment.
yes, I was just about to ask actually. That would be tremendously helpful, thank you !
nstarman
left a comment
There was a problem hiding this comment.
I don't know enough C to meaningfully review this. But I trust y'all 😰 😆
0a9d98a to
f1cb13b
Compare
da-woods
left a comment
There was a problem hiding this comment.
Suggestions aren't tested so there may be small typos, but hopefully should be very close to working.
e87f8c8 to
9e4da2d
Compare
|
Fantastic, thanks a lot @da-woods, I couldn't have done this without your help ! |
|
@nstarman do you want to formally approve this one, or would you like a second opinion ? |
|
2nd opinion plz. |
|
Who can we ask a review from ? I think David has more expertise there than most (all ?) of us (combined ? 😅) |
da-woods
left a comment
There was a problem hiding this comment.
One change and a couple of things that might be fixed as follow ups. But it looks good to me. Although I'm not the most impartial on this.
|
|
||
| PyObject *since_unicode = PyObject_Str(self->since); | ||
| const char* since_utf8 = PyUnicode_AsUTF8(since_unicode); | ||
| const char* since_utf8 = PyUnicode_AsUTF8AndSize(since_unicode, NULL); |
There was a problem hiding this comment.
Propably something for a follow-up PR rather than to fix here, but I think that you could save a lot of this by using PyErr_WarnFormat later. (Unless I'm missing something which is completely possible...)
There was a problem hiding this comment.
This module was my very first experience using Python's C-API and isn't really polished in any way. In any case it's also temporary code that we'll soon get rid of anyway, so it doesn't matter much if the slow path is sub-optimal.
There was a problem hiding this comment.
Fair enough - that seems reasonable to leave as is then
| {Py_tp_members, depr_kws_wrap_members}, | ||
| {Py_tp_call, (ternaryfunc)depr_kws_wrap_call}, | ||
| {Py_tp_descr_get, depr_kws_wrap_get}, | ||
| {0, NULL}, |
There was a problem hiding this comment.
Again, something for a follow-up PR since it's not a new problem, but this type looks like it needs GC.
There was a problem hiding this comment.
Do you mean I should set Py_TPFLAGS_HAVE_GC (and abide the contract that comes with it) ?
There was a problem hiding this comment.
Yes I think so. It looks like the type has a dict and I think wrapped is an arbitrary Python callable, so I think it can participate in reference loops.
This doesn't change with the Limited API though, so personally I'd do it separately.
There was a problem hiding this comment.
Fine with me. Thanks for the tip !
3ea6406 to
2476a79
Compare
mhvk
left a comment
There was a problem hiding this comment.
Thought I might as well look at this one too - another possible wrong DECREF, but otherwise would seem to make sense.
|
@mhvk I'm not seeing the specific comment you're alluding to. Did you forget to submit it ? |
Co-authored-by: da-woods <[email protected]>
2476a79 to
cb04af7
Compare
mhvk
left a comment
There was a problem hiding this comment.
Approving since my one comment turned out to be based on a misunderstanding.
Description
Ref #18163
This should be the last (non-infrastructural) missing piece (!)