[Python-Dev] C new-style classes and GC (original) (raw)
Guido van Rossum guido@python.org
Sun, 18 May 2003 15:02:55 -0400
- Previous message: [Python-Dev] Re: C new-style classes and GC
- Next message: [Python-Dev] Re: C new-style classes and GC
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
PEP 253 may be partly out of date here -- or not. In the section on creating a subclassable type, it says:
""" The base type must do the following: - Add the flag value PyTPFLAGSBASETYPE to tpflags. - Declare and use tpnew(), tpalloc() and optional tpinit() slots. - Declare and use tpdealloc() and tpfree(). - Export its object structure declaration. - Export a subtyping-aware type-checking macro. """ This doesn't leave a choice about defining tpalloc() or tpfree() -- it says both are required. For a subclassable type, I believe both must actually be implemented too. For a non-subclassable type, I expect they're optional. But if you don't define tpfree in that case, then I believe you must also not do the obj->obtype->tpfree(obj) business in the tpdealloc slot (else it will segfault).
PyType_Ready() inherits tp_free from the base class, so it's optional.
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Re: C new-style classes and GC
- Next message: [Python-Dev] Re: C new-style classes and GC
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]