Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/python/intern/bpy_operator.c')
-rw-r--r--source/blender/python/intern/bpy_operator.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index 6d86d788644..5ac76ab9ac1 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -77,7 +77,6 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
wmOperatorType *ot;
const char *opname;
PyObject *context_dict = NULL; /* optional args */
- PyObject *context_dict_back;
const char *context_str = NULL;
PyObject *ret;
@@ -85,7 +84,7 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
/* 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 = (bContext *)BPy_GetContext();
+ bContext *C = BPY_context_get();
if (C == NULL) {
PyErr_SetString(PyExc_RuntimeError, "Context is None, cant poll any operators");
@@ -119,7 +118,7 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
}
}
- if (context_dict == NULL || context_dict == Py_None) {
+ if (ELEM(context_dict, NULL, Py_None)) {
context_dict = NULL;
}
else if (!PyDict_Check(context_dict)) {
@@ -131,16 +130,25 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
return NULL;
}
- context_dict_back = CTX_py_dict_get(C);
- CTX_py_dict_set(C, (void *)context_dict);
- Py_XINCREF(context_dict); /* so we done loose it */
+ struct bContext_PyState context_py_state;
+ if (context_dict != NULL) {
+ CTX_py_state_push(C, &context_py_state, (void *)context_dict);
+ Py_INCREF(context_dict); /* so we don't lose it */
+ }
/* main purpose of this function */
ret = WM_operator_poll_context((bContext *)C, ot, context) ? Py_True : Py_False;
- /* restore with original context dict, probably NULL but need this for nested operator calls */
- Py_XDECREF(context_dict);
- CTX_py_dict_set(C, (void *)context_dict_back);
+ if (context_dict != NULL) {
+ PyObject *context_dict_test = CTX_py_dict_get(C);
+ if (context_dict_test != context_dict) {
+ Py_DECREF(context_dict_test);
+ }
+ /* Restore with original context dict,
+ * probably NULL but need this for nested operator calls. */
+ Py_DECREF(context_dict);
+ CTX_py_state_pop(C, &context_py_state);
+ }
return Py_INCREF_RET(ret);
}
@@ -156,7 +164,6 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
const char *context_str = NULL;
PyObject *kw = NULL; /* optional args */
PyObject *context_dict = NULL; /* optional args */
- PyObject *context_dict_back;
/* note that context is an int, python does the conversion in this case */
int context = WM_OP_EXEC_DEFAULT;
@@ -164,7 +171,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
/* 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 = (bContext *)BPy_GetContext();
+ bContext *C = BPY_context_get();
if (C == NULL) {
PyErr_SetString(PyExc_RuntimeError, "Context is None, cant poll any operators");
@@ -213,7 +220,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
}
}
- if (context_dict == NULL || context_dict == Py_None) {
+ if (ELEM(context_dict, NULL, Py_None)) {
context_dict = NULL;
}
else if (!PyDict_Check(context_dict)) {
@@ -225,17 +232,16 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
return NULL;
}
- context_dict_back = CTX_py_dict_get(C);
-
/**
* It might be that there is already a Python context override. We don't want to remove that
* except when this operator call sets a new override explicitly. This is necessary so that
* called operator runs in the same context as the calling code by default.
*/
+ struct bContext_PyState context_py_state;
if (context_dict != NULL) {
- CTX_py_dict_set(C, (void *)context_dict);
+ CTX_py_state_push(C, &context_py_state, (void *)context_dict);
+ Py_INCREF(context_dict); /* so we don't lose it */
}
- Py_XINCREF(context_dict); /* so we done loose it */
if (WM_operator_poll_context((bContext *)C, ot, context) == false) {
const char *msg = CTX_wm_operator_poll_msg_get(C);
@@ -314,9 +320,16 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
#endif
}
- /* restore with original context dict, probably NULL but need this for nested operator calls */
- Py_XDECREF(context_dict);
- CTX_py_dict_set(C, (void *)context_dict_back);
+ if (context_dict != NULL) {
+ PyObject *context_dict_test = CTX_py_dict_get(C);
+ if (context_dict_test != context_dict) {
+ Py_DECREF(context_dict_test);
+ }
+ /* Restore with original context dict,
+ * probably NULL but need this for nested operator calls. */
+ Py_DECREF(context_dict);
+ CTX_py_state_pop(C, &context_py_state);
+ }
if (error_val == -1) {
return NULL;
@@ -326,7 +339,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
* is freed by clear_globals(), further access will crash blender.
* Setting context is not needed in this case, only calling because this
* function corrects bpy.data (internal Main pointer) */
- BPY_modules_update(C);
+ BPY_modules_update();
/* return operator_ret as a bpy enum */
return pyrna_enum_bitfield_to_py(rna_enum_operator_return_items, operator_ret);
@@ -346,7 +359,7 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
char *buf = NULL;
PyObject *pybuf;
- bContext *C = (bContext *)BPy_GetContext();
+ bContext *C = BPY_context_get();
if (C == NULL) {
PyErr_SetString(PyExc_RuntimeError,