diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-09-13 10:56:32 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-09-13 10:56:32 +0300 |
commit | d538de90a7ac2179f8c8bd235c24bf12d10e0ef3 (patch) | |
tree | b0f6bffd7b76d07f9da78bc88aecadc445ae0a47 | |
parent | c197c210e48c708eb380849488bd082adbc044eb (diff) | |
parent | 9900addf11d9a5b964aa745cf141998195f7c8db (diff) |
Merge branch 'master' into blender2.8
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 4183970c9a1..78ae9976586 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -64,6 +64,21 @@ /* so operators called can spawn threads which acquire the GIL */ #define BPY_RELEASE_GIL +static wmOperatorType *ot_lookup_from_py_string(PyObject *value, const char *py_fn_id) +{ + const char *opname = _PyUnicode_AsString(value); + if (opname == NULL) { + PyErr_Format(PyExc_TypeError, "%s() expects a string argument", py_fn_id); + return NULL; + } + + wmOperatorType *ot = WM_operatortype_find(opname, true); + if (ot == NULL) { + PyErr_Format(PyExc_KeyError, "%s(\"%s\") not found", py_fn_id, opname); + return NULL; + } + return ot; +} static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) { @@ -397,17 +412,8 @@ static PyObject *pyop_dir(PyObject *UNUSED(self)) static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value) { wmOperatorType *ot; - PointerRNA ptr; - const char *opname = _PyUnicode_AsString(value); - BPy_StructRNA *pyrna = NULL; - if (opname == NULL) { - PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_rna() expects a string argument"); - return NULL; - } - ot = WM_operatortype_find(opname, true); - if (ot == NULL) { - PyErr_Format(PyExc_KeyError, "_bpy.ops.get_rna(\"%s\") not found", opname); + if ((ot = ot_lookup_from_py_string(value, "getrna")) == NULL) { return NULL; } @@ -415,11 +421,11 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value) //RNA_pointer_create(NULL, &RNA_Struct, ot->srna, &ptr); /* XXX - should call WM_operator_properties_free */ + PointerRNA ptr; WM_operator_properties_create_ptr(&ptr, ot); WM_operator_properties_sanitize(&ptr, 0); - - pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); + BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); #ifdef PYRNA_FREE_SUPPORT pyrna->freeptr = true; #endif @@ -429,21 +435,11 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value) static PyObject *pyop_getinstance(PyObject *UNUSED(self), PyObject *value) { wmOperatorType *ot; - wmOperator *op; - PointerRNA ptr; - const char *opname = _PyUnicode_AsString(value); - BPy_StructRNA *pyrna = NULL; - - if (opname == NULL) { - PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_instance() expects a string argument"); - return NULL; - } - ot = WM_operatortype_find(opname, true); - if (ot == NULL) { - PyErr_Format(PyExc_KeyError, "_bpy.ops.get_instance(\"%s\") not found", opname); + if ((ot = ot_lookup_from_py_string(value, "get_instance")) == NULL) { return NULL; } + wmOperator *op; #ifdef PYRNA_FREE_SUPPORT op = MEM_callocN(sizeof(wmOperator), __func__); #else @@ -453,9 +449,10 @@ static PyObject *pyop_getinstance(PyObject *UNUSED(self), PyObject *value) BLI_strncpy(op->idname, ot->idname, sizeof(op->idname)); /* in case its needed */ op->type = ot; + PointerRNA ptr; RNA_pointer_create(NULL, &RNA_Operator, op, &ptr); - pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); + BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); #ifdef PYRNA_FREE_SUPPORT pyrna->freeptr = true; #endif |