summaryrefslogtreecommitdiffstats
path: root/Modules/gcmodule.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-04-06 23:30:52 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-04-06 23:30:52 (GMT)
commit1155887a74a5a4062614c4ee5a6f91f2d0198f75 (patch)
tree91372036eb6ae675ba569573a71080bebe7ad273 /Modules/gcmodule.c
parent259272b7a0edaf06b1a70379e74907ae4166c67e (diff)
downloadcpython-1155887a74a5a4062614c4ee5a6f91f2d0198f75.zip
cpython-1155887a74a5a4062614c4ee5a6f91f2d0198f75.tar.gz
cpython-1155887a74a5a4062614c4ee5a6f91f2d0198f75.tar.bz2
initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size.
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r--Modules/gcmodule.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 36e53ec..bf56cd4 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -973,32 +973,29 @@ void
initgc(void)
{
PyObject *m;
- PyObject *d;
m = Py_InitModule4("gc",
GcMethods,
gc__doc__,
NULL,
PYTHON_API_VERSION);
- d = PyModule_GetDict(m);
+
if (garbage == NULL) {
garbage = PyList_New(0);
+ if (garbage == NULL)
+ return;
}
- PyDict_SetItemString(d, "garbage", garbage);
- PyDict_SetItemString(d, "DEBUG_STATS",
- PyInt_FromLong(DEBUG_STATS));
- PyDict_SetItemString(d, "DEBUG_COLLECTABLE",
- PyInt_FromLong(DEBUG_COLLECTABLE));
- PyDict_SetItemString(d, "DEBUG_UNCOLLECTABLE",
- PyInt_FromLong(DEBUG_UNCOLLECTABLE));
- PyDict_SetItemString(d, "DEBUG_INSTANCES",
- PyInt_FromLong(DEBUG_INSTANCES));
- PyDict_SetItemString(d, "DEBUG_OBJECTS",
- PyInt_FromLong(DEBUG_OBJECTS));
- PyDict_SetItemString(d, "DEBUG_SAVEALL",
- PyInt_FromLong(DEBUG_SAVEALL));
- PyDict_SetItemString(d, "DEBUG_LEAK",
- PyInt_FromLong(DEBUG_LEAK));
+ if (PyModule_AddObject(m, "garbage", garbage) < 0)
+ return;
+#define ADD_INT(NAME) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) return
+ ADD_INT(DEBUG_STATS);
+ ADD_INT(DEBUG_COLLECTABLE);
+ ADD_INT(DEBUG_UNCOLLECTABLE);
+ ADD_INT(DEBUG_INSTANCES);
+ ADD_INT(DEBUG_OBJECTS);
+ ADD_INT(DEBUG_SAVEALL);
+ ADD_INT(DEBUG_LEAK);
+#undef ADD_INT
}
/* for debugging */