Carl Banks <pavlovevide...@gmail.com> writes: > Unfortunately, references on the stack would need to be registered > as well, so "PyObject* p;" might have to be replaced with something > like "Py_DECLARE_REF(PyObject,p);" which magically registers it. > Ugly.
Not only registered at the beginning of the function, but also (since CPython uses C, not C++) explicitly unregistered at every point of exit from the function. Emacs implements these as macros called GCPRO and UNGCPRO, and they're very easy to get wrong. In a way, they are even worse than the current Python INCREF/DECREF. See description at, for example, http://www.xemacs.org/Documentation/beta/html/internals_19.html#SEC78 -- http://mail.python.org/mailman/listinfo/python-list