[capi-sig] overriding pythons import - change in 2.6
Campbell Barton
ideasman42 at gmail.com
Fri Oct 3 08:31:58 CEST 2008
was trying to hunt down why modules would not import in Blender3D with
python 2.6, and found its caused by an extra argument to import that
was making our own internal replacement for __builtin__.__import__
fail.
Added an #ifdef to work around this, for anyone else replacing the
builtin import, this could save you some time.
static PyObject *blender_import( PyObject * self, PyObject * args )
{
PyObject *exception, *err, *tb;
char *name;
PyObject *globals = NULL, *locals = NULL, *fromlist = NULL;
PyObject *m;
//PyObject_Print(args, stderr, 0);
#if (PY_VERSION_HEX >= 0x02060000)
int dummy_val; /* what does this do?*/
if( !PyArg_ParseTuple( args, "s|OOOi:bimport",
&name, &globals, &locals, &fromlist, &dummy_val) )
return NULL;
#else
if( !PyArg_ParseTuple( args, "s|OOO:bimport",
&name, &globals, &locals, &fromlist ) )
return NULL;
#endif
m = PyImport_ImportModuleEx( name, globals, locals, fromlist );
if( m )
return m;
else
PyErr_Fetch( &exception, &err, &tb ); /*restore for probable later use */
--
- Campbell
More information about the capi-sig
mailing list