[Python-Dev] another Py_TPFLAGS_HEAPTYPE question (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Mon Aug 17 08:53:56 CEST 2009


Thanks for the pointer. I noticed that subtypedealloc is only called for types that are allocated using typenew(). Does this mean that it is not safe to create types in C using just PyTypeReady() and set PyTPFLAGSHEAPTYPE on them? The documentation is not clear on this point.

As Benjamin says, this is getting off-topic - python-dev is not a place to ask for help in your project.

I believe setting flags on a type is inherently unsafe.

Here is what I would like to do when I create my types dynamically:

- implement tpalloc and tpdealloc() to INCREF and DECREF the type. - not set PyTPFLAGSHEAPTYPE. - set PyTPFLAGSHAVEGC (because instances of my obj can create cycles) Does this seem safe? I notice that subtypedealloc() does some funky GC/trashcan stuff. Is it safe for me not to call subtypedealloc? Can I safely implement my tpdealloc function like this?

If you bypass documented API, you really need to study the code, understand its motivation, judge whether certain usage is "safe" wrt. to the current implementation, and judge the likelihood of this code not getting changed in future versions.

Regards, Martin



More information about the Python-Dev mailing list