[Python-Dev] 2.4.4: backport classobject.c HAVE_WEAKREFS?
Fredrik Lundh
fredrik at pythonware.com
Wed Oct 11 12:35:23 CEST 2006
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;
...
NoddyType = PyType_Setup("noddy.Noddy", sizeof(Noddy));
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;
(a preprocessor that generated this based on suitable "macro decorators" could
be implemented in just over 8 lines of Python...)
with this in place, we could simply remove all those silly NULL checks from the
interpreter.
</F>
More information about the Python-Dev
mailing list