svn merge -r 30954:31059 https://svn.blender.org/svnroot/bf-blender/trunk/blender
This commit is contained in:
@@ -146,28 +146,6 @@ void BPY_update_modules( void )
|
||||
bpy_context_module->ptr.data= (void *)BPy_GetContext();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Description: This function creates a new Python dictionary object.
|
||||
* note: dict is owned by sys.modules["__main__"] module, reference is borrowed
|
||||
* note: important we use the dict from __main__, this is what python expects
|
||||
for 'pickle' to work as well as strings like this...
|
||||
>> foo = 10
|
||||
>> print(__import__("__main__").foo)
|
||||
*****************************************************************************/
|
||||
static PyObject *CreateGlobalDictionary(bContext *C, const char *filename)
|
||||
{
|
||||
PyInterpreterState *interp= PyThreadState_GET()->interp;
|
||||
PyObject *mod_main= PyModule_New("__main__");
|
||||
PyDict_SetItemString(interp->modules, "__main__", mod_main);
|
||||
Py_DECREF(mod_main); /* sys.modules owns now */
|
||||
|
||||
PyModule_AddObject(mod_main, "__builtins__", interp->builtins);
|
||||
PyModule_AddStringConstant(mod_main, "__name__", "__main__");
|
||||
PyModule_AddStringConstant(mod_main, "__file__", filename); /* __file__ only for nice UI'ness */
|
||||
|
||||
return PyModule_GetDict(mod_main);
|
||||
}
|
||||
|
||||
/* must be called before Py_Initialize */
|
||||
void BPY_start_python_path(void)
|
||||
{
|
||||
@@ -329,13 +307,13 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
|
||||
if (fn==NULL && text==NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
if (text) {
|
||||
char fn_dummy[FILE_MAXDIR];
|
||||
bpy_text_filename_get(fn_dummy, text);
|
||||
py_dict = CreateGlobalDictionary(C, fn_dummy);
|
||||
py_dict = bpy_namespace_dict_new(fn_dummy);
|
||||
|
||||
if( !text->compiled ) { /* if it wasn't already compiled, do it now */
|
||||
char *buf = txt_to_buf( text );
|
||||
@@ -356,7 +334,7 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
|
||||
else {
|
||||
FILE *fp= fopen(fn, "r");
|
||||
|
||||
py_dict = CreateGlobalDictionary(C, fn);
|
||||
py_dict = bpy_namespace_dict_new(fn);
|
||||
|
||||
if(fp) {
|
||||
#ifdef _WIN32
|
||||
@@ -500,7 +478,7 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
|
||||
|
||||
gilstate = PyGILState_Ensure();
|
||||
|
||||
py_dict = CreateGlobalDictionary(C);
|
||||
py_dict = bpy_namespace_dict_new("<dummy>");
|
||||
|
||||
PyObject *module = PyImport_ImportModule(scpt->script.filename);
|
||||
if (module==NULL) {
|
||||
@@ -552,7 +530,7 @@ int BPY_eval_button(bContext *C, const char *expr, double *value)
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
py_dict= CreateGlobalDictionary(C, "<blender button>");
|
||||
py_dict= bpy_namespace_dict_new("<blender button>");
|
||||
|
||||
mod = PyImport_ImportModule("math");
|
||||
if (mod) {
|
||||
@@ -623,7 +601,7 @@ int BPY_eval_string(bContext *C, const char *expr)
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
py_dict= CreateGlobalDictionary(C, "<blender string>");
|
||||
py_dict= bpy_namespace_dict_new("<blender string>");
|
||||
|
||||
retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
|
||||
|
||||
|
||||
@@ -4544,10 +4544,17 @@ static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *par
|
||||
PyGILState_STATE gilstate;
|
||||
|
||||
bContext *C= BPy_GetContext(); // XXX - NEEDS FIXING, QUITE BAD.
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
|
||||
py_class= RNA_struct_py_type_get(ptr->type);
|
||||
|
||||
/* rare case. can happen when registering subclasses */
|
||||
if(py_class==NULL) {
|
||||
fprintf(stderr, "bpy_class_call(): unable to get python class for rna struct '%.200s'\n", RNA_struct_identifier(ptr->type));
|
||||
return -1;
|
||||
}
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
/* exception, operators store their PyObjects for re-use */
|
||||
if(ptr->data) {
|
||||
if(RNA_struct_is_a(ptr->type, &RNA_Operator)) {
|
||||
@@ -4736,7 +4743,16 @@ void pyrna_alloc_types(void)
|
||||
prop = RNA_struct_find_property(&ptr, "structs");
|
||||
|
||||
RNA_PROP_BEGIN(&ptr, itemptr, prop) {
|
||||
Py_DECREF(pyrna_struct_Subtype(&itemptr));
|
||||
PyObject *item= pyrna_struct_Subtype(&itemptr);
|
||||
if(item == NULL) {
|
||||
if(PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Py_DECREF(item);
|
||||
}
|
||||
}
|
||||
RNA_PROP_END;
|
||||
|
||||
@@ -4799,6 +4815,14 @@ static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
|
||||
if(srna==NULL)
|
||||
return NULL;
|
||||
|
||||
/* fails in cases, cant use this check but would like to :| */
|
||||
/*
|
||||
if(RNA_struct_py_type_get(srna)) {
|
||||
PyErr_Format(PyExc_ValueError, "bpy.types.register(...): %.200s's parent class %.200s is alredy registered, this is not allowed.", ((PyTypeObject*)py_class)->tp_name, RNA_struct_identifier(srna));
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
/* check that we have a register callback for this type */
|
||||
reg= RNA_struct_register(srna);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user