Revision: 19751
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19751
Author:   campbellbarton
Date:     2009-04-16 08:24:47 +0200 (Thu, 16 Apr 2009)

Log Message:
-----------
bpy_internal_import.c should build with py2.3 now, also gave 
bpy_internal_import functions better names.

Modified Paths:
--------------
    trunk/blender/source/blender/python/BPY_interface.c
    trunk/blender/source/blender/python/api2_2x/bpy_internal_import.c
    trunk/blender/source/blender/python/api2_2x/bpy_internal_import.h
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp

Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c 2009-04-16 01:42:53 UTC 
(rev 19750)
+++ trunk/blender/source/blender/python/BPY_interface.c 2009-04-16 06:24:47 UTC 
(rev 19751)
@@ -1276,7 +1276,7 @@
         * 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 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_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 );

Modified: trunk/blender/source/blender/python/api2_2x/bpy_internal_import.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/bpy_internal_import.c   
2009-04-16 01:42:53 UTC (rev 19750)
+++ trunk/blender/source/blender/python/api2_2x/bpy_internal_import.c   
2009-04-16 06:24:47 UTC (rev 19751)
@@ -56,7 +56,7 @@
 }
 
 
-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 @@
  * 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 @@
        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 @@
        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 @@
        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 @@
        /* 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 @@
        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 @@
 #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
         */

Modified: trunk/blender/source/blender/python/api2_2x/bpy_internal_import.h
===================================================================
--- trunk/blender/source/blender/python/api2_2x/bpy_internal_import.h   
2009-04-16 01:42:53 UTC (rev 19750)
+++ trunk/blender/source/blender/python/api2_2x/bpy_internal_import.h   
2009-04-16 06:24:47 UTC (rev 19751)
@@ -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);

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2009-04-16 
01:42:53 UTC (rev 19750)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2009-04-16 
06:24:47 UTC (rev 19751)
@@ -1244,7 +1244,7 @@
        }
        
        /* 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 *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 @@
        */
        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 @@
        PyErr_Clear(); // incase some of these were alredy removed.
        
        /* clear user defined modules */
-       importClearUserModules();
+       bpy_text_clear_modules();
 }
 
 void exitGamePythonScripting()


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to