diff options
Diffstat (limited to 'source/blender/python/generic/bpy_internal_import.c')
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.c | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index 11f8ff49ffe..a1b99e12e94 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -26,17 +26,27 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include <Python.h> +#include <stddef.h> + +#include "compile.h" /* for the PyCodeObject */ +#include "eval.h" /* for PyEval_EvalCode */ + #include "bpy_internal_import.h" -#include "DNA_text_types.h" #include "MEM_guardedalloc.h" -#include "BKE_text.h" /* txt_to_buf */ -#include "BKE_main.h" -#include "BKE_global.h" /* grr, only for G.sce */ + +#include "DNA_text_types.h" + #include "BLI_listbase.h" #include "BLI_path_util.h" #include "BLI_string.h" -#include <stddef.h> +#include "BLI_utildefines.h" + + /* UNUSED */ +#include "BKE_text.h" /* txt_to_buf */ +#include "BKE_main.h" +#include "BKE_global.h" /* grr, only for G.main->name */ static Main *bpy_import_main= NULL; @@ -61,16 +71,17 @@ void bpy_import_main_set(struct Main *maggie) /* returns a dummy filename for a textblock so we can tell what file a text block comes from */ void bpy_text_filename_get(char *fn, Text *text) { - sprintf(fn, "%s/%s", text->id.lib ? text->id.lib->filepath : G.sce, text->id.name+2); - - /* XXX, this is a bug in python's Py_CompileString()! +#if PY_VERSION_HEX >= 0x03020000 + sprintf(fn, "%s%c%s", text->id.lib ? text->id.lib->filepath : G.main->name, SEP, text->id.name+2); +#else + /* this is a bug in python's Py_CompileString()!, fixed for python 3.2. the string encoding should not be required to be utf-8 - reported: http://bugs.python.org/msg115202 - */ - BLI_utf8_invalid_strip(fn, strlen(fn)); + reported: http://bugs.python.org/msg115202 */ + strcpy(fn, text->id.name+2); +#endif } -PyObject *bpy_text_import( Text *text ) +PyObject *bpy_text_import(Text *text) { char *buf = NULL; char modulename[24]; @@ -191,24 +202,24 @@ PyObject *bpy_text_reimport( PyObject *module, int *found ) } -static PyObject *blender_import( PyObject * self, PyObject * args, PyObject * kw) +static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject * kw) { PyObject *exception, *err, *tb; char *name; int found= 0; PyObject *globals = NULL, *locals = NULL, *fromlist = NULL; - PyObject *newmodule; + int level= -1; /* relative imports */ + PyObject *newmodule; //PyObject_Print(args, stderr, 0); - int dummy_val; /* what does this do?*/ - static char *kwlist[] = {"name", "globals", "locals", "fromlist", "level", 0}; + static const 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) ) + if( !PyArg_ParseTupleAndKeywords(args, kw, "s|OOOi:bpy_import_meth", (char **)kwlist, + &name, &globals, &locals, &fromlist, &level) ) return NULL; /* import existing builtin modules or modules that have been imported already */ - newmodule = PyImport_ImportModuleEx( name, globals, locals, fromlist ); + newmodule= PyImport_ImportModuleLevel(name, globals, locals, fromlist, level); if(newmodule) return newmodule; @@ -244,7 +255,7 @@ static PyObject *blender_import( PyObject * self, PyObject * args, PyObject * k * our reload() module, to handle reloading in-memory scripts */ -static PyObject *blender_reload( PyObject * self, PyObject * module ) +static PyObject *blender_reload(PyObject *UNUSED(self), PyObject * module) { PyObject *exception, *err, *tb; PyObject *newmodule = NULL; @@ -281,8 +292,8 @@ static PyObject *blender_reload( PyObject * self, PyObject * module ) return newmodule; } -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_O, "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_O, "blenders reload"}; /* Clear user modules. |