Merge from trunk: 15912:16031
This commit is contained in:
@@ -160,11 +160,10 @@ ScriptError g_script_error;
|
||||
* Function prototypes
|
||||
***************************************************************************/
|
||||
PyObject *RunPython( Text * text, PyObject * globaldict );
|
||||
char *GetName( Text * text );
|
||||
PyObject *CreateGlobalDictionary( void );
|
||||
void ReleaseGlobalDictionary( PyObject * dict );
|
||||
void DoAllScriptsFromList( ListBase * list, short event );
|
||||
PyObject *importText( char *name );
|
||||
static PyObject *importText( char *name );
|
||||
void init_ourImport( void );
|
||||
void init_ourReload( void );
|
||||
PyObject *blender_import( PyObject * self, PyObject * args );
|
||||
@@ -651,7 +650,7 @@ int BPY_txt_do_python_Text( struct Text *text )
|
||||
}
|
||||
|
||||
/* Create a new script structure and initialize it: */
|
||||
script = alloc_libblock( &G.main->script, ID_SCRIPT, GetName( text ) );
|
||||
script = alloc_libblock( &G.main->script, ID_SCRIPT, text->id.name+2 );
|
||||
|
||||
if( !script ) {
|
||||
printf( "couldn't allocate memory for Script struct!" );
|
||||
@@ -662,8 +661,7 @@ int BPY_txt_do_python_Text( struct Text *text )
|
||||
* an error after it will call BPY_Err_Handle below, but the text struct
|
||||
* will have been deallocated already, so we need to copy its name here.
|
||||
*/
|
||||
BLI_strncpy( textname, GetName( text ),
|
||||
strlen( GetName( text ) ) + 1 );
|
||||
BLI_strncpy( textname, text->id.name+2, 21 );
|
||||
|
||||
script->id.us = 1;
|
||||
script->flags = SCRIPT_RUNNING;
|
||||
@@ -1135,12 +1133,10 @@ int BPY_menu_invoke( BPyMenu *pym, short menutype )
|
||||
*****************************************************************************/
|
||||
void BPY_free_compiled_text( struct Text *text )
|
||||
{
|
||||
if( !text->compiled )
|
||||
return;
|
||||
Py_DECREF( ( PyObject * ) text->compiled );
|
||||
text->compiled = NULL;
|
||||
|
||||
return;
|
||||
if( text->compiled ) {
|
||||
Py_DECREF( ( PyObject * ) text->compiled );
|
||||
text->compiled = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@@ -2753,8 +2749,7 @@ PyObject *RunPython( Text * text, PyObject * globaldict )
|
||||
buf = txt_to_buf( text );
|
||||
|
||||
text->compiled =
|
||||
Py_CompileString( buf, GetName( text ),
|
||||
Py_file_input );
|
||||
Py_CompileString( buf, text->id.name+2, Py_file_input );
|
||||
|
||||
MEM_freeN( buf );
|
||||
|
||||
@@ -2768,15 +2763,6 @@ PyObject *RunPython( Text * text, PyObject * globaldict )
|
||||
return PyEval_EvalCode( text->compiled, globaldict, globaldict );
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Description: This function returns the value of the name field of the
|
||||
* given Text struct.
|
||||
*****************************************************************************/
|
||||
char *GetName( Text * text )
|
||||
{
|
||||
return ( text->id.name + 2 );
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Description: This function creates a new Python dictionary object.
|
||||
*****************************************************************************/
|
||||
@@ -2821,49 +2807,38 @@ void DoAllScriptsFromList( ListBase * list, short event )
|
||||
return;
|
||||
}
|
||||
|
||||
PyObject *importText( char *name )
|
||||
static PyObject *importText( char *name )
|
||||
{
|
||||
Text *text;
|
||||
char *txtname;
|
||||
char txtname[22]; /* 21+NULL */
|
||||
char *buf = NULL;
|
||||
int namelen = strlen( name );
|
||||
|
||||
txtname = malloc( namelen + 3 + 1 );
|
||||
if( !txtname )
|
||||
return NULL;
|
||||
|
||||
|
||||
if (namelen>21-3) return NULL; /* we know this cant be importable, the name is too long for blender! */
|
||||
|
||||
memcpy( txtname, name, namelen );
|
||||
memcpy( &txtname[namelen], ".py", 4 );
|
||||
|
||||
text = ( Text * ) & ( G.main->text.first );
|
||||
|
||||
while( text ) {
|
||||
if( !strcmp( txtname, GetName( text ) ) )
|
||||
for(text = G.main->text.first; text; text = text->id.next) {
|
||||
if( !strcmp( txtname, text->id.name+2 ) )
|
||||
break;
|
||||
text = text->id.next;
|
||||
}
|
||||
|
||||
if( !text ) {
|
||||
free( txtname );
|
||||
if( !text )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( !text->compiled ) {
|
||||
buf = txt_to_buf( text );
|
||||
text->compiled =
|
||||
Py_CompileString( buf, GetName( text ),
|
||||
Py_file_input );
|
||||
text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input );
|
||||
MEM_freeN( buf );
|
||||
|
||||
if( PyErr_Occurred( ) ) {
|
||||
PyErr_Print( );
|
||||
BPY_free_compiled_text( text );
|
||||
free( txtname );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
free( txtname );
|
||||
return PyImport_ExecCodeModule( name, text->compiled );
|
||||
}
|
||||
|
||||
@@ -2934,7 +2909,7 @@ static PyObject *reimportText( PyObject *module )
|
||||
/* look up the text object */
|
||||
text = ( Text * ) & ( G.main->text.first );
|
||||
while( text ) {
|
||||
if( !strcmp( txtname, GetName( text ) ) )
|
||||
if( !strcmp( txtname, text->id.name+2 ) )
|
||||
break;
|
||||
text = text->id.next;
|
||||
}
|
||||
@@ -2951,8 +2926,7 @@ static PyObject *reimportText( PyObject *module )
|
||||
|
||||
/* compile the buffer */
|
||||
buf = txt_to_buf( text );
|
||||
text->compiled = Py_CompileString( buf, GetName( text ),
|
||||
Py_file_input );
|
||||
text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input );
|
||||
MEM_freeN( buf );
|
||||
|
||||
/* if compile failed.... return this error */
|
||||
|
||||
Reference in New Issue
Block a user