[Python-Dev] A little GC confusion

Michael Hudson mwh@python.net
21 Feb 2002 13:47:56 +0000


Kevin Jacobs <jacobs@penguin.theopalgroup.com> writes:
> I doesn't have any time to really look at your code, but I thought I'd point
> out a trick that several extension modules use to protect statically
> allocated type objects. Here is the code from socketmodule.c:
>> /* static PyTypeObject PySocketSock_Type = {
> .
> .
> .
> 0, /* set below */ /* tp_alloc */
> PySocketSock_new, /* tp_new */
> 0, /* set below */ /* tp_free */
> };
>> /* buried in init_socket */
> PySocketSock_Type.tp_alloc = PyType_GenericAlloc;
> PySocketSock_Type.tp_free = _PyObject_Del;
>> This trick ensures that the static type object is never freed.

Um, I think you'll find this is because PyType_GenericAlloc &
_PyObject_Del aren't compile-time constants when _socket is
dynamically linked (they're defined in a different dll).
Cheers,
M.
-- 
 > so python will fork if activestate starts polluting it?
 I find it more relevant to speculate on whether Python would fork
 if the merpeople start invading our cities riding on the backs of 
 giant king crabs. -- Brian Quinlan, comp.lang.python

AltStyle によって変換されたページ (->オリジナル) /