diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-09-04 03:51:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-09-04 03:51:55 +0400 |
commit | 961a26d50058de81ca27a9465320c0177e5eeeb4 (patch) | |
tree | a7e1857dd8fb463332c15bbf54ce0b0f92813906 | |
parent | 19d5a5da452bf5d07bc9409577141401c1e2e0be (diff) |
fix for 2 python refcounting errors
-rw-r--r-- | source/blender/python/BPY_interface.c | 11 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 6 |
2 files changed, 8 insertions, 9 deletions
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 05ea2d77ab9..05254bca8c0 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -292,7 +292,7 @@ void syspath_append( char *dirname ) short ok=1; PyErr_Clear( ); - dir = Py_BuildValue( "s", dirname ); + dir = PyString_FromString( dirname ); 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 (ok && PyList_Append( path, dir ) != 0) + if (ok && PyList_Append( path, dir ) != 0) /* decref below */ ok = 0; /* append failed */ if( (ok==0) || PyErr_Occurred( ) ) Py_FatalError( "could import or build sys.path, can't continue" ); } + Py_DECREF( dir ); Py_XDECREF( mod_sys ); } void init_syspath( int first_time ) { - PyObject *path; PyObject *mod, *d; char *progname; char execdir[FILE_MAXDIR]; /*defines from DNA_space_types.h */ int n; - - - path = Py_BuildValue( "s", bprogname ); mod = PyImport_ImportModule( "Blender.sys" ); if( 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 ); } else printf( "Warning: could not set Blender.sys.progname\n" ); diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index e9fb0278d76..4b6a38f18c0 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -274,7 +274,7 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args) { char cpath[sizeof(G.sce)]; char *searchpath = NULL; - PyObject* list; + PyObject* list, *value; DIR *dp; struct dirent *dirp; @@ -300,7 +300,9 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args) while ((dirp = readdir(dp)) != NULL) { 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); } } |