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
Weak reference support for C function objects #66314
Comments
Currently, it is not possible to take a weakref to a PyCFunction object. However, those objects already have full GC support, so it wouldn't be silly to add weakref support to them. (this came in the context of numba, which generates such C functions on-the-fly) |
FWIW, functions in Cython (which C-level-inherit from PyCFunction) support weak references just fine. Adding that as a general feature to PyCFunction sounds like the right thing to do. |
I have made a patch related to this issue, please take a look at it. Thanks :) |
Patch looks ok. Not sure about the test dependency from test_weakref.py to _testcapi, though. Is that module allowed to be used everywhere? Wouldn't it be enough to test that one of the builtin functions is now weak referencible? "len" seems to be used in other places, for example. |
It's better to check that the weakref gets cleared when the object dies, and for that you need an object you can dispose of. |
@kilowu, your patch looks good to me. As a necessary step to include your contribution, could you please sign the contributor's agreement? See https://www.python.org/psf/contrib/contrib-form/ Thank you very much! |
@pitrou, thank you for the review. I have signed the contributor agreement form after submitting this patch. Please let me know if there is a further step to help you to verify the signed contributor agreement. I'm really glad to have the chance to contribute back to the community. |
Ah, yes, indeed, the agreement seems to have been validated in the meantime (you can see it by the asterisk near your name in the comments here). Thank you! |
New changeset 87f940e85cb0 by Antoine Pitrou in branch 'default': |
I have committed your patch. Thank you very much for contributing! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: