summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-04-26 05:34:03 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2006-04-26 05:34:03 +0000
commit57a0361a9e70268fd3299482284bbcf71ea7642f (patch)
tree4d8e0c0555ef01f96f52e48a787265689bf026f9
parenta5f1fd09eb159891313ea5a777b44fc664abdcf1 (diff)
downloadcpython-git-57a0361a9e70268fd3299482284bbcf71ea7642f.tar.gz
Patch from Aldo Cortesi (OpenBSD buildbot owner).
After the patch (45590) to add extra debug stats to the gc module, Python was crashing on OpenBSD due to: Fatal Python error: Interpreter not initialized (version mismatch?) This seems to occur due to calling collect() when initialized (in pythonrun.c) is set to 0. Now, the import will occur in the init function which shouldn't suffer this problem.
-rw-r--r--Modules/gcmodule.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 0176d6f6f8..6ff2c9a1aa 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -75,6 +75,7 @@ static PyObject *delstr = NULL;
DEBUG_OBJECTS | \
DEBUG_SAVEALL
static int debug;
+static PyObject *tmod = NULL;
/*--------------------------------------------------------------------------
gc_refs values.
@@ -734,7 +735,6 @@ collect(int generation)
PyGC_Head unreachable; /* non-problematic unreachable trash */
PyGC_Head finalizers; /* objects with, & reachable from, __del__ */
PyGC_Head *gc;
- static PyObject *tmod = NULL;
double t1 = 0.0;
if (delstr == NULL) {
@@ -743,12 +743,6 @@ collect(int generation)
Py_FatalError("gc couldn't allocate \"__del__\"");
}
- if (tmod == NULL) {
- tmod = PyImport_ImportModule("time");
- if (tmod == NULL)
- PyErr_Clear();
- }
-
if (debug & DEBUG_STATS) {
if (tmod != NULL) {
PyObject *f = PyObject_CallMethod(tmod, "time", NULL);
@@ -1233,6 +1227,19 @@ initgc(void)
Py_INCREF(garbage);
if (PyModule_AddObject(m, "garbage", garbage) < 0)
return;
+
+ /* Importing can't be done in collect() because collect()
+ * can be called via PyGC_Collect() in Py_Finalize().
+ * This wouldn't be a problem, except that <initialized> is
+ * reset to 0 before calling collect which trips up
+ * the import and triggers an assertion.
+ */
+ if (tmod == NULL) {
+ tmod = PyImport_ImportModule("time");
+ if (tmod == NULL)
+ PyErr_Clear();
+ }
+
#define ADD_INT(NAME) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) return
ADD_INT(DEBUG_STATS);
ADD_INT(DEBUG_COLLECTABLE);