Update of /cvsroot/mahogany/M/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv25926/src/Python

Modified Files:
        InitPython.cpp PythonDll.cpp 
Log Message:
call Py_Finalize() to avoid memory leak reports when using Python

Index: InitPython.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/Python/InitPython.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -b -u -2 -r1.38 -r1.39
--- InitPython.cpp      12 Jan 2004 17:48:28 -0000      1.38
+++ InitPython.cpp      13 Jan 2004 23:40:24 -0000      1.39
@@ -44,5 +44,8 @@
 PyObject *Python_MinitModule = NULL;
 
-// returns TRUE if no error, FALSE if a Python error occured. In the last case
+// had Python been initialized? (MT ok as only used by the main thread)
+static bool gs_isPythonInitialized = false;
+
+// returns true if no error, false if a Python error occured. In the last case
 // an appropriate error message is logged.
 static bool CheckPyError()
@@ -52,12 +55,12 @@
       ERRORMESSAGE((_T("%s"), PythonGetErrorMessage().c_str()));
 
-      return FALSE;
+      return false;
    }
 
    // no error
-   return TRUE;
+   return true;
 }
 
-bool
+extern bool
 InitPython(void)
 {
@@ -124,7 +127,4 @@
    putenv((char *)pythonPathNew.c_str());
 
-   // initialise the interpreter - this we do always, just to avoid problems
-   Py_Initialize();
-
    if ( !READ_CONFIG(mApplication->GetProfile(), MP_USEPYTHON) )
    {
@@ -133,4 +133,8 @@
    }
 
+   // initialise the interpreter -- this we do always, just to avoid problems
+   Py_Initialize();
+   gs_isPythonInitialized = true;
+
    // initialise the modules
    init_HeaderInfo();
@@ -142,5 +146,5 @@
 
    // the return code
-   bool rc = TRUE;
+   bool rc = true;
 
    // run the init script
@@ -151,5 +155,5 @@
       ERRORMESSAGE(("Python: Cannot find/evaluate Minit.py initialisation script."));
 
-      rc = FALSE;
+      rc = false;
    }
    else
@@ -170,5 +174,5 @@
          ERRORMESSAGE(("Python: Cannot find Minit.Minit function in Minit module."));
 
-         rc = FALSE;
+         rc = false;
       }
    }
@@ -183,4 +187,19 @@
 }
 
+extern
+void FreePython()
+{
+   if ( gs_isPythonInitialized )
+   {
+      Py_Finalize();
+
+      gs_isPythonInitialized = false;
+   }
+
+#ifdef USE_PYTHON_DYNAMIC
+   FreePythonDll();
+#endif // USE_PYTHON_DYNAMIC
+}
+
 #endif // USE_PYTHON
 

Index: PythonDll.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/Python/PythonDll.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -b -u -2 -r1.13 -r1.14
--- PythonDll.cpp       6 Jan 2004 00:24:17 -0000       1.13
+++ PythonDll.cpp       13 Jan 2004 23:40:24 -0000      1.14
@@ -58,4 +58,8 @@
 extern "C"
 {
+   // startup/shutdown
+   void(*M_Py_Initialize)(void) = NULL;
+   void(*M_Py_Finalize)(void) = NULL;
+
    // errors
    //int(*M_PyErr_BadArgument)(void) = NULL;
@@ -122,5 +126,4 @@
    PyObject*(*M_Py_FindMethod)(PyMethodDef[], PyObject *, char *) = NULL;
    PyObject*(*M_Py_InitModule4)(char *, PyMethodDef *, char *, PyObject *, int) = 
NULL;
-   void(*M_Py_Initialize)(void) = NULL;
    PyObject *(*M_PyEval_CallObjectWithKeywords)(PyObject *, PyObject *, PyObject *) = 
NULL;
    PyObject *(*M_PyFloat_FromDouble)(double) = NULL;
@@ -165,4 +168,8 @@
 } pythonFuncs[] =
 {
+   // startup/shutdown
+   PYTHON_FUNC(Py_Initialize)
+   PYTHON_FUNC(Py_Finalize)
+
    // errors
    PYTHON_FUNC(PyErr_Clear)
@@ -201,5 +208,4 @@
 
    // ...
-   PYTHON_FUNC(Py_Initialize)
    PYTHON_FUNC(_Py_NoneStruct)
    PYTHON_FUNC_ALT(Py_InitModule4, Py_InitModule4TraceRefs)



-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to