diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-12-07 07:12:15 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-12-07 07:12:15 +0300 |
commit | d624d1cbddf9ee51108e7eb89a6cfd7044fd57c0 (patch) | |
tree | d93701004cd4a3bdfabe8bd5f40b5e90eead91d1 /source/blender/python/intern | |
parent | 48614fbc2af024d613845b03d632e544f8127261 (diff) |
pass along the context to extension functions, this was already being done in all cases except for the render engine.
this allows python to NULL its internal context while scripts are not running.
Diffstat (limited to 'source/blender/python/intern')
-rw-r--r-- | source/blender/python/intern/bpy.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 21 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 3 |
3 files changed, 20 insertions, 6 deletions
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c index 770640f577d..2b6fbd7aaa5 100644 --- a/source/blender/python/intern/bpy.c +++ b/source/blender/python/intern/bpy.c @@ -223,7 +223,7 @@ void BPy_init_modules( void ) PyModule_AddObject( mod, "app", BPY_app_struct() ); /* bpy context */ - RNA_pointer_create(NULL, &RNA_Context, BPy_GetContext(), &ctx_ptr); + RNA_pointer_create(NULL, &RNA_Context, (void *)BPy_GetContext(), &ctx_ptr); bpy_context_module= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ctx_ptr); /* odd that this is needed, 1 ref on creation and another for the module * but without we get a crash on exit */ diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index ea8d39806db..ef7c1cc369a 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -52,8 +52,13 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) int context= WM_OP_EXEC_DEFAULT; // XXX Todo, work out a better solution for passing on context, could make a tuple from self and pack the name and Context into it... - bContext *C = BPy_GetContext(); + bContext *C= (bContext *)BPy_GetContext(); + if(C==NULL) { + PyErr_SetString(PyExc_SystemError, "Context is None, cant poll any operators"); + return NULL; + } + if (!PyArg_ParseTuple(args, "s|Os:_bpy.ops.poll", &opname, &context_dict, &context_str)) return NULL; @@ -114,7 +119,12 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) int context= WM_OP_EXEC_DEFAULT; // XXX Todo, work out a better solution for passing on context, could make a tuple from self and pack the name and Context into it... - bContext *C = BPy_GetContext(); + bContext *C = (bContext *)BPy_GetContext(); + + if(C==NULL) { + PyErr_SetString(PyExc_SystemError, "Context is None, cant poll any operators"); + return NULL; + } if (!PyArg_ParseTuple(args, "sO|O!s:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context_str)) return NULL; @@ -232,8 +242,13 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args) char *buf = NULL; PyObject *pybuf; - bContext *C = BPy_GetContext(); + bContext *C = (bContext *)BPy_GetContext(); + if(C==NULL) { + PyErr_SetString(PyExc_SystemError, "Context is None, cant get the string representation of this object."); + return NULL; + } + if (!PyArg_ParseTuple(args, "s|O!i:_bpy.ops.as_string", &opname, &PyDict_Type, &kw, &all_args)) return NULL; diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index cda20348a9d..b95dc520526 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -5125,7 +5125,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun extern void BPY_update_modules( void ); //XXX temp solution /* TODO - multiple return values like with rna functions */ -static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *parms) +static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms) { PyObject *args; PyObject *ret= NULL, *py_srna= NULL, *py_class, *py_class_instance= NULL, *parmitem; @@ -5141,7 +5141,6 @@ static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *par PyGILState_STATE gilstate; - bContext *C= BPy_GetContext(); // XXX - NEEDS FIXING, QUITE BAD. #ifdef USE_PEDANTIC_WRITE /* testing, for correctness, not operator and not draw function */ const short is_readonly= strstr("draw", RNA_function_identifier(func)) || !RNA_struct_is_a(ptr->type, &RNA_Operator); |