diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2008-06-11 05:26:20 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2008-06-11 05:26:20 (GMT) |
commit | 1a21451b1d73b65af949193208372e86bf308411 (patch) | |
tree | 8e98d7be9e249b011ae9380479656e5284ec0234 /Modules/gcmodule.c | |
parent | cdf94635d7e364f9ce1905bafa5b540f4d16147c (diff) | |
download | cpython-1a21451b1d73b65af949193208372e86bf308411.zip cpython-1a21451b1d73b65af949193208372e86bf308411.tar.gz cpython-1a21451b1d73b65af949193208372e86bf308411.tar.bz2 |
Implement PEP 3121: new module initialization and finalization API.
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r-- | Modules/gcmodule.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index f332231..897590c 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -1192,27 +1192,37 @@ static PyMethodDef GcMethods[] = { {NULL, NULL} /* Sentinel */ }; +static struct PyModuleDef gcmodule = { + PyModuleDef_HEAD_INIT, + "gc", + gc__doc__, + -1, + GcMethods, + NULL, + NULL, + NULL, + NULL +}; + + PyMODINIT_FUNC -initgc(void) +PyInit_gc(void) { PyObject *m; - m = Py_InitModule4("gc", - GcMethods, - gc__doc__, - NULL, - PYTHON_API_VERSION); + m = PyModule_Create(&gcmodule); + if (m == NULL) - return; + return NULL; if (garbage == NULL) { garbage = PyList_New(0); if (garbage == NULL) - return; + return NULL; } Py_INCREF(garbage); if (PyModule_AddObject(m, "garbage", garbage) < 0) - return; + return NULL; /* Importing can't be done in collect() because collect() * can be called via PyGC_Collect() in Py_Finalize(). @@ -1226,13 +1236,14 @@ initgc(void) PyErr_Clear(); } -#define ADD_INT(NAME) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) return +#define ADD_INT(NAME) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) return NULL ADD_INT(DEBUG_STATS); ADD_INT(DEBUG_COLLECTABLE); ADD_INT(DEBUG_UNCOLLECTABLE); ADD_INT(DEBUG_SAVEALL); ADD_INT(DEBUG_LEAK); #undef ADD_INT + return m; } /* API to invoke gc.collect() from C */ |