]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Use a counter instead of a Boolean to check for initialized; n calls
authorGuido van Rossum <guido@python.org>
Wed, 20 Aug 1997 22:40:18 +0000 (22:40 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 20 Aug 1997 22:40:18 +0000 (22:40 +0000)
to Py_Initialize will be undone by n calls to Py_Uninitialize.

Demo/pysvr/pysvr.c
Python/pythonrun.c

index c651648362cb632f2fedd3920836e006458d662f..b1397c9615c261ecc6afba46be127b89bad0db49 100644 (file)
@@ -168,6 +168,7 @@ main_thread(int port)
                PyEval_AcquireThread(gtstate);
                gtstate = NULL;
                Py_Finalize();
+               Py_Finalize();
        }
        exit(0);
 }
@@ -213,6 +214,7 @@ init_python()
        if (gtstate)
                return;
        Py_Initialize(); /* Initialize the interpreter */
+       Py_Initialize(); /* Initialize the interpreter */
        PyEval_InitThreads(); /* Create (and acquire) the interpreter lock */
        gtstate = PyEval_SaveThread(); /* Release the thread state */
 }
index 4d641146712c4aedca5a900dfc5e6409c0ef5785..9f977f05b43247056aa25a667cc3c9127afe552d 100644 (file)
@@ -98,9 +98,8 @@ Py_Initialize()
        PyObject *bimod, *sysmod;
        char *p;
 
-       if (initialized)
-               Py_FatalError("Py_Initialize: already initialized");
-       initialized = 1;
+       if (++initialized > 1)
+               return;
        
        if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
                Py_DebugFlag = 1;
@@ -166,9 +165,10 @@ Py_Finalize()
 
        call_sys_exitfunc();
 
-       if (!initialized)
+       if (--initialized > 0)
+               return;
+       if (initialized < 0)
                Py_FatalError("Py_Finalize: not initialized");
-       initialized = 0;
 
        tstate = PyThreadState_Get();
        interp = tstate->interp;