classification
Title: Weak reference support for C function objects
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Anthony.Kong, ezio.melotti, kilowu, pitrou, python-dev, scoder
Priority: normal Keywords: easy, patch

Created on 2014-07-31 17:51 by pitrou, last changed 2014-08-06 23:36 by pitrou. This issue is now closed.

Files
File name Uploaded Description Edit
22116.patch kilowu, 2014-08-02 12:51 review
Messages (10)
msg224432 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-07-31 17:51
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)
msg224541 - (view) Author: Stefan Behnel (scoder) * Date: 2014-08-02 08:37
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.
msg224558 - (view) Author: Wei Wu (kilowu) * Date: 2014-08-02 12:49
I have made a patch related to this issue, please take a look at it. Thanks :)
msg224561 - (view) Author: Stefan Behnel (scoder) * Date: 2014-08-02 13:19
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.
msg224641 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-08-03 14:57
> Wouldn't it be enough to test that one of the builtin functions is now weak referencible?

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.
msg224675 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-08-04 02:41
@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!
msg224692 - (view) Author: Wei Wu (kilowu) * Date: 2014-08-04 07:20
@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.
msg224738 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-08-04 15:45
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!
msg224974 - (view) Author: Roundup Robot (python-dev) Date: 2014-08-06 23:34
New changeset 87f940e85cb0 by Antoine Pitrou in branch 'default':
Issue #22116: C functions and methods (of the 'builtin_function_or_method' type) can now be weakref'ed.  Patch by Wei Wu.
http://hg.python.org/cpython/rev/87f940e85cb0
msg224975 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-08-06 23:36
I have committed your patch. Thank you very much for contributing!
History
Date User Action Args
2014-08-06 23:36:29pitrousetstatus: open -> closed
resolution: fixed
messages: + msg224975

stage: patch review -> resolved
2014-08-06 23:34:49python-devsetnosy: + python-dev
messages: + msg224974
2014-08-04 15:45:14pitrousetmessages: + msg224738
2014-08-04 07:20:58kilowusetmessages: + msg224692
2014-08-04 02:41:55pitrousetmessages: + msg224675
2014-08-04 02:35:17pitrousetstage: test needed -> patch review
2014-08-03 14:57:44pitrousetmessages: + msg224641
2014-08-02 13:19:48scodersetmessages: + msg224561
2014-08-02 12:51:14kilowusetfiles: + 22116.patch
keywords: + patch
2014-08-02 12:49:37kilowusetnosy: + kilowu
messages: + msg224558
2014-08-02 08:37:42scodersetnosy: + scoder
messages: + msg224541
2014-08-02 08:01:04Anthony.Kongsetnosy: + Anthony.Kong
2014-08-01 10:46:28ezio.melottisetnosy: + ezio.melotti

stage: test needed
2014-07-31 20:14:34pitrousetkeywords: + easy
2014-07-31 17:51:31pitroucreate