Hi Skip, On Wed, Jun 15, 2005 at 06:35:10AM -0700, [EMAIL PROTECTED] wrote: > Why this worked is a bit mystical. Perhaps it never gets freed because the > object just happens never to be DECREF'd (but that seems unlikely). > /* Add the Dialect type */ > + Py_INCREF(&Dialect_Type); > if (PyModule_AddObject(module, "Dialect", (PyObject *)&Dialect_Type)) > return;
Hum, you probably don't want to know, but it works just fine to forget a Py_INCREF before PyModule_AddObject() for the following reason: 1. the reference is stored in the module's dict, so the object is kept alive from there. 2. after the module initialization code is completed, the import mechanism make a copy of the dict (!) just in case some users wants to reload() the module (!!) in which case the module's dict is simplify overwritten with the copy again (!!!). So there is a reference left to the object from this hidden dict, and no way for the user to kill it -- short of using gc.getreferrers(), which is how I figured this out, but gc.getreferrers() is officially dangerous. So unlike what I thought in my previous e-mail, even if the user deletes the entry in the module's normal dict, nothing bad can happend because of this particular feature of import... So it just works. Hum. Armin _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com