Update of /cvsroot/mahogany/M/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25574/src/Python
Modified Files:
InitPython.cpp
Log Message:
don't load anything on stratup if startup module is empty, don't complain if it
doesn't define Init() function; call PyErr_Clear() before Py_Finalize() to fix crash
on unloading Python DLL
Index: InitPython.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/Python/InitPython.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -b -u -2 -r1.40 -r1.41
--- InitPython.cpp 15 Jan 2004 23:09:52 -0000 1.40
+++ InitPython.cpp 18 Sep 2004 19:01:04 -0000 1.41
@@ -1,10 +1,13 @@
-/*-*- c++ -*-********************************************************
- * InitPython.cpp: initialisation of the Python interpreter *
- * *
- * (C) 1998 by Karsten Ball�der ([EMAIL PROTECTED]) *
- * *
- * $Id$
- *
- *******************************************************************/
+///////////////////////////////////////////////////////////////////////////////
+// Project: M
+// File name: InitPython.cpp: initialisation of the Python interpreter
+// Purpose: public InitPython() and FreePython()
+// Author: Karsten Ballueder, Vadim Zeitlin
+// Modified by:
+// Created: 1998
+// CVS-ID: $Id$
+// Copyright: (c) 1998-2004 Mahogany Team
+// Licence: M license
+///////////////////////////////////////////////////////////////////////////////
#include "Mpch.h"
@@ -28,4 +31,5 @@
extern const MOption MP_PYTHONPATH;
+extern const MOption MP_PYTHONMODULE_TO_LOAD;
extern const MOption MP_USEPYTHON;
@@ -42,7 +46,4 @@
}
-/// used by PythonHelp.cc helper functions
-PyObject *Python_MinitModule = NULL;
-
// had Python been initialized? (MT ok as only used by the main thread)
static bool gs_isPythonInitialized = false;
@@ -128,5 +129,5 @@
putenv((char *)pythonPathNew.c_str());
- if ( !READ_CONFIG(mApplication->GetProfile(), MP_USEPYTHON) )
+ if ( !READ_APPCONFIG(MP_USEPYTHON) )
{
// it is not an error to have it disabled
@@ -151,9 +152,14 @@
// run the init script
- Python_MinitModule = PyImport_ImportModule("Minit");
+ String startScript = READ_APPCONFIG(MP_PYTHONMODULE_TO_LOAD);
+
+ if ( !startScript.empty() )
+ {
+ PyObject *moduleInit = PyImport_ImportModule(startScript);
- if( !CheckPyError() || Python_MinitModule == NULL)
+ if ( !CheckPyError() || !moduleInit )
{
- ERRORMESSAGE(("Python: Cannot find/evaluate Minit.py initialisation script."));
+ ERRORMESSAGE(("Cannot load Python module \"%s\".",
+ startScript.c_str()));
rc = false;
@@ -161,20 +167,12 @@
else
{
- Py_INCREF(Python_MinitModule); // keep it in memory
- PyObject *minit = PyObject_GetAttrString(Python_MinitModule, "Minit");
- if(minit)
+ Py_INCREF(moduleInit); // keep it in memory
+ PyObject *minit = PyObject_GetAttrString(moduleInit, "Init");
+ if ( minit )
{
- Py_INCREF(minit);
- PyObject_CallObject(minit,NULL);
+ PyObject_CallObject(minit, NULL);
rc = CheckPyError();
- Py_DECREF(minit);
}
- else
- {
- (void)CheckPyError();
-
- ERRORMESSAGE(("Python: Cannot find Minit.Minit function in Minit module."));
-
- rc = false;
+ //else: no Init() function, ignore it
}
}
@@ -194,4 +192,8 @@
if ( gs_isPythonInitialized )
{
+ // ensure there are no pending errors because otherwise Py_Finalize()
+ // calls abort()
+ PyErr_Clear();
+
Py_Finalize();
-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates