diff options
Diffstat (limited to 'source/blender/python/generic/bpy_internal_import.c')
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index c41ea386c0e..05c846b16f5 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -65,6 +65,11 @@ PyObject *bpy_text_import( char *name, int *found ) Main *maggie= bpy_import_main; *found= 0; + + if(!maggie) { + printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); + return NULL; + } if (namelen>21-3) return NULL; /* we know this cant be importable, the name is too long for blender! */ @@ -106,12 +111,17 @@ PyObject *bpy_text_import( char *name, int *found ) PyObject *bpy_text_reimport( PyObject *module, int *found ) { Text *text; - char *txtname; - char *name; + const char *txtname; + const char *name; char *buf = NULL; //XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main; Main *maggie= bpy_import_main; + if(!maggie) { + printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); + return NULL; + } + *found= 0; /* get name, filename from the module itself */ @@ -156,7 +166,7 @@ PyObject *bpy_text_reimport( PyObject *module, int *found ) } /* make into a module */ - return PyImport_ExecCodeModule( name, text->compiled ); + return PyImport_ExecCodeModule( (char *)name, text->compiled ); } @@ -169,20 +179,12 @@ static PyObject *blender_import( PyObject * self, PyObject * args, PyObject * k PyObject *newmodule; //PyObject_Print(args, stderr, 0); -#if (PY_VERSION_HEX >= 0x02060000) int dummy_val; /* what does this do?*/ static char *kwlist[] = {"name", "globals", "locals", "fromlist", "level", 0}; if( !PyArg_ParseTupleAndKeywords( args, kw, "s|OOOi:bpy_import_meth", kwlist, &name, &globals, &locals, &fromlist, &dummy_val) ) return NULL; -#else - static char *kwlist[] = {"name", "globals", "locals", "fromlist", 0}; - - if( !PyArg_ParseTupleAndKeywords( args, kw, "s|OOO:bpy_import_meth", kwlist, - &name, &globals, &locals, &fromlist ) ) - return NULL; -#endif /* import existing builtin modules or modules that have been imported alredy */ newmodule = PyImport_ImportModuleEx( name, globals, locals, fromlist ); @@ -263,8 +265,8 @@ static PyObject *blender_reload( PyObject * self, PyObject * args ) return newmodule; } -PyMethodDef bpy_import_meth[] = { {"bpy_import_meth", blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"} }; -PyMethodDef bpy_reload_meth[] = { {"bpy_reload_meth", blender_reload, METH_VARARGS, "blenders reload"} }; +PyMethodDef bpy_import_meth[] = { {"bpy_import_meth", (PyCFunction)blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"} }; +PyMethodDef bpy_reload_meth[] = { {"bpy_reload_meth", (PyCFunction)blender_reload, METH_VARARGS, "blenders reload"} }; /* Clear user modules. |