bpy_internal_import.c should build with py2.3 now, also gave bpy_internal_import functions better names.

This commit is contained in:
2009-04-16 06:24:47 +00:00
parent bbdaa03d65
commit 32253dfaaf
4 changed files with 33 additions and 28 deletions

View File

@@ -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 );

View File

@@ -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
*/

View File

@@ -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);

View File

@@ -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()