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.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index b8883e655f2..7327679cc7e 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -52,9 +52,16 @@
#include "WM_types.h"
#include "MEM_guardedalloc.h"
+
+#include "BLI_ghash.h"
+
#include "BKE_report.h"
#include "BKE_context.h"
+/* so operators called can spawn threads which aquire the GIL */
+#define BPY_RELEASE_GIL
+
+
static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
{
wmOperatorType *ot;
@@ -110,7 +117,6 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
}
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 */
@@ -219,7 +225,22 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
reports= MEM_mallocN(sizeof(ReportList), "wmOperatorReportList");
BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD); /* own so these dont move into global reports */
- operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports);
+#ifdef BPY_RELEASE_GIL
+ /* release GIL, since a thread could be started from an operator
+ * that updates a driver */
+ /* note: I havve not seen any examples of code that does this
+ * so it may not be officially supported but seems to work ok. */
+ {
+ PyThreadState *ts= PyEval_SaveThread();
+#endif
+
+ operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports);
+
+#ifdef BPY_RELEASE_GIL
+ /* regain GIL */
+ PyEval_RestoreThread(ts);
+ }
+#endif
error_val= BPy_reports_to_error(reports, PyExc_RuntimeError, FALSE);
@@ -271,7 +292,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
* function corrects bpy.data (internal Main pointer) */
BPY_modules_update(C);
- /* needed for when WM_OT_read_factory_settings us called fro within a script */
+ /* needed for when WM_OT_read_factory_settings us called from within a script */
bpy_import_main_set(CTX_data_main(C));
/* return operator_ret as a bpy enum */
@@ -340,15 +361,18 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
static PyObject *pyop_dir(PyObject *UNUSED(self))
{
+ GHashIterator *iter= WM_operatortype_iter();
PyObject *list= PyList_New(0), *name;
- wmOperatorType *ot;
-
- for(ot= WM_operatortype_first(); ot; ot= ot->next) {
+
+ for( ; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
+ wmOperatorType *ot= BLI_ghashIterator_getValue(iter);
+
name= PyUnicode_FromString(ot->idname);
PyList_Append(list, name);
Py_DECREF(name);
}
-
+ BLI_ghashIterator_free(iter);
+
return list;
}
@@ -378,7 +402,9 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
+#ifdef PYRNA_FREE_SUPPORT
pyrna->freeptr= TRUE;
+#endif
return (PyObject *)pyrna;
}