From J.Demeyer at UGent.be Wed Jan 9 09:43:17 2019 From: J.Demeyer at UGent.be (Jeroen Demeyer) Date: Wed, 9 Jan 2019 15:43:17 +0100 Subject: [Cython] Hooking tp_clear() In-Reply-To: <3bd0af8922924b0aa442aef92f886644@xmail103.UGent.be> References: <5B91941C.1080504@UGent.be> <3bd0af8922924b0aa442aef92f886644@xmail103.UGent.be> Message-ID: <5C360885.60406@UGent.be> (reviving this thread after I thought about it some more...) As I mentioned in the original post, I want something like __dealloc__ but with access to a particular cdef attribute (representing a Python object). Since Python attributes of cdef classes may have been cleared by tp_clear, they cannot be accessed in __dealloc__. I suggested hooking tp_clear to do the cleanup but maybe there is a simpler solution: do that cleanup in __dealloc__ anyway but make sure that this specific attribute is not cleared in tp_clear. So really I want something like @cython.no_gc_clear (just found out about that now) but for a specific attribute only. There could be new syntax like cdef class X: cdef no_gc_clear object attr This is a better solution than a blanket @cython.no_gc_clear: in my code, I'm sure that there are no reference cycles involving only that attribute, but there may be reference cycles involving other attributes. This should be fairly easy to implement. Any comments before I submit a PR? Jeroen. From stefan_ml at behnel.de Wed Jan 9 16:12:09 2019 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 9 Jan 2019 22:12:09 +0100 Subject: [Cython] Hooking tp_clear() In-Reply-To: <5C360885.60406@UGent.be> References: <5B91941C.1080504@UGent.be> <3bd0af8922924b0aa442aef92f886644@xmail103.UGent.be> <5C360885.60406@UGent.be> Message-ID: Jeroen Demeyer schrieb am 09.01.19 um 15:43: > (reviving this thread after I thought about it some more...) > > As I mentioned in the original post, I want something like __dealloc__ but > with access to a particular cdef attribute (representing a Python object). > Since Python attributes of cdef classes may have been cleared by tp_clear, > they cannot be accessed in __dealloc__. > > I suggested hooking tp_clear to do the cleanup but maybe there is a simpler > solution: do that cleanup in __dealloc__ anyway but make sure that this > specific attribute is not cleared in tp_clear. > > So really I want something like @cython.no_gc_clear (just found out about > that now) but for a specific attribute only. > > There could be new syntax like > > cdef class X: > ??? cdef no_gc_clear object attr > > This is a better solution than a blanket @cython.no_gc_clear: in my code, > I'm sure that there are no reference cycles involving only that attribute, > but there may be reference cycles involving other attributes. > > This should be fairly easy to implement. Any comments before I submit a PR? I would like to avoid adding Cython specific features that are better served by the general finalisation mechanism of PEP-442. Stefan From J.Demeyer at UGent.be Thu Jan 10 03:41:37 2019 From: J.Demeyer at UGent.be (Jeroen Demeyer) Date: Thu, 10 Jan 2019 09:41:37 +0100 Subject: [Cython] Hooking tp_clear() In-Reply-To: <5a6fad0d2ba44ca79f5e3d6c2908bd60@xmail203.UGent.be> References: <5B91941C.1080504@UGent.be> <3bd0af8922924b0aa442aef92f886644@xmail103.UGent.be> <5C360885.60406@UGent.be> <5a6fad0d2ba44ca79f5e3d6c2908bd60@xmail203.UGent.be> Message-ID: <5C370541.4010606@UGent.be> On 2019-01-09 22:12, Stefan Behnel wrote: > I would like to avoid adding Cython specific features that are better > served by the general finalisation mechanism of PEP-442. That could also be used as argument against @cython.no_gc_clear but we still have that anyway. Second, with PEP-442 you don't have much control over exactly when tp_finalize is called. With tp_dealloc you know for sure that it's called precisely when the object is actually being deallocated (as opposed to planned to be deallocated). For my application, tp_finalize would be too soon: it would put objects in an inconsistent state. And last but not least, PEP-442 doesn't help for Python 2. Jeroen. From stefan_ml at behnel.de Fri Jan 25 02:53:08 2019 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 25 Jan 2019 08:53:08 +0100 Subject: [Cython] =?utf-8?q?More_syntax_warnings_=E2=80=93_a_perfect_task?= =?utf-8?q?_for_a_new_contributor?= Message-ID: Hi all, there is currently a discussion on python-dev about letting the compiler generate more SyntaxWarnings for "obviously unintended" code. https://mail.python.org/pipermail/python-dev/2019-January/156113.html Serhiy Storchaka has written a proof-of-concept patch for CPython here: https://bugs.python.org/issue15248 I think Cython could also be improved in that regard. While we reject a few more things at compile time than CPython's compiler, we tend to be very relaxed about things that seem wrong at compile time and would most likely fail at runtime (but might not get executed). Cython is a much smarter compiler than the one in CPython, and could base such warnings on its much greater knowledge about code and types. This would be an excellent task for someone who wants to start contributing to Cython, because the infrastructure is mostly there and each little warning should be relatively easy to add together with a unit test and is a little, self-contained task all by itself. I created a ticket for it: https://github.com/cython/cython/issues/2814 Anyone interested? Stefan