fix for 2 python refcounting errors

This commit is contained in:
Campbell Barton 2008-09-03 23:51:55 +00:00
parent 19d5a5da45
commit 961a26d500
2 changed files with 8 additions and 9 deletions

@ -292,7 +292,7 @@ void syspath_append( char *dirname )
short ok=1; short ok=1;
PyErr_Clear( ); PyErr_Clear( );
dir = Py_BuildValue( "s", dirname ); dir = PyString_FromString( dirname );
mod_sys = PyImport_ImportModule( "sys" ); /* new ref */ mod_sys = PyImport_ImportModule( "sys" ); /* new ref */
@ -308,32 +308,29 @@ void syspath_append( char *dirname )
} }
if (PySequence_Contains(path, dir)==0) { /* Only add if we need to */ if (PySequence_Contains(path, dir)==0) { /* Only add if we need to */
if (ok && PyList_Append( path, dir ) != 0) if (ok && PyList_Append( path, dir ) != 0) /* decref below */
ok = 0; /* append failed */ ok = 0; /* append failed */
if( (ok==0) || PyErr_Occurred( ) ) if( (ok==0) || PyErr_Occurred( ) )
Py_FatalError( "could import or build sys.path, can't continue" ); Py_FatalError( "could import or build sys.path, can't continue" );
} }
Py_DECREF( dir );
Py_XDECREF( mod_sys ); Py_XDECREF( mod_sys );
} }
void init_syspath( int first_time ) void init_syspath( int first_time )
{ {
PyObject *path;
PyObject *mod, *d; PyObject *mod, *d;
char *progname; char *progname;
char execdir[FILE_MAXDIR]; /*defines from DNA_space_types.h */ char execdir[FILE_MAXDIR]; /*defines from DNA_space_types.h */
int n; int n;
path = Py_BuildValue( "s", bprogname );
mod = PyImport_ImportModule( "Blender.sys" ); mod = PyImport_ImportModule( "Blender.sys" );
if( mod ) { if( mod ) {
d = PyModule_GetDict( mod ); d = PyModule_GetDict( mod );
EXPP_dict_set_item_str( d, "progname", path ); EXPP_dict_set_item_str( d, "progname", PyString_FromString( bprogname ) );
Py_DECREF( mod ); Py_DECREF( mod );
} else } else
printf( "Warning: could not set Blender.sys.progname\n" ); printf( "Warning: could not set Blender.sys.progname\n" );

@ -274,7 +274,7 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args)
{ {
char cpath[sizeof(G.sce)]; char cpath[sizeof(G.sce)];
char *searchpath = NULL; char *searchpath = NULL;
PyObject* list; PyObject* list, *value;
DIR *dp; DIR *dp;
struct dirent *dirp; struct dirent *dirp;
@ -300,7 +300,9 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args)
while ((dirp = readdir(dp)) != NULL) { while ((dirp = readdir(dp)) != NULL) {
if (BLI_testextensie(dirp->d_name, ".blend")) { if (BLI_testextensie(dirp->d_name, ".blend")) {
PyList_Append(list, PyString_FromString(dirp->d_name)); value = PyString_FromString(dirp->d_name);
PyList_Append(list, value);
Py_DECREF(value);
} }
} }