--- mod_python_orig.c Fri Sep 2 13:17:37 2005 +++ mod_python_patched.c Fri Sep 2 13:27:39 2005 @@ -149,6 +149,7 @@ idata->obcallback = NULL; p = PyCObject_FromVoidPtr((void *) idata, NULL); PyDict_SetItemString(interpreters, (char *)name, p); + Py_DECREF(p); } } else { @@ -517,10 +518,6 @@ /* create and acquire the interpreter lock */ PyEval_InitThreads(); #endif - /* Release the thread state because we will never use - * the main interpreter, only sub interpreters created later. */ - PyThreadState_Swap(NULL); - /* create the obCallBack dictionary */ interpreters = PyDict_New(); if (! interpreters) { @@ -529,6 +526,25 @@ exit(1); } + { + /* + Workaround for "PEP 311 - Simplified Global Interpreter + Lock Acquisition for Extensions" + */ + PyObject *p = 0; + interpreterdata * idata = (interpreterdata *)malloc(sizeof(interpreterdata)); + PyThreadState* currentThreadState = PyThreadState_Get(); + PyInterpreterState *istate = currentThreadState->interp; + idata->istate = istate; + /* obcallback will be created on first use */ + idata->obcallback = NULL; + p = PyCObject_FromVoidPtr((void *) idata, NULL); + PyDict_SetItemString(interpreters, MAIN_INTERPRETER, p); + Py_DECREF(p); + } + + PyThreadState_Swap(NULL); + #ifdef WITH_THREAD /* release the lock; now other threads can run */ PyEval_ReleaseLock(); @@ -598,9 +614,6 @@ return conf; } -/* -code begin -*/ /** ** modpython_table_overlap ** @@ -694,11 +707,6 @@ return (void *) merged_conf; } - -/* -code end -*/ - /** ** python_directive