diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-08-02 08:20:41 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-08-02 08:20:41 +0400 |
commit | 55e64f0ba4f43535a163090ddf6a1715de0a6fa4 (patch) | |
tree | f278c6f30429c9cd41ed554ca11ead5dc0ccc86c /source/blender | |
parent | 3d81ee3e4aaa5f146c5fb36cef8ad3ec5a81100f (diff) |
minor changes to Martni's commit 30961
- removed the immediate option from C/api and now store in python only, when python loads modules it sets it to False.
- unloading a module would clear the entire TypeMap for all modules, only remove the module types that is being unloaded.
- added some checks for bad class registering, report errors rather then crashing.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 4 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 48 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.h | 2 |
3 files changed, 27 insertions, 27 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index d0e321ade06..375bf20797b 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -329,8 +329,6 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc if (fn==NULL && text==NULL) { return 0; } - - bpy_set_immediate_register(1); bpy_context_set(C, &gilstate); @@ -397,8 +395,6 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc bpy_context_clear(C, &gilstate); - bpy_set_immediate_register(0); - return py_result ? 1:0; } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 8fc7fc2b342..a18c9f7e92d 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -4175,11 +4175,9 @@ static PyObject *pyrna_basetype_getattro( BPy_BaseTypeRNA *self, PyObject *pynam static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self); static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class); static PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class); -static PyObject *pyrna_register_immediate(PyObject *self); static struct PyMethodDef pyrna_basetype_methods[] = { {"__dir__", (PyCFunction)pyrna_basetype_dir, METH_NOARGS, ""}, - {"immediate", (PyCFunction)pyrna_register_immediate, METH_NOARGS, ""}, {"register", (PyCFunction)pyrna_basetype_register, METH_O, ""}, {"unregister", (PyCFunction)pyrna_basetype_unregister, METH_O, ""}, {NULL, NULL, 0, NULL} @@ -4546,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)) { @@ -4738,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; @@ -4771,22 +4785,6 @@ void pyrna_free_types(void) } -static int IMMEDIATE = 0; - -void bpy_set_immediate_register(int value) -{ - IMMEDIATE = value; -} - -static PyObject *pyrna_register_immediate(PyObject *self) -{ - if (IMMEDIATE) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - /* Note! MemLeak XXX * * There is currently a bug where moving registering a python class does @@ -4817,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); diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index 32f2cd477d6..bd9838a76d4 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -86,8 +86,6 @@ int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_ int pyrna_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value, const char *error_prefix); -void bpy_set_immediate_register(int value); - int pyrna_deferred_register_props(struct StructRNA *srna, PyObject *class_dict); /* called before stopping python */ |