[Cython] Surprising behaviour wrt. generated tp_clear and tp_dealloc functions

Stefan Behnel stefan_ml at behnel.de
Sun Jul 14 10:39:47 CEST 2013


Torsten Landschoff, 11.07.2013 00:10:
> I attached my current (trivial) patch. Currently I only support a decorator
> 
>     @cython.noclear
>     cdef class ...
> 
> to inhibit generation of tp_clear.

Thanks, looks ok to me. Please open a pull request on github for it.


> Before I continue with this approach I am wondering about the API. Is
> noclear usable as a name? I think not because nobody will know what it
> is talking about.

I think that name is as good as any. It could be "no_gc_clear", if you find
that clearer. It hints at GC, at least. I think that should be part of the
name somehow.

Please also document it somewhere in the extension types doc section (in
the user guide):

https://github.com/cython/cython/blob/master/docs/src/userguide/extension_types.rst


> But I do not know how to press the information "do not generate the
> tp_clear slot which will clear references to break reference cycles
> during GC" into a short name.

It doesn't have to say it all, especially since it's a very special purpose
thing. Eventually, Cython should be able to reduce the need even further,
so users will only have to apply it when they already know that they need
it. The docs should answer the question "is there a way to do this?"


> How should the decorator to completely disable GC for a class be called?
> @cython.nogc?

+1

People who apply it will already have to know the difference between
reference counting and cyclic garbage collection, otherwise, they wouldn't
even know why to use it.


> @cython.refcounted (because the class will only support
> cleanup via reference counting)?

No, all Python objects are ref-counted.

Stefan



More information about the cython-devel mailing list