[Python-Dev] Preventing 1.5 extensions crashing under 1.6/2.0 Python

Mark Hammond MarkH@ActiveState.com
Fri, 4 Aug 2000 15:58:52 +1000


[Re forcing all extensions to use PythonExtensionInit_XXX]

> I sort-of like this idea -- at least at the +0 level.

Since this email there have been some strong objections to this.  I too
would weigh in at -1 for this, simply for the amount of work it would cost
me personally!


> Unfortunately we only have two days to get this done for 1.6 -- I plan
> to release 1.6b1 this Friday!  If you don't get to it, prepare a patch
> for 2.0 would be the next best thing.

It is now Friday afternoon for me.  Regardless of the outcome of this, the
patch Fredrik posted recently would still seem reasonable, and not have too
much impact on performance (ie, after locating and loading a .dll/.so, one
function call isnt too bad!):

I've even left his trailing comment, which I agree with too?

Shall this be checked in to the 1.6 and 2.0 trees?

Mark.

Index: Python/modsupport.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/modsupport.c,v
retrieving revision 2.48
diff -u -r2.48 modsupport.c
--- Python/modsupport.c 2000/07/09 03:09:56     2.48
+++ Python/modsupport.c 2000/07/18 07:55:03
@@ -51,6 +51,8 @@
 {
        PyObject *m, *d, *v;
        PyMethodDef *ml;
+       if (!Py_IsInitialized())
+               Py_FatalError("Interpreter not initialized (version
mismatch?)");
        if (module_api_version != PYTHON_API_VERSION)
                fprintf(stderr, api_version_warning,
                        name, PYTHON_API_VERSION, name,
module_api_version);

"Fatal Python error: Interpreter not initialized" might not be too helpful,
but it's surely better than "PyThreadState_Get: no current thread"...