diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-03-23 17:52:28 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-03-23 17:52:28 (GMT) |
commit | 7571a0fbcf6fd5d6014008f566f970c84cff7d95 (patch) | |
tree | 4d9d82af5dc1b2aa4b51a89648dce4c188c237f5 /Python/bltinmodule.c | |
parent | a16b21fb0ab25e4cbe54fe0a39da5e448f3d44cb (diff) | |
download | cpython-7571a0fbcf6fd5d6014008f566f970c84cff7d95.zip cpython-7571a0fbcf6fd5d6014008f566f970c84cff7d95.tar.gz cpython-7571a0fbcf6fd5d6014008f566f970c84cff7d95.tar.bz2 |
Improved new Py_TRACE_REFS gimmicks.
Arranged that all the objects exposed by __builtin__ appear in the list
of all objects. I basically peed away two days tracking down a mystery
leak in sys.gettotalrefcount() in a ZODB app (== tons of code), because
the object leaking the references didn't appear in the sys.getobjects(0)
list. The object happened to be False. Now False is in the list, along
with other popular & previously missing leak candidates (like None).
Alas, we still don't have a choke point covering *all* Python objects,
so the list of all objects may still be incomplete.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index e246591..29e11e5 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1818,9 +1818,22 @@ _PyBuiltin_Init(void) return NULL; dict = PyModule_GetDict(mod); +#ifdef Py_TRACE_REFS + /* __builtin__ exposes a number of statically allocated objects + * that, before this code was added in 2.3, never showed up in + * the list of "all objects" maintained by Py_TRACE_REFS. As a + * result, programs leaking references to None and False (etc) + * couldn't be diagnosed by examining sys.getobjects(0). + */ +#define ADD_TO_ALL(OBJECT) _Py_AddToAllObjects((PyObject *)(OBJECT), 0) +#else +#define ADD_TO_ALL(OBJECT) (void)0 +#endif + #define SETBUILTIN(NAME, OBJECT) \ - if (PyDict_SetItemString(dict, NAME, (PyObject *)OBJECT) < 0) \ - return NULL + if (PyDict_SetItemString(dict, NAME, (PyObject *)OBJECT) < 0) \ + return NULL; \ + ADD_TO_ALL(OBJECT) SETBUILTIN("None", Py_None); SETBUILTIN("Ellipsis", Py_Ellipsis); @@ -1864,6 +1877,7 @@ _PyBuiltin_Init(void) Py_XDECREF(debug); return mod; +#undef ADD_TO_ALL #undef SETBUILTIN } |