[Python-Dev] 2.4.4: backport classobject.c HAVE_WEAKREFS?

Nick Coghlan ncoghlan at gmail.com
Fri Oct 13 11:07:12 CEST 2006


Fredrik Lundh wrote:
> Martin v. Löwis wrote:
> 
>> Of course, if everybody would always recompile all extension modules
>> for a new Python feature release, those flags weren't necessary.
> 
> a dynamic registration approach would be even better, with a single entry point
> used to register all methods and hooks your C extension has implemented, and
> code on the other side that builds a properly initialized type descriptor from that
> set, using fallback functions and error stubs where needed.
> 
> e.g. the impossible-to-write-from-scratch NoddyType struct initialization in
> 
>     http://docs.python.org/ext/node24.html
> 
> would collapse to
> 
>     static PyTypeObject NoddyType;

Wouldn't that have to be a pointer to allow the Python runtime complete 
control of the structure size without recompiling the extension?:

     static PyTypeObject *NoddyType;

     NoddyType = PyType_Alloc("noddy.Noddy");
     if (!NoddyType)
         return;
     PyType_Register(NoddyType, PY_TP_DEALLOC, Noddy_dealloc);
     PyType_Register(NoddyType, PY_TP_DOC, "Noddy objects");
     PyType_Register(NoddyType, PY_TP_TRAVERSE, Noddy_traverse);
     PyType_Register(NoddyType, PY_TP_CLEAR, Noddy_clear);
     PyType_Register(NoddyType, PY_TP_METHODS, Noddy_methods);
     PyType_Register(NoddyType, PY_TP_MEMBERS, Noddy_members);
     PyType_Register(NoddyType, PY_TP_INIT, Noddy_init);
     PyType_Register(NoddyType, PY_TP_NEW, Noddy_new);
     if (PyType_Ready(NoddyType) < 0)
         return;

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list