Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-16 10:24:47 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-16 10:24:47 +0400
commit32253dfaaf43751037d4dcabd834e812902d6538 (patch)
treeabfb8cb9689ff2b2d5cf8157662a6ec997176aad /source
parentbbdaa03d6598a6f09e7272ade1ef96abf3ce1d53 (diff)
bpy_internal_import.c should build with py2.3 now, also gave bpy_internal_import functions better names.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/BPY_interface.c6
-rw-r--r--source/blender/python/api2_2x/bpy_internal_import.c33
-rw-r--r--source/blender/python/api2_2x/bpy_internal_import.h10
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp12
4 files changed, 33 insertions, 28 deletions
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c
index 3b539be7a95..ea3d6a54162 100644
--- a/source/blender/python/BPY_interface.c
+++ b/source/blender/python/BPY_interface.c
@@ -1276,7 +1276,7 @@ static int bpy_pydriver_create_dict(void)
* Users can add their own functions to this module. */
if (G.f&G_DOSCRIPTLINKS) {
int found; /* not used but needed as an arg */
- mod = importText("pydrivers", &found); /* can also use PyImport_Import() */
+ mod = bpy_text_import("pydrivers", &found); /* can also use PyImport_Import() */
if (mod) {
PyDict_SetItemString(d, "pydrivers", mod);
PyDict_SetItemString(d, "p", mod);
@@ -2831,7 +2831,7 @@ static void DoAllScriptsFromList( ListBase * list, short event )
static void init_ourImport( void )
{
PyObject *m, *d;
- PyObject *import = PyCFunction_New( bpy_import, NULL );
+ PyObject *import = PyCFunction_New( bpy_import_meth, NULL );
m = PyImport_AddModule( "__builtin__" );
d = PyModule_GetDict( m );
@@ -2842,7 +2842,7 @@ static void init_ourImport( void )
static void init_ourReload( void )
{
PyObject *m, *d;
- PyObject *reload = PyCFunction_New( bpy_reload, NULL );
+ PyObject *reload = PyCFunction_New( bpy_reload_meth, NULL );
m = PyImport_AddModule( "__builtin__" );
d = PyModule_GetDict( m );
diff --git a/source/blender/python/api2_2x/bpy_internal_import.c b/source/blender/python/api2_2x/bpy_internal_import.c
index a62ae689f59..1e1454dcd5c 100644
--- a/source/blender/python/api2_2x/bpy_internal_import.c
+++ b/source/blender/python/api2_2x/bpy_internal_import.c
@@ -56,7 +56,7 @@ void bpy_import_main_set(struct Main *maggie)
}
-PyObject *importText( char *name, int *found )
+PyObject *bpy_text_import( char *name, int *found )
{
Text *text;
char txtname[22]; /* 21+NULL */
@@ -103,7 +103,7 @@ PyObject *importText( char *name, int *found )
* find in-memory module and recompile
*/
-PyObject *reimportText( PyObject *module, int *found )
+PyObject *bpy_text_reimport( PyObject *module, int *found )
{
Text *text;
char *txtname;
@@ -172,13 +172,13 @@ static PyObject *blender_import( PyObject * self, PyObject * args, PyObject * k
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", kwlist,
+ 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", kwlist,
+ if( !PyArg_ParseTupleAndKeywords( args, kw, "s|OOO:bpy_import_meth", kwlist,
&name, &globals, &locals, &fromlist ) )
return NULL;
#endif
@@ -192,7 +192,7 @@ static PyObject *blender_import( PyObject * self, PyObject * args, PyObject * k
PyErr_Fetch( &exception, &err, &tb ); /* get the python error incase we cant import as blender text either */
/* importing from existing modules failed, see if we have this module as blender text */
- newmodule = importText( name, &found );
+ newmodule = bpy_text_import( name, &found );
if( newmodule ) {/* found module as blender text, ignore above exception */
PyErr_Clear( );
@@ -228,7 +228,7 @@ static PyObject *blender_reload( PyObject * self, PyObject * args )
int found= 0;
/* check for a module arg */
- if( !PyArg_ParseTuple( args, "O:bpy_reload", &module ) )
+ if( !PyArg_ParseTuple( args, "O:bpy_reload_meth", &module ) )
return NULL;
/* try reimporting from file */
@@ -239,7 +239,7 @@ static PyObject *blender_reload( PyObject * self, PyObject * args )
/* no file, try importing from memory */
PyErr_Fetch( &exception, &err, &tb ); /*restore for probable later use */
- newmodule = reimportText( module, &found );
+ newmodule = bpy_text_reimport( module, &found );
if( newmodule ) {/* found module as blender text, ignore above exception */
PyErr_Clear( );
Py_XDECREF( exception );
@@ -262,8 +262,8 @@ static PyObject *blender_reload( PyObject * self, PyObject * args )
return newmodule;
}
-PyMethodDef bpy_import[] = { {"bpy_import", blender_import, METH_KEYWORDS, "blenders import"} };
-PyMethodDef bpy_reload[] = { {"bpy_reload", blender_reload, METH_VARARGS, "blenders reload"} };
+PyMethodDef bpy_import_meth[] = { {"bpy_import_meth", blender_import, METH_KEYWORDS, "blenders import"} };
+PyMethodDef bpy_reload_meth[] = { {"bpy_reload_meth", blender_reload, METH_VARARGS, "blenders reload"} };
/* Clear user modules.
@@ -284,20 +284,25 @@ PyMethodDef bpy_reload[] = { {"bpy_reload", blender_reload, METH_VARARGS, "blend
#endif
-void importClearUserModules(void)
+void bpy_text_clear_modules(void)
{
- PyObject *modules= PySys_GetObject("modules");
+ PyObject *modules= PySys_GetObject("modules");
char *fname;
char *file_extension;
/* looping over the dict */
PyObject *key, *value;
- Py_ssize_t pos = 0;
+ int pos = 0;
/* new list */
- PyObject *list= PyList_New(0);
-
+ PyObject *list;
+
+ if (modules==NULL)
+ return; /* should never happen but just incase */
+
+ list= PyList_New(0);
+
/* go over sys.modules and remove anything with a
* sys.modukes[x].__file__ thats ends with a .py and has no path
*/
diff --git a/source/blender/python/api2_2x/bpy_internal_import.h b/source/blender/python/api2_2x/bpy_internal_import.h
index 9d440406636..137818bb0db 100644
--- a/source/blender/python/api2_2x/bpy_internal_import.h
+++ b/source/blender/python/api2_2x/bpy_internal_import.h
@@ -35,11 +35,11 @@
#include "compile.h" /* for the PyCodeObject */
#include "eval.h" /* for PyEval_EvalCode */
-PyObject *importText( char *name, int *found );
-PyObject *reimportText( PyObject *module, int *found );
-void importClearUserModules( void ); /* Clear user modules */
-extern PyMethodDef bpy_import[];
-extern PyMethodDef bpy_reload[];
+PyObject* bpy_text_import( char *name, int *found );
+PyObject* bpy_text_reimport( PyObject *module, int *found );
+void bpy_text_clear_modules( void ); /* Clear user modules */
+extern PyMethodDef bpy_import_meth[];
+extern PyMethodDef bpy_reload_meth[];
/* The game engine has its own Main struct, if this is set search this rather then G.main */
struct Main *bpy_import_main_get(void);
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index eafb7fc0cb8..7643a043a7c 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -1244,7 +1244,7 @@ PyObject *KXpy_import(PyObject *self, PyObject *args)
}
/* Import blender texts as python modules */
- m= importText(name, &found);
+ m= bpy_text_import(name, &found);
if (m)
return m;
@@ -1267,10 +1267,10 @@ PyObject *KXpy_reload(PyObject *self, PyObject *args) {
PyObject *newmodule = NULL;
/* check for a module arg */
- if( !PyArg_ParseTuple( args, "O:bpy_reload", &module ) )
+ if( !PyArg_ParseTuple( args, "O:bpy_reload_meth", &module ) )
return NULL;
- newmodule= reimportText( module, &found );
+ newmodule= bpy_text_reimport( module, &found );
if (newmodule)
return newmodule;
@@ -1353,8 +1353,8 @@ void setSandbox(TPythonSecurityLevel level)
*/
default:
/* Allow importing internal text, from bpy_internal_import.py */
- PyDict_SetItemString(d, "reload", item=PyCFunction_New(bpy_reload, NULL)); Py_DECREF(item);
- PyDict_SetItemString(d, "__import__", item=PyCFunction_New(bpy_import, NULL)); Py_DECREF(item);
+ PyDict_SetItemString(d, "reload", item=PyCFunction_New(bpy_reload_meth, NULL)); Py_DECREF(item);
+ PyDict_SetItemString(d, "__import__", item=PyCFunction_New(bpy_import_meth, NULL)); Py_DECREF(item);
break;
}
}
@@ -1440,7 +1440,7 @@ static void clearGameModules()
PyErr_Clear(); // incase some of these were alredy removed.
/* clear user defined modules */
- importClearUserModules();
+ bpy_text_clear_modules();
}
void exitGamePythonScripting()