diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-29 22:12:48 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-29 23:14:28 +0300 |
commit | 25ec4b437fe927205a810470cdc23efd7282c85b (patch) | |
tree | 6d7ba2fe73703915b4b94d3f2dab03fb731e9544 /source/blender/python/intern | |
parent | 18d06e8d21ed8c9a19df4205abcd7ed17eb9af00 (diff) |
Cleanup: style, use braces for the Python API
Diffstat (limited to 'source/blender/python/intern')
-rw-r--r-- | source/blender/python/intern/bpy.c | 26 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app.c | 16 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app_handlers.c | 3 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app_translations.c | 15 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_capi_utils.c | 6 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_driver.c | 34 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 36 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_library_load.c | 3 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 6 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator_wrap.c | 3 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 181 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 442 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_anim.c | 21 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_array.c | 32 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_callback.c | 36 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_traceback.c | 24 |
16 files changed, 598 insertions, 286 deletions
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c index 55d226e1461..f67ed1a3713 100644 --- a/source/blender/python/intern/bpy.c +++ b/source/blender/python/intern/bpy.c @@ -126,9 +126,15 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec return NULL; } - if (absolute) flag |= BKE_BPATH_TRAVERSE_ABS; - if (!packed) flag |= BKE_BPATH_TRAVERSE_SKIP_PACKED; - if (local) flag |= BKE_BPATH_TRAVERSE_SKIP_LIBRARY; + if (absolute) { + flag |= BKE_BPATH_TRAVERSE_ABS; + } + if (!packed) { + flag |= BKE_BPATH_TRAVERSE_SKIP_PACKED; + } + if (local) { + flag |= BKE_BPATH_TRAVERSE_SKIP_LIBRARY; + } list = PyList_New(0); @@ -157,10 +163,10 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj } /* stupid string compare */ - if (STREQ(type, "DATAFILES")) folder_id = BLENDER_USER_DATAFILES; - else if (STREQ(type, "CONFIG")) folder_id = BLENDER_USER_CONFIG; - else if (STREQ(type, "SCRIPTS")) folder_id = BLENDER_USER_SCRIPTS; - else if (STREQ(type, "AUTOSAVE")) folder_id = BLENDER_USER_AUTOSAVE; + if (STREQ(type, "DATAFILES")) { folder_id = BLENDER_USER_DATAFILES; } + else if (STREQ(type, "CONFIG")) { folder_id = BLENDER_USER_CONFIG; } + else if (STREQ(type, "SCRIPTS")) { folder_id = BLENDER_USER_SCRIPTS; } + else if (STREQ(type, "AUTOSAVE")) { folder_id = BLENDER_USER_AUTOSAVE; } else { PyErr_SetString(PyExc_ValueError, "invalid resource argument"); return NULL; @@ -203,9 +209,9 @@ static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObj } /* stupid string compare */ - if (STREQ(type, "USER")) folder_id = BLENDER_RESOURCE_PATH_USER; - else if (STREQ(type, "LOCAL")) folder_id = BLENDER_RESOURCE_PATH_LOCAL; - else if (STREQ(type, "SYSTEM")) folder_id = BLENDER_RESOURCE_PATH_SYSTEM; + if (STREQ(type, "USER")) { folder_id = BLENDER_RESOURCE_PATH_USER; } + else if (STREQ(type, "LOCAL")) { folder_id = BLENDER_RESOURCE_PATH_LOCAL; } + else if (STREQ(type, "SYSTEM")) { folder_id = BLENDER_RESOURCE_PATH_SYSTEM; } else { PyErr_SetString(PyExc_ValueError, "invalid resource argument"); return NULL; diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c index 252fd1b3e23..2cd3086dae1 100644 --- a/source/blender/python/intern/bpy_app.c +++ b/source/blender/python/intern/bpy_app.c @@ -253,8 +253,12 @@ static int bpy_app_debug_set(PyObject *UNUSED(self), PyObject *value, void *clos return -1; } - if (param) G.debug |= flag; - else G.debug &= ~flag; + if (param) { + G.debug |= flag; + } + else { + G.debug &= ~flag; + } return 0; } @@ -278,8 +282,12 @@ static int bpy_app_global_flag_set(PyObject *UNUSED(self), PyObject *value, void return -1; } - if (param) G.f |= flag; - else G.f &= ~flag; + if (param) { + G.f |= flag; + } + else { + G.f &= ~flag; + } return 0; } diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c index b6b9f294810..c91c0d69a16 100644 --- a/source/blender/python/intern/bpy_app_handlers.c +++ b/source/blender/python/intern/bpy_app_handlers.c @@ -90,8 +90,9 @@ static PyObject *bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type), PyO { PyObject *value; - if (!PyArg_ParseTuple(args, "O:bpy.app.handlers.persistent", &value)) + if (!PyArg_ParseTuple(args, "O:bpy.app.handlers.persistent", &value)) { return NULL; + } if (PyFunction_Check(value)) { PyObject **dict_ptr = _PyObject_GetDictPtr(value); diff --git a/source/blender/python/intern/bpy_app_translations.c b/source/blender/python/intern/bpy_app_translations.c index 1ed68201a2e..f571caee8ec 100644 --- a/source/blender/python/intern/bpy_app_translations.c +++ b/source/blender/python/intern/bpy_app_translations.c @@ -89,8 +89,9 @@ static bool _ghashutil_keycmp(const void *a, const void *b) const GHashKey *B = b; /* Note: comparing msgid first, most of the time it will be enough! */ - if (BLI_ghashutil_strcmp(A->msgid, B->msgid) == false) + if (BLI_ghashutil_strcmp(A->msgid, B->msgid) == false) { return BLI_ghashutil_strcmp(A->msgctxt, B->msgctxt); + } return true; /* true means they are not equal! */ } @@ -249,8 +250,9 @@ const char *BPY_app_translations_py_pgettext(const char *msgctxt, const char *ms const char *tmp; /* Just in case, should never happen! */ - if (!_translations) + if (!_translations) { return msgid; + } tmp = BLT_lang_get(); if (!STREQ(tmp, locale) || !_translations_cache) { @@ -458,8 +460,9 @@ static PyObject *app_translations_locales_get(PyObject *UNUSED(self), void *UNUS if (items) { /* This is not elegant, but simple! */ for (it = items; it->identifier; it++) { - if (it->value) + if (it->value) { num_locales++; + } } } @@ -467,8 +470,9 @@ static PyObject *app_translations_locales_get(PyObject *UNUSED(self), void *UNUS if (items) { for (it = items; it->identifier; it++) { - if (it->value) + if (it->value) { PyTuple_SET_ITEM(ret, pos++, PyUnicode_FromString(it->description)); + } } } @@ -801,8 +805,9 @@ PyObject *BPY_app_translations_struct(void) PyStructSequence_InitType(&BlenderAppTranslationsContextsType, &app_translations_contexts_desc); } - if (PyType_Ready(&BlenderAppTranslationsType) < 0) + if (PyType_Ready(&BlenderAppTranslationsType) < 0) { return NULL; + } ret = PyObject_CallObject((PyObject *)&BlenderAppTranslationsType, NULL); diff --git a/source/blender/python/intern/bpy_capi_utils.c b/source/blender/python/intern/bpy_capi_utils.c index 3a5b3077ee6..549a06f5b28 100644 --- a/source/blender/python/intern/bpy_capi_utils.c +++ b/source/blender/python/intern/bpy_capi_utils.c @@ -48,8 +48,9 @@ char *BPy_enum_as_string(const EnumPropertyItem *item) char *cstring; for (e = item; item->identifier; item++) { - if (item->identifier[0]) + if (item->identifier[0]) { BLI_dynstr_appendf(dynstr, (e == item) ? "'%s'" : ", '%s'", item->identifier); + } } cstring = BLI_dynstr_get_cstring(dynstr); @@ -93,8 +94,9 @@ bool BPy_errors_to_report_ex(ReportList *reports, const bool use_full, const boo { PyObject *pystring; - if (!PyErr_Occurred()) + if (!PyErr_Occurred()) { return 1; + } /* less hassle if we allow NULL */ if (reports == NULL) { diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index 93d9225ad01..cb23739ca33 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -69,13 +69,17 @@ int bpy_pydriver_create_dict(void) PyObject *d, *mod; /* validate namespace for driver evaluation */ - if (bpy_pydriver_Dict) return -1; + if (bpy_pydriver_Dict) { + return -1; + } d = PyDict_New(); - if (d == NULL) + if (d == NULL) { return -1; - else + } + else { bpy_pydriver_Dict = d; + } /* import some modules: builtins, bpy, math, (Blender.noise)*/ PyDict_SetItemString(d, "__builtins__", PyEval_GetBuiltins()); @@ -205,8 +209,9 @@ void BPY_driver_reset(void) PyGILState_STATE gilstate; bool use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } if (bpy_pydriver_Dict) { /* free the global dict used by pydrivers */ PyDict_Clear(bpy_pydriver_Dict); @@ -227,8 +232,9 @@ void BPY_driver_reset(void) /* freed when clearing driver dict */ g_pydriver_state_prev.self = NULL; - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } return; } @@ -399,8 +405,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C /* get the py expression to be evaluated */ expr = driver_orig->expression; - if (expr[0] == '\0') + if (expr[0] == '\0') { return 0.0f; + } #ifndef USE_BYTECODE_WHITELIST if (!(G.f & G_FLAG_SCRIPT_AUTOEXEC)) { @@ -418,8 +425,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } /* needed since drivers are updated directly after undo where 'main' is * re-allocated [#28807] */ @@ -429,8 +437,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C if (!bpy_pydriver_Dict) { if (bpy_pydriver_create_dict() != 0) { fprintf(stderr, "PyDriver error: couldn't create Python dictionary\n"); - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } return 0.0f; } } @@ -445,8 +454,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C bpy_pydriver_namespace_clear_self(); } - if (driver_orig->expr_comp == NULL) + if (driver_orig->expr_comp == NULL) { driver_orig->flag |= DRIVER_FLAG_RECOMPILE; + } /* compile the expression first if it hasn't been compiled or needs to be rebuilt */ if (driver_orig->flag & DRIVER_FLAG_RECOMPILE) { @@ -571,8 +581,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C retval = PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars); #else /* evaluate the compiled expression */ - if (expr_code) + if (expr_code) { retval = PyEval_EvalCode((void *)expr_code, bpy_pydriver_Dict, driver_vars); + } #endif /* decref the driver vars first... */ @@ -593,8 +604,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C Py_DECREF(retval); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (isfinite(result)) { return (float)result; diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 189fb97f3d2..e07e39642e9 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -98,8 +98,9 @@ void BPY_context_update(bContext *C) /* don't do this from a non-main (e.g. render) thread, it can cause a race * condition on C->data.recursion. ideal solution would be to disable * context entirely from non-main threads, but that's more complicated */ - if (!BLI_thread_is_main()) + if (!BLI_thread_is_main()) { return; + } BPy_SetContext(C); bpy_import_main_set(CTX_data_main(C)); @@ -110,8 +111,9 @@ void bpy_context_set(bContext *C, PyGILState_STATE *gilstate) { py_call_level++; - if (gilstate) + if (gilstate) { *gilstate = PyGILState_Ensure(); + } if (py_call_level == 1) { BPY_context_update(C); @@ -135,8 +137,9 @@ void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate) { py_call_level--; - if (gilstate) + if (gilstate) { PyGILState_Release(*gilstate); + } if (py_call_level < 0) { fprintf(stderr, "ERROR: Python context internal state bug. this should not happen!\n"); @@ -163,14 +166,16 @@ void BPY_text_free_code(Text *text) PyGILState_STATE gilstate; bool use_gil = !PyC_IsInterpreterActive(); - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } Py_DECREF((PyObject *)text->compiled); text->compiled = NULL; - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } } } @@ -184,8 +189,9 @@ void BPY_modules_update(bContext *C) /* refreshes the main struct */ BPY_update_rna_module(); - if (bpy_context_module) + if (bpy_context_module) { bpy_context_module->ptr.data = (void *)C; + } } void BPY_context_set(bContext *C) @@ -371,11 +377,13 @@ void BPY_python_end(void) printf("*bpy stats* - "); printf("tot exec: %d, ", bpy_timer_count); printf("tot run: %.4fsec, ", bpy_timer_run_tot); - if (bpy_timer_count > 0) + if (bpy_timer_count > 0) { printf("average run: %.6fsec, ", (bpy_timer_run_tot / bpy_timer_count)); + } - if (bpy_timer > 0.0) + if (bpy_timer > 0.0) { printf("tot usage %.4f%%", (bpy_timer_run_tot / bpy_timer) * 100.0); + } printf("\n"); @@ -750,8 +758,9 @@ void BPY_modules_load_user(bContext *C) Text *text; /* can happen on file load */ - if (bmain == NULL) + if (bmain == NULL) { return; + } /* update pointers since this can run from a nested script * on file load */ @@ -802,8 +811,9 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult * PointerRNA *ptr = NULL; bool done = false; - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } pyctx = (PyObject *)CTX_py_dict_get(C); item = PyDict_GetItemString(pyctx, member); @@ -870,8 +880,9 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult * CLOG_INFO(BPY_LOG_CONTEXT, 2, "'%s' found", member); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } return done; } @@ -971,8 +982,9 @@ PyInit_bpy(void) dealloc_obj_Type.tp_dealloc = dealloc_obj_dealloc; dealloc_obj_Type.tp_flags = Py_TPFLAGS_DEFAULT; - if (PyType_Ready(&dealloc_obj_Type) < 0) + if (PyType_Ready(&dealloc_obj_Type) < 0) { return NULL; + } dob = (dealloc_obj *) dealloc_obj_Type.tp_alloc(&dealloc_obj_Type, 0); dob->mod = bpy_proxy; /* borrow */ diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c index bf12db0f3a1..77fb6bf1525 100644 --- a/source/blender/python/intern/bpy_library_load.c +++ b/source/blender/python/intern/bpy_library_load.c @@ -476,8 +476,9 @@ int BPY_library_load_module(PyObject *mod_par) /* some compilers don't like accessing this directly, delay assignment */ bpy_lib_Type.tp_getattro = PyObject_GenericGetAttr; - if (PyType_Ready(&bpy_lib_Type) < 0) + if (PyType_Ready(&bpy_lib_Type) < 0) { return -1; + } return 0; } diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 98b2f871c54..ff6bd3840e9 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -93,8 +93,9 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) return NULL; } - if (!PyArg_ParseTuple(args, "s|Os:_bpy.ops.poll", &opname, &context_dict, &context_str)) + if (!PyArg_ParseTuple(args, "s|Os:_bpy.ops.poll", &opname, &context_dict, &context_str)) { return NULL; + } ot = WM_operatortype_find(opname, true); @@ -362,8 +363,9 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args) error_val = pyrna_pydict_to_props(&ptr, kw, false, "Converting py args to operator properties: "); } - if (error_val == 0) + if (error_val == 0) { buf = WM_operator_pystring_ex(C, NULL, all_args, macro_args, ot, &ptr); + } WM_operator_properties_free(&ptr); diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index 6f1450fcbc2..6a130a7c52b 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -162,8 +162,9 @@ PyObject *PYOP_wrap_macro_define(PyObject *UNUSED(self), PyObject *args) const char *opname; const char *macroname; - if (!PyArg_ParseTuple(args, "Os:_bpy.ops.macro_define", ¯o, &opname)) + if (!PyArg_ParseTuple(args, "Os:_bpy.ops.macro_define", ¯o, &opname)) { return NULL; + } if (WM_operatortype_find(opname, true) == NULL) { PyErr_Format(PyExc_ValueError, diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index 385b02f231e..18a39f39e70 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -201,10 +201,12 @@ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw) PyTuple_SET_ITEM(ret, 0, func); Py_INCREF(func); - if (kw == NULL) + if (kw == NULL) { kw = PyDict_New(); - else + } + else { Py_INCREF(kw); + } PyTuple_SET_ITEM(ret, 1, kw); @@ -282,8 +284,9 @@ static bool bpy_prop_boolean_get_cb(struct PointerRNA *ptr, struct PropertyRNA * use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_GET]; @@ -313,8 +316,9 @@ static bool bpy_prop_boolean_get_cb(struct PointerRNA *ptr, struct PropertyRNA * Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -342,8 +346,9 @@ static void bpy_prop_boolean_set_cb(struct PointerRNA *ptr, struct PropertyRNA * use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_SET]; @@ -369,8 +374,9 @@ static void bpy_prop_boolean_set_cb(struct PointerRNA *ptr, struct PropertyRNA * Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -395,8 +401,9 @@ static bool bpy_prop_poll_cb(struct PointerRNA *self, PointerRNA candidate, stru py_candidate = pyrna_struct_as_instance(&candidate); py_func = py_data[BPY_DATA_CB_SLOT_POLL]; - if (!is_write_ok) + if (!is_write_ok) { pyrna_write_set(true); + } args = PyTuple_New(2); PyTuple_SET_ITEM(args, 0, py_self); @@ -416,8 +423,9 @@ static bool bpy_prop_poll_cb(struct PointerRNA *self, PointerRNA candidate, stru } PyGILState_Release(gilstate); - if (!is_write_ok) + if (!is_write_ok) { pyrna_write_set(false); + } return result; } @@ -442,8 +450,9 @@ static void bpy_prop_boolean_array_get_cb(struct PointerRNA *ptr, struct Propert use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_GET]; @@ -458,15 +467,17 @@ static void bpy_prop_boolean_array_get_cb(struct PointerRNA *ptr, struct Propert if (ret == NULL) { PyC_Err_PrintWithFunc(py_func); - for (i = 0; i < len; ++i) + for (i = 0; i < len; ++i) { values[i] = false; + } } else { if (PyC_AsArray(values, ret, len, &PyBool_Type, false, "BoolVectorProperty get") == -1) { PyC_Err_PrintWithFunc(py_func); - for (i = 0; i < len; ++i) + for (i = 0; i < len; ++i) { values[i] = false; + } /* PyC_AsArray decrements refcount internally on error */ } @@ -475,8 +486,9 @@ static void bpy_prop_boolean_array_get_cb(struct PointerRNA *ptr, struct Propert } } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -504,8 +516,9 @@ static void bpy_prop_boolean_array_set_cb(struct PointerRNA *ptr, struct Propert use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_SET]; @@ -532,8 +545,9 @@ static void bpy_prop_boolean_array_set_cb(struct PointerRNA *ptr, struct Propert Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -560,8 +574,9 @@ static int bpy_prop_int_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop) use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_GET]; @@ -588,8 +603,9 @@ static int bpy_prop_int_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop) Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -617,8 +633,9 @@ static void bpy_prop_int_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_SET]; @@ -644,8 +661,9 @@ static void bpy_prop_int_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -672,8 +690,9 @@ static void bpy_prop_int_array_get_cb(struct PointerRNA *ptr, struct PropertyRNA use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_GET]; @@ -688,15 +707,17 @@ static void bpy_prop_int_array_get_cb(struct PointerRNA *ptr, struct PropertyRNA if (ret == NULL) { PyC_Err_PrintWithFunc(py_func); - for (i = 0; i < len; ++i) + for (i = 0; i < len; ++i) { values[i] = 0; + } } else { if (PyC_AsArray(values, ret, len, &PyLong_Type, false, "IntVectorProperty get") == -1) { PyC_Err_PrintWithFunc(py_func); - for (i = 0; i < len; ++i) + for (i = 0; i < len; ++i) { values[i] = 0; + } /* PyC_AsArray decrements refcount internally on error */ } @@ -705,8 +726,9 @@ static void bpy_prop_int_array_get_cb(struct PointerRNA *ptr, struct PropertyRNA } } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -734,8 +756,9 @@ static void bpy_prop_int_array_set_cb(struct PointerRNA *ptr, struct PropertyRNA use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_SET]; @@ -762,8 +785,9 @@ static void bpy_prop_int_array_set_cb(struct PointerRNA *ptr, struct PropertyRNA Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -790,8 +814,9 @@ static float bpy_prop_float_get_cb(struct PointerRNA *ptr, struct PropertyRNA *p use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_GET]; @@ -818,8 +843,9 @@ static float bpy_prop_float_get_cb(struct PointerRNA *ptr, struct PropertyRNA *p Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -847,8 +873,9 @@ static void bpy_prop_float_set_cb(struct PointerRNA *ptr, struct PropertyRNA *pr use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_SET]; @@ -874,8 +901,9 @@ static void bpy_prop_float_set_cb(struct PointerRNA *ptr, struct PropertyRNA *pr Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -902,8 +930,9 @@ static void bpy_prop_float_array_get_cb(struct PointerRNA *ptr, struct PropertyR use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_GET]; @@ -918,15 +947,17 @@ static void bpy_prop_float_array_get_cb(struct PointerRNA *ptr, struct PropertyR if (ret == NULL) { PyC_Err_PrintWithFunc(py_func); - for (i = 0; i < len; ++i) + for (i = 0; i < len; ++i) { values[i] = 0.0f; + } } else { if (PyC_AsArray(values, ret, len, &PyFloat_Type, false, "FloatVectorProperty get") == -1) { PyC_Err_PrintWithFunc(py_func); - for (i = 0; i < len; ++i) + for (i = 0; i < len; ++i) { values[i] = 0.0f; + } /* PyC_AsArray decrements refcount internally on error */ } @@ -935,8 +966,9 @@ static void bpy_prop_float_array_get_cb(struct PointerRNA *ptr, struct PropertyR } } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -964,8 +996,9 @@ static void bpy_prop_float_array_set_cb(struct PointerRNA *ptr, struct PropertyR use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_SET]; @@ -992,8 +1025,9 @@ static void bpy_prop_float_array_set_cb(struct PointerRNA *ptr, struct PropertyR Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -1019,8 +1053,9 @@ static void bpy_prop_string_get_cb(struct PointerRNA *ptr, struct PropertyRNA *p use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_GET]; @@ -1051,8 +1086,9 @@ static void bpy_prop_string_get_cb(struct PointerRNA *ptr, struct PropertyRNA *p Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -1079,8 +1115,9 @@ static int bpy_prop_string_length_cb(struct PointerRNA *ptr, struct PropertyRNA use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_GET]; @@ -1111,8 +1148,9 @@ static int bpy_prop_string_length_cb(struct PointerRNA *ptr, struct PropertyRNA Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -1141,8 +1179,9 @@ static void bpy_prop_string_set_cb(struct PointerRNA *ptr, struct PropertyRNA *p use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_SET]; @@ -1155,8 +1194,9 @@ static void bpy_prop_string_set_cb(struct PointerRNA *ptr, struct PropertyRNA *p PyErr_SetString(PyExc_ValueError, "the return value must be a string"); PyC_Err_PrintWithFunc(py_func); } - else + else { PyTuple_SET_ITEM(args, 1, py_value); + } ret = PyObject_CallObject(py_func, args); @@ -1174,8 +1214,9 @@ static void bpy_prop_string_set_cb(struct PointerRNA *ptr, struct PropertyRNA *p Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -1202,8 +1243,9 @@ static int bpy_prop_enum_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_GET]; @@ -1230,8 +1272,9 @@ static int bpy_prop_enum_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -1259,8 +1302,9 @@ static void bpy_prop_enum_set_cb(struct PointerRNA *ptr, struct PropertyRNA *pro use_gil = true; /* !PyC_IsInterpreterActive(); */ - if (use_gil) + if (use_gil) { gilstate = PyGILState_Ensure(); + } py_func = py_data[BPY_DATA_CB_SLOT_SET]; @@ -1286,8 +1330,9 @@ static void bpy_prop_enum_set_cb(struct PointerRNA *ptr, struct PropertyRNA *pro Py_DECREF(ret); } - if (use_gil) + if (use_gil) { PyGILState_Release(gilstate); + } if (!is_write_ok) { pyrna_write_set(false); @@ -1423,8 +1468,9 @@ static const EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject * } } - if (tmp_icon) + if (tmp_icon) { tmp.icon = icon_id_from_name(tmp_icon); + } items[i] = tmp; @@ -2139,8 +2185,9 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject return NULL; } - if (pydef && PyC_AsArray(def, pydef, size, &PyBool_Type, false, "BoolVectorProperty(default=sequence)") == -1) + if (pydef && PyC_AsArray(def, pydef, size, &PyBool_Type, false, "BoolVectorProperty(default=sequence)") == -1) { return NULL; + } if (bpy_prop_callback_check(update_cb, "update", 2) == -1) { return NULL; @@ -2155,7 +2202,9 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject // prop = RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name ? name : id, description); prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype); RNA_def_property_array(prop, size); - if (pydef) RNA_def_property_boolean_array_default(prop, def); + if (pydef) { + RNA_def_property_boolean_array_default(prop, def); + } RNA_def_property_ui_text(prop, name ? name : id, description); if (py_tags) { @@ -2366,8 +2415,9 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject return NULL; } - if (pydef && PyC_AsArray(def, pydef, size, &PyLong_Type, false, "IntVectorProperty(default=sequence)") == -1) + if (pydef && PyC_AsArray(def, pydef, size, &PyLong_Type, false, "IntVectorProperty(default=sequence)") == -1) { return NULL; + } if (bpy_prop_callback_check(update_cb, "update", 2) == -1) { return NULL; @@ -2381,7 +2431,9 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject prop = RNA_def_property(srna, id, PROP_INT, subtype); RNA_def_property_array(prop, size); - if (pydef) RNA_def_property_int_array_default(prop, def); + if (pydef) { + RNA_def_property_int_array_default(prop, def); + } RNA_def_property_range(prop, min, max); RNA_def_property_ui_text(prop, name ? name : id, description); RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3); @@ -2618,8 +2670,9 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec return NULL; } - if (pydef && PyC_AsArray(def, pydef, size, &PyFloat_Type, false, "FloatVectorProperty(default=sequence)") == -1) + if (pydef && PyC_AsArray(def, pydef, size, &PyFloat_Type, false, "FloatVectorProperty(default=sequence)") == -1) { return NULL; + } if (bpy_prop_callback_check(update_cb, "update", 2) == -1) { return NULL; @@ -2633,7 +2686,9 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec prop = RNA_def_property(srna, id, PROP_FLOAT, subtype | unit); RNA_def_property_array(prop, size); - if (pydef) RNA_def_property_float_array_default(prop, def); + if (pydef) { + RNA_def_property_float_array_default(prop, def); + } RNA_def_property_range(prop, min, max); RNA_def_property_ui_text(prop, name ? name : id, description); RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision); @@ -2728,8 +2783,12 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw } prop = RNA_def_property(srna, id, PROP_STRING, subtype); - if (maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen + 1); /* +1 since it includes null terminator */ - if (def && def[0]) RNA_def_property_string_default(prop, def); + if (maxlen != 0) { + RNA_def_property_string_maxlength(prop, maxlen + 1); /* +1 since it includes null terminator */ + } + if (def && def[0]) { + RNA_def_property_string_default(prop, def); + } RNA_def_property_ui_text(prop, name ? name : id, description); if (py_tags) { @@ -2890,8 +2949,12 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) } } - if (opts & PROP_ENUM_FLAG) prop = RNA_def_enum_flag(srna, id, eitems, defvalue, name ? name : id, description); - else prop = RNA_def_enum(srna, id, eitems, defvalue, name ? name : id, description); + if (opts & PROP_ENUM_FLAG) { + prop = RNA_def_enum_flag(srna, id, eitems, defvalue, name ? name : id, description); + } + else { + prop = RNA_def_enum(srna, id, eitems, defvalue, name ? name : id, description); + } if (py_tags) { RNA_def_property_tags(prop, prop_tags); @@ -2994,8 +3057,9 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw) BPY_PROPDEF_CHECK(PointerProperty, property_flag_items); ptype = pointer_type_from_py(type, "PointerProperty(...)"); - if (!ptype) + if (!ptype) { return NULL; + } if (!RNA_struct_is_a(ptype, &RNA_PropertyGroup) && !RNA_struct_is_ID(ptype)) { PyErr_Format(PyExc_TypeError, "PointerProperty(...) expected an RNA type derived from %.200s or %.200s", @@ -3077,8 +3141,9 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw) BPY_PROPDEF_CHECK(CollectionProperty, property_flag_items); ptype = pointer_type_from_py(type, "CollectionProperty(...):"); - if (!ptype) + if (!ptype) { return NULL; + } if (!RNA_struct_is_a(ptype, &RNA_PropertyGroup)) { PyErr_Format( diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 4e96479242b..f695464ec42 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -314,8 +314,12 @@ static bool rna_id_write_error(PointerRNA *ptr, PyObject *key) if (!ELEM(idcode, ID_WM, ID_SCR, ID_WS)) { /* may need more added here */ const char *idtype = BKE_idcode_to_name(idcode); const char *pyname; - if (key && PyUnicode_Check(key)) pyname = _PyUnicode_AsString(key); - else pyname = "<UNKNOWN>"; + if (key && PyUnicode_Check(key)) { + pyname = _PyUnicode_AsString(key); + } + else { + pyname = "<UNKNOWN>"; + } /* make a nice string error */ BLI_assert(idtype != NULL); @@ -392,8 +396,9 @@ static int mathutils_rna_vector_get(BaseMathObject *bmo, int subtype) PYRNA_PROP_CHECK_INT(self); - if (self->prop == NULL) + if (self->prop == NULL) { return -1; + } RNA_property_float_get_array(&self->ptr, self->prop, bmo->data); @@ -414,8 +419,9 @@ static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype) PYRNA_PROP_CHECK_INT(self); - if (self->prop == NULL) + if (self->prop == NULL) { return -1; + } #ifdef USE_PEDANTIC_WRITE if (rna_disallow_writes && rna_id_write_error(&self->ptr, NULL)) { @@ -465,8 +471,9 @@ static int mathutils_rna_vector_get_index(BaseMathObject *bmo, int UNUSED(subtyp PYRNA_PROP_CHECK_INT(self); - if (self->prop == NULL) + if (self->prop == NULL) { return -1; + } bmo->data[index] = RNA_property_float_get_index(&self->ptr, self->prop, index); return 0; @@ -478,8 +485,9 @@ static int mathutils_rna_vector_set_index(BaseMathObject *bmo, int UNUSED(subtyp PYRNA_PROP_CHECK_INT(self); - if (self->prop == NULL) + if (self->prop == NULL) { return -1; + } #ifdef USE_PEDANTIC_WRITE if (rna_disallow_writes && rna_id_write_error(&self->ptr, NULL)) { @@ -522,8 +530,9 @@ static int mathutils_rna_matrix_get(BaseMathObject *bmo, int UNUSED(subtype)) PYRNA_PROP_CHECK_INT(self); - if (self->prop == NULL) + if (self->prop == NULL) { return -1; + } RNA_property_float_get_array(&self->ptr, self->prop, bmo->data); return 0; @@ -535,8 +544,9 @@ static int mathutils_rna_matrix_set(BaseMathObject *bmo, int UNUSED(subtype)) PYRNA_PROP_CHECK_INT(self); - if (self->prop == NULL) + if (self->prop == NULL) { return -1; + } #ifdef USE_PEDANTIC_WRITE if (rna_disallow_writes && rna_id_write_error(&self->ptr, NULL)) { @@ -639,8 +649,10 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop) totdim = RNA_property_array_dimension(ptr, prop, NULL); if (totdim == 1 || (totdim == 2 && subtype == PROP_MATRIX)) { - if (!is_thick) - ret = pyrna_prop_CreatePyObject(ptr, prop); /* owned by the mathutils PyObject */ + if (!is_thick) { + /* owned by the mathutils PyObject */ + ret = pyrna_prop_CreatePyObject(ptr, prop); + } switch (subtype) { case PROP_ALL_VECTOR_SUBTYPES: @@ -801,8 +813,9 @@ static PyObject *pyrna_struct_richcmp(PyObject *a, PyObject *b, int op) PyObject *res; int ok = -1; /* zero is true */ - if (BPy_StructRNA_Check(a) && BPy_StructRNA_Check(b)) + if (BPy_StructRNA_Check(a) && BPy_StructRNA_Check(b)) { ok = pyrna_struct_compare((BPy_StructRNA *)a, (BPy_StructRNA *)b); + } switch (op) { case Py_NE: @@ -831,8 +844,9 @@ static PyObject *pyrna_prop_richcmp(PyObject *a, PyObject *b, int op) PyObject *res; int ok = -1; /* zero is true */ - if (BPy_PropertyRNA_Check(a) && BPy_PropertyRNA_Check(b)) + if (BPy_PropertyRNA_Check(a) && BPy_PropertyRNA_Check(b)) { ok = pyrna_prop_compare((BPy_PropertyRNA *)a, (BPy_PropertyRNA *)b); + } switch (op) { case Py_NE: @@ -888,8 +902,10 @@ static PyObject *pyrna_struct_repr(BPy_StructRNA *self) PyObject *tmp_str; PyObject *ret; - if (id == NULL || !PYRNA_STRUCT_IS_VALID(self)) - return pyrna_struct_str(self); /* fallback */ + if (id == NULL || !PYRNA_STRUCT_IS_VALID(self)) { + /* fallback */ + return pyrna_struct_str(self); + } tmp_str = PyUnicode_FromString(id->name + 2); @@ -959,8 +975,9 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self) len = pyrna_prop_array_length((BPy_PropertyArrayRNA *)self); } - if (len != -1) + if (len != -1) { sprintf(--c, "[%d]", len); + } } /* if a pointer, try to print name of pointer target too */ @@ -1004,8 +1021,10 @@ static PyObject *pyrna_prop_repr_ex( PYRNA_PROP_CHECK_OBJ(self); - if (id == NULL) - return pyrna_prop_str(self); /* fallback */ + if (id == NULL) { + /* fallback */ + return pyrna_prop_str(self); + } tmp_str = PyUnicode_FromString(id->name + 2); @@ -1066,19 +1085,23 @@ static Py_hash_t pyrna_struct_hash(BPy_StructRNA *self) static long pyrna_prop_hash(BPy_PropertyRNA *self) { long x, y; - if (self->ptr.data == NULL) + if (self->ptr.data == NULL) { x = 0; + } else { x = _Py_HashPointer(self->ptr.data); - if (x == -1) + if (x == -1) { return -1; + } } y = _Py_HashPointer((void *)(self->prop)); - if (y == -1) + if (y == -1) { return -1; + } x ^= y; - if (x == -1) + if (x == -1) { x = -2; + } return x; } @@ -1425,8 +1448,9 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val) PyErr_Warn(PyExc_RuntimeWarning, error_str); #endif - if (ptr_name) + if (ptr_name) { MEM_freeN((void *)ptr_name); + } } ret = PyUnicode_FromString(""); @@ -1582,7 +1606,9 @@ int pyrna_pydict_to_props( while (PyDict_Next(kw, &pos, &key, &value)) { arg_name = _PyUnicode_AsString(key); - if (RNA_struct_find_property(ptr, arg_name) == NULL) break; + if (RNA_struct_find_property(ptr, arg_name) == NULL) { + break; + } arg_name = NULL; } @@ -1649,8 +1675,12 @@ static int pyrna_py_to_prop( return -1; } else { - if (data) *((bool *)data) = param; - else RNA_property_boolean_set(ptr, prop, param); + if (data) { + *((bool *)data) = param; + } + else { + RNA_property_boolean_set(ptr, prop, param); + } } break; } @@ -1755,8 +1785,12 @@ static int pyrna_py_to_prop( return -1; } else { - if (data) *((char **)data) = (char *)param; - else RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value)); + if (data) { + *((char **)data) = (char *)param; + } + else { + RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value)); + } } } else { @@ -1796,8 +1830,12 @@ static int pyrna_py_to_prop( else { /* same as bytes */ /* XXX, this is suspect but needed for function calls, need to see if theres a better way */ - if (data) *((char **)data) = (char *)param; - else RNA_property_string_set(ptr, prop, param); + if (data) { + *((char **)data) = (char *)param; + } + else { + RNA_property_string_set(ptr, prop, param); + } } #ifdef USE_STRING_COERCE Py_XDECREF(value_coerce); @@ -1823,8 +1861,12 @@ static int pyrna_py_to_prop( } } - if (data) *((int *)data) = val; - else RNA_property_enum_set(ptr, prop, val); + if (data) { + *((int *)data) = val; + } + else { + RNA_property_enum_set(ptr, prop, val); + } break; } @@ -1922,23 +1964,29 @@ static int pyrna_py_to_prop( if (flag_parameter & PARM_RNAPTR) { if (flag & PROP_THICK_WRAP) { - if (value == Py_None) + if (value == Py_None) { memset(data, 0, sizeof(PointerRNA)); - else if (RNA_struct_is_a(param->ptr.type, ptr_type)) + } + else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { *((PointerRNA *)data) = param->ptr; - else + } + else { raise_error = true; + } } else { /* for function calls, we sometimes want to pass the 'ptr' directly, * watch out that it remains valid!, possibly we could support this later if needed */ BLI_assert(value_new == NULL); - if (value == Py_None) + if (value == Py_None) { *((void **)data) = NULL; - else if (RNA_struct_is_a(param->ptr.type, ptr_type)) + } + else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { *((PointerRNA **)data) = ¶m->ptr; - else + } + else { raise_error = true; + } } } else if (value == Py_None) { @@ -1953,10 +2001,12 @@ static int pyrna_py_to_prop( } else { /* data == NULL, assign to RNA */ - if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type)) + if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type)) { RNA_property_pointer_set(ptr, prop, value == Py_None ? PointerRNA_NULL : param->ptr); - else + } + else { raise_error = true; + } } if (raise_error) { @@ -2027,8 +2077,9 @@ static int pyrna_py_to_prop( link->ptr = itemptr; BLI_addtail(lb, link); } - else + else { RNA_property_collection_add(ptr, prop, &itemptr); + } if (pyrna_pydict_to_props( &itemptr, item, true, @@ -2152,10 +2203,12 @@ static Py_ssize_t pyrna_prop_array_length(BPy_PropertyArrayRNA *self) { PYRNA_PROP_CHECK_INT((BPy_PropertyRNA *)self); - if (RNA_property_array_dimension(&self->ptr, self->prop, NULL) > 1) + if (RNA_property_array_dimension(&self->ptr, self->prop, NULL) > 1) { return RNA_property_multi_array_length(&self->ptr, self->prop, self->arraydim); - else + } + else { return RNA_property_array_length(&self->ptr, self->prop); + } } static Py_ssize_t pyrna_prop_collection_length(BPy_PropertyRNA *self) @@ -2271,10 +2324,13 @@ static PyObject *pyrna_prop_array_subscript_int(BPy_PropertyArrayRNA *self, int len = pyrna_prop_array_length(self); - if (keynum < 0) keynum += len; + if (keynum < 0) { + keynum += len; + } - if (keynum >= 0 && keynum < len) + if (keynum >= 0 && keynum < len) { return pyrna_prop_array_to_py_index(self, keynum); + } PyErr_Format(PyExc_IndexError, "bpy_prop_array[index]: index %d out of range", keynum); @@ -2287,8 +2343,9 @@ static PyObject *pyrna_prop_collection_subscript_str(BPy_PropertyRNA *self, cons PYRNA_PROP_CHECK_OBJ(self); - if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) + if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) { return pyrna_struct_CreatePyObject(&newptr); + } PyErr_Format(PyExc_KeyError, "bpy_prop_collection[key]: key \"%.200s\" not found", keyname); return NULL; @@ -2463,8 +2520,9 @@ static PyObject *pyrna_prop_array_subscript_slice( totdim = RNA_property_array_dimension(ptr, prop, NULL); if (totdim > 1) { - for (count = start; count < stop; count++) + for (count = start; count < stop; count++) { PyTuple_SET_ITEM(tuple, count - start, pyrna_prop_array_to_py_index(self, count)); + } } else { switch (RNA_property_type(prop)) { @@ -2476,8 +2534,9 @@ static PyObject *pyrna_prop_array_subscript_slice( else { values = values_stack; } RNA_property_float_get_array(ptr, prop, values); - for (count = start; count < stop; count++) + for (count = start; count < stop; count++) { PyTuple_SET_ITEM(tuple, count - start, PyFloat_FromDouble(values[count])); + } if (values != values_stack) { PyMem_FREE(values); @@ -2492,8 +2551,9 @@ static PyObject *pyrna_prop_array_subscript_slice( else { values = values_stack; } RNA_property_boolean_get_array(ptr, prop, values); - for (count = start; count < stop; count++) + for (count = start; count < stop; count++) { PyTuple_SET_ITEM(tuple, count - start, PyBool_FromLong(values[count])); + } if (values != values_stack) { PyMem_FREE(values); @@ -2508,8 +2568,9 @@ static PyObject *pyrna_prop_array_subscript_slice( else { values = values_stack; } RNA_property_int_get_array(ptr, prop, values); - for (count = start; count < stop; count++) + for (count = start; count < stop; count++) { PyTuple_SET_ITEM(tuple, count - start, PyLong_FromLong(values[count])); + } if (values != values_stack) { PyMem_FREE(values); @@ -2537,8 +2598,9 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject } else if (PyIndex_Check(key)) { Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return NULL; + } return pyrna_prop_collection_subscript_int(self, i); } @@ -2560,14 +2622,22 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ - if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) return NULL; - if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) return NULL; + if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { + return NULL; + } + if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { + return NULL; + } if (start < 0 || stop < 0) { /* only get the length for negative values */ Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop); - if (start < 0) start += len; - if (stop < 0) stop += len; + if (start < 0) { + start += len; + } + if (stop < 0) { + stop += len; + } } if (stop - start <= 0) { @@ -2662,8 +2732,9 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self, PyObject * #endif if (PyIndex_Check(key)) { Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return -1; + } return pyrna_prop_collection_ass_subscript_int(self, i, value); } @@ -2726,8 +2797,9 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject #endif if (PyIndex_Check(key)) { Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return NULL; + } return pyrna_prop_array_subscript_int(self, i); } else if (PySlice_Check(key)) { @@ -2751,8 +2823,9 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject int len = pyrna_prop_array_length(self); Py_ssize_t start, stop, slicelength; - if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) { return NULL; + } if (slicelength <= 0) { return PyTuple_New(0); @@ -2963,8 +3036,12 @@ static int prop_subscript_ass_array_slice( totdim - arraydim, &dimsize[arraydim], range); - if (PyErr_Occurred()) ret = -1; - else RNA_property_float_set_array(ptr, prop, values); + if (PyErr_Occurred()) { + ret = -1; + } + else { + RNA_property_float_set_array(ptr, prop, values); + } break; } case PROP_INT: @@ -2986,8 +3063,12 @@ static int prop_subscript_ass_array_slice( totdim - arraydim, &dimsize[arraydim], range); - if (PyErr_Occurred()) ret = -1; - else RNA_property_int_set_array(ptr, prop, values); + if (PyErr_Occurred()) { + ret = -1; + } + else { + RNA_property_int_set_array(ptr, prop, values); + } break; } case PROP_BOOLEAN: @@ -3006,8 +3087,12 @@ static int prop_subscript_ass_array_slice( value_items, &values[arrayoffset + (start * span)], totdim - arraydim, &dimsize[arraydim]); - if (PyErr_Occurred()) ret = -1; - else RNA_property_boolean_set_array(ptr, prop, values); + if (PyErr_Occurred()) { + ret = -1; + } + else { + RNA_property_boolean_set_array(ptr, prop, values); + } break; } default: @@ -3034,10 +3119,13 @@ static int prop_subscript_ass_array_int(BPy_PropertyArrayRNA *self, Py_ssize_t k len = pyrna_prop_array_length(self); - if (keynum < 0) keynum += len; + if (keynum < 0) { + keynum += len; + } - if (keynum >= 0 && keynum < len) + if (keynum >= 0 && keynum < len) { return pyrna_py_to_prop_array_index(self, keynum, value); + } PyErr_SetString(PyExc_IndexError, "bpy_prop_array[index] = value: index out of range"); @@ -3165,8 +3253,9 @@ static int pyrna_prop_collection_contains(BPy_PropertyRNA *self, PyObject *key) return -1; } - if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) + if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) { return 1; + } return 0; } @@ -3191,8 +3280,9 @@ static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value) group = RNA_struct_idprops(&self->ptr, 0); - if (!group) + if (!group) { return 0; + } return IDP_GetPropertyFromGroup(group, name) ? 1 : 0; } @@ -3335,8 +3425,9 @@ static PyObject *pyrna_struct_keys(BPy_PropertyRNA *self) group = RNA_struct_idprops(&self->ptr, 0); - if (group == NULL) + if (group == NULL) { return PyList_New(0); + } return BPy_Wrap_GetKeys(group); } @@ -3363,8 +3454,9 @@ static PyObject *pyrna_struct_items(BPy_PropertyRNA *self) group = RNA_struct_idprops(&self->ptr, 0); - if (group == NULL) + if (group == NULL) { return PyList_New(0); + } return BPy_Wrap_GetItems(self->ptr.id.data, group); } @@ -3391,8 +3483,9 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self) group = RNA_struct_idprops(&self->ptr, 0); - if (group == NULL) + if (group == NULL) { return PyList_New(0); + } return BPy_Wrap_GetValues(self->ptr.id.data, group); } @@ -3413,8 +3506,9 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg PYRNA_STRUCT_CHECK_OBJ(self); - if (!PyArg_ParseTuple(args, "s:is_property_set", &name)) + if (!PyArg_ParseTuple(args, "s:is_property_set", &name)) { return NULL; + } if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) { PyErr_Format(PyExc_TypeError, @@ -3438,8 +3532,9 @@ static PyObject *pyrna_struct_property_unset(BPy_StructRNA *self, PyObject *args PYRNA_STRUCT_CHECK_OBJ(self); - if (!PyArg_ParseTuple(args, "s:property_unset", &name)) + if (!PyArg_ParseTuple(args, "s:property_unset", &name)) { return NULL; + } if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) { PyErr_Format(PyExc_TypeError, @@ -3468,8 +3563,9 @@ static PyObject *pyrna_struct_is_property_hidden(BPy_StructRNA *self, PyObject * PYRNA_STRUCT_CHECK_OBJ(self); - if (!PyArg_ParseTuple(args, "s:is_property_hidden", &name)) + if (!PyArg_ParseTuple(args, "s:is_property_hidden", &name)) { return NULL; + } if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) { PyErr_Format(PyExc_TypeError, @@ -3496,8 +3592,9 @@ static PyObject *pyrna_struct_is_property_readonly(BPy_StructRNA *self, PyObject PYRNA_STRUCT_CHECK_OBJ(self); - if (!PyArg_ParseTuple(args, "s:is_property_readonly", &name)) + if (!PyArg_ParseTuple(args, "s:is_property_readonly", &name)) { return NULL; + } if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) { PyErr_Format(PyExc_TypeError, @@ -3592,8 +3689,9 @@ static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args) PYRNA_STRUCT_CHECK_OBJ(self); - if (!PyArg_ParseTuple(args, "s|O!:path_resolve", &path, &PyBool_Type, &coerce)) + if (!PyArg_ParseTuple(args, "s|O!:path_resolve", &path, &PyBool_Type, &coerce)) { return NULL; + } if (RNA_path_resolve_full(&self->ptr, path, &r_ptr, &r_prop, &index)) { if (r_prop) { @@ -3650,8 +3748,9 @@ static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args) PYRNA_STRUCT_CHECK_OBJ(self); - if (!PyArg_ParseTuple(args, "|s:path_from_id", &name)) + if (!PyArg_ParseTuple(args, "|s:path_from_id", &name)) { return NULL; + } if (name) { prop = RNA_struct_find_property(&self->ptr, name); @@ -3990,8 +4089,9 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA *self) * */ ret = PyList_New(0); - if (!BPy_StructRNA_CheckExact(self)) + if (!BPy_StructRNA_CheckExact(self)) { pyrna_dir_members_py(ret, (PyObject *)self); + } pyrna_dir_members_rna(ret, &self->ptr); @@ -4636,8 +4736,9 @@ static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self) nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); if (nameptr) { PyTuple_SET_ITEM(item, 0, PyUnicode_FromStringAndSize(nameptr, namelen)); - if (name != nameptr) + if (name != nameptr) { MEM_freeN(nameptr); + } } else { /* a bit strange but better then returning an empty list */ @@ -4693,8 +4794,9 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args) PYRNA_STRUCT_CHECK_OBJ(self); - if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) + if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) { return NULL; + } /* mostly copied from BPy_IDGroup_Map_GetItem */ if (RNA_struct_idprops_check(self->ptr.type) == 0) { @@ -4737,8 +4839,9 @@ static PyObject *pyrna_struct_pop(BPy_StructRNA *self, PyObject *args) PYRNA_STRUCT_CHECK_OBJ(self); - if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) + if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) { return NULL; + } /* mostly copied from BPy_IDGroup_Map_GetItem */ if (RNA_struct_idprops_check(self->ptr.type) == 0) { @@ -4801,14 +4904,16 @@ static PyObject *pyrna_prop_collection_get(BPy_PropertyRNA *self, PyObject *args PYRNA_PROP_CHECK_OBJ(self); - if (!PyArg_ParseTuple(args, "O|O:get", &key_ob, &def)) + if (!PyArg_ParseTuple(args, "O|O:get", &key_ob, &def)) { return NULL; + } if (PyUnicode_Check(key_ob)) { const char *key = _PyUnicode_AsString(key_ob); - if (RNA_property_collection_lookup_string(&self->ptr, self->prop, key, &newptr)) + if (RNA_property_collection_lookup_string(&self->ptr, self->prop, key, &newptr)) { return pyrna_struct_CreatePyObject(&newptr); + } } else if (PyTuple_Check(key_ob)) { PyObject *ret = pyrna_prop_collection_subscript_str_lib_pair(self, key_ob, @@ -4942,13 +5047,16 @@ static int foreach_parse_args( *size = RNA_raw_type_sizeof(*raw_type); #if 0 /* works fine but not strictly needed, we could allow RNA_property_collection_raw_* to do the checks */ - if ((*attr_tot) < 1) + if ((*attr_tot) < 1) { *attr_tot = 1; + } - if (RNA_property_type(self->prop) == PROP_COLLECTION) + if (RNA_property_type(self->prop) == PROP_COLLECTION) { array_tot = RNA_property_collection_length(&self->ptr, self->prop); - else + } + else { array_tot = RNA_property_array_length(&self->ptr, self->prop); + } target_tot = array_tot * (*attr_tot); @@ -4978,14 +5086,26 @@ static bool foreach_compat_buffer(RawPropertyType raw_type, int attr_signed, con switch (raw_type) { case PROP_RAW_CHAR: - if (attr_signed) return (f == 'b') ? 1 : 0; - else return (f == 'B') ? 1 : 0; + if (attr_signed) { + return (f == 'b') ? 1 : 0; + } + else { + return (f == 'B') ? 1 : 0; + } case PROP_RAW_SHORT: - if (attr_signed) return (f == 'h') ? 1 : 0; - else return (f == 'H') ? 1 : 0; + if (attr_signed) { + return (f == 'h') ? 1 : 0; + } + else { + return (f == 'H') ? 1 : 0; + } case PROP_RAW_INT: - if (attr_signed) return (f == 'i') ? 1 : 0; - else return (f == 'I') ? 1 : 0; + if (attr_signed) { + return (f == 'i') ? 1 : 0; + } + else { + return (f == 'I') ? 1 : 0; + } case PROP_RAW_BOOLEAN: return (f == '?') ? 1 : 0; case PROP_RAW_FLOAT: @@ -5013,11 +5133,13 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) bool attr_signed; RawPropertyType raw_type; - if (foreach_parse_args(self, args, &attr, &seq, &tot, &size, &raw_type, &attr_tot, &attr_signed) == -1) + if (foreach_parse_args(self, args, &attr, &seq, &tot, &size, &raw_type, &attr_tot, &attr_signed) == -1) { return NULL; + } - if (tot == 0) + if (tot == 0) { Py_RETURN_NONE; + } @@ -5098,7 +5220,10 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) ok = RNA_property_collection_raw_get(NULL, &self->ptr, self->prop, attr, array, raw_type, tot); - if (!ok) i = tot; /* skip the loop */ + if (!ok) { + /* skip the loop */ + i = tot; + } for ( ; i < tot; i++) { @@ -5135,8 +5260,9 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) } } - if (array) + if (array) { PyMem_Free(array); + } if (PyErr_Occurred()) { /* Maybe we could make our own error */ @@ -5348,8 +5474,9 @@ static PyObject *pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *UN { BPy_PropertyRNA *base; - if (!PyArg_ParseTuple(args, "O!:bpy_prop.__new__", &pyrna_prop_Type, &base)) + if (!PyArg_ParseTuple(args, "O!:bpy_prop.__new__", &pyrna_prop_Type, &base)) { return NULL; + } if (type == Py_TYPE(base)) { return Py_INCREF_RET((PyObject *)base); @@ -5383,8 +5510,9 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat len = data_alloc->array_tot; data = data_alloc->array; } - else + else { len = RNA_property_array_length(ptr, prop); + } /* resolve the array from a new pytype */ @@ -5393,13 +5521,15 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat switch (type) { case PROP_BOOLEAN: ret = PyTuple_New(len); - for (a = 0; a < len; a++) + for (a = 0; a < len; a++) { PyTuple_SET_ITEM(ret, a, PyBool_FromLong(((bool *)data)[a])); + } break; case PROP_INT: ret = PyTuple_New(len); - for (a = 0; a < len; a++) + for (a = 0; a < len; a++) { PyTuple_SET_ITEM(ret, a, PyLong_FromLong(((int *)data)[a])); + } break; case PROP_FLOAT: switch (RNA_property_subtype(prop)) { @@ -5420,8 +5550,9 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat #endif default: ret = PyTuple_New(len); - for (a = 0; a < len; a++) + for (a = 0; a < len; a++) { PyTuple_SET_ITEM(ret, a, PyFloat_FromDouble(((float *)data)[a])); + } break; } break; @@ -5451,10 +5582,12 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat PyObject *value_coerce = NULL; const int subtype = RNA_property_subtype(prop); - if (flag & PROP_THICK_WRAP) + if (flag & PROP_THICK_WRAP) { data_ch = (char *)data; - else + } + else { data_ch = *(char **)data; + } #ifdef USE_STRING_COERCE if (subtype == PROP_BYTESTRING) { @@ -5674,8 +5807,9 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject #else item = small_dict_get_item_string(kw, RNA_property_identifier(parm)); /* borrow ref */ #endif - if (item) + if (item) { kw_tot++; /* make sure invalid keywords are not given */ + } kw_arg = true; } @@ -5712,19 +5846,21 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject char error_prefix[512]; PyErr_Clear(); /* re-raise */ - if (kw_arg == true) + if (kw_arg == true) { BLI_snprintf(error_prefix, sizeof(error_prefix), "%.200s.%.200s(): error with keyword argument \"%.200s\" - ", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), RNA_property_identifier(parm)); - else + } + else { BLI_snprintf(error_prefix, sizeof(error_prefix), "%.200s.%.200s(): error with argument %d, \"%.200s\" - ", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), i, RNA_property_identifier(parm)); + } pyrna_py_to_prop(&funcptr, parm, iter.data, item, error_prefix); @@ -5783,8 +5919,9 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject RNA_parameter_list_begin(&parms, &iter); for (; iter.valid; RNA_parameter_list_next(&iter)) { parm = iter.parm; - if (RNA_parameter_flag(parm) & PARM_OUTPUT) + if (RNA_parameter_flag(parm) & PARM_OUTPUT) { continue; + } BLI_dynstr_appendf(good_args, first ? "%s" : ", %s", RNA_property_identifier(parm)); first = false; @@ -5831,18 +5968,21 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject for (; iter.valid; RNA_parameter_list_next(&iter)) { parm = iter.parm; - if (RNA_parameter_flag(parm) & PARM_OUTPUT) + if (RNA_parameter_flag(parm) & PARM_OUTPUT) { PyTuple_SET_ITEM(ret, i++, pyrna_param_to_py(&funcptr, parm, iter.data)); + } } RNA_parameter_list_end(&iter); } - else + else { ret = pyrna_param_to_py(&funcptr, pret_single, retdata_single); + } /* possible there is an error in conversion */ - if (ret == NULL) + if (ret == NULL) { err = -1; + } } } } @@ -5865,11 +6005,13 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject RNA_parameter_list_end(&iter); RNA_parameter_list_free(&parms); - if (ret) + if (ret) { return ret; + } - if (err == -1) + if (err == -1) { return NULL; + } Py_RETURN_NONE; } @@ -6660,8 +6802,9 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna) Py_INCREF(newclass); - if (RNA_struct_py_type_get(srna)) + if (RNA_struct_py_type_get(srna)) { PyC_ObSpit("RNA WAS SET - ", RNA_struct_py_type_get(srna)); + } Py_XDECREF(((PyObject *)RNA_struct_py_type_get(srna))); @@ -7074,30 +7217,38 @@ void BPY_rna_init(void) #endif /* metaclass */ - if (PyType_Ready(&pyrna_struct_meta_idprop_Type) < 0) + if (PyType_Ready(&pyrna_struct_meta_idprop_Type) < 0) { return; + } - if (PyType_Ready(&pyrna_struct_Type) < 0) + if (PyType_Ready(&pyrna_struct_Type) < 0) { return; + } - if (PyType_Ready(&pyrna_prop_Type) < 0) + if (PyType_Ready(&pyrna_prop_Type) < 0) { return; + } - if (PyType_Ready(&pyrna_prop_array_Type) < 0) + if (PyType_Ready(&pyrna_prop_array_Type) < 0) { return; + } - if (PyType_Ready(&pyrna_prop_collection_Type) < 0) + if (PyType_Ready(&pyrna_prop_collection_Type) < 0) { return; + } - if (PyType_Ready(&pyrna_prop_collection_idprop_Type) < 0) + if (PyType_Ready(&pyrna_prop_collection_idprop_Type) < 0) { return; + } - if (PyType_Ready(&pyrna_func_Type) < 0) + if (PyType_Ready(&pyrna_func_Type) < 0) { return; + } #ifdef USE_PYRNA_ITER - if (PyType_Ready(&pyrna_prop_collection_iter_Type) < 0) + if (PyType_Ready(&pyrna_prop_collection_iter_Type) < 0) { return; + } #endif } @@ -7239,8 +7390,9 @@ PyObject *BPY_rna_types(void) pyrna_basetype_Type.tp_flags = Py_TPFLAGS_DEFAULT; pyrna_basetype_Type.tp_methods = pyrna_basetype_methods; - if (PyType_Ready(&pyrna_basetype_Type) < 0) + if (PyType_Ready(&pyrna_basetype_Type) < 0) { return NULL; + } } /* static members for the base class */ @@ -7288,8 +7440,9 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, const bool parent, const char *e if (parent) { /* be very careful with this since it will return a parent classes srna. * modifying this will do confusing stuff! */ - if (py_srna == NULL) + if (py_srna == NULL) { py_srna = (BPy_StructRNA *)PyObject_GetAttr(self, bpy_intern_str_bl_rna); + } } if (py_srna == NULL) { @@ -7473,8 +7626,9 @@ static int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict) } ret = deferred_register_prop(srna, key, item); - if (ret != 0) + if (ret != 0) { break; + } } } @@ -7518,8 +7672,9 @@ int pyrna_deferred_register_class(StructRNA *srna, PyTypeObject *py_class) { /* Panels and Menus don't need this * save some time and skip the checks here */ - if (!RNA_struct_idprops_register_check(srna)) + if (!RNA_struct_idprops_register_check(srna)) { return 0; + } return pyrna_deferred_register_class_recursive(srna, py_class); } @@ -7541,16 +7696,18 @@ static int rna_function_arg_count(FunctionRNA *func, int *min_count) if (!(RNA_parameter_flag(parm) & PARM_OUTPUT)) { if (!done_min_count && (RNA_parameter_flag(parm) & PARM_PYFUNC_OPTIONAL)) { /* From now on, following parameters are optional in py func */ - if (min_count) + if (min_count) { *min_count = count; + } done_min_count = true; } count++; } } - if (!done_min_count && min_count) + if (!done_min_count && min_count) { *min_count = count; + } return count; } @@ -7567,8 +7724,9 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v const char *py_class_name = ((PyTypeObject *)py_class)->tp_name; /* __name__ */ if (srna_base) { - if (bpy_class_validate_recursive(dummyptr, srna_base, py_data, have_function) != 0) + if (bpy_class_validate_recursive(dummyptr, srna_base, py_data, have_function) != 0) { return -1; + } } if (base_class) { @@ -7591,8 +7749,9 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v * Keep this as-is since its working but we should be using 'FUNC_USE_SELF_TYPE' for many functions. */ const bool is_staticmethod = (flag & FUNC_NO_SELF) && !(flag & FUNC_USE_SELF_TYPE); - if (!(flag & FUNC_REGISTER)) + if (!(flag & FUNC_REGISTER)) { continue; + } item = PyObject_GetAttrString(py_class, RNA_function_identifier(func)); @@ -7672,8 +7831,9 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v PropertyRNA *prop = (PropertyRNA *)link; const int flag = RNA_property_flag(prop); - if (!(flag & PROP_REGISTER)) + if (!(flag & PROP_REGISTER)) { continue; + } /* TODO(campbell): Use Python3.7x _PyObject_LookupAttr(), also in the macro below. */ identifier = RNA_property_identifier(prop); @@ -7769,8 +7929,9 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param /* XXX, this is needed because render engine calls without a context * this should be supported at some point but at the moment its not! */ - if (C == NULL) + if (C == NULL) { C = BPy_GetContext(); + } /* annoying!, need to check if the screen gets set to NULL which is a * hint that the file was actually re-loaded. */ @@ -7792,8 +7953,9 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param } /* end exception */ - if (py_class_instance == NULL) + if (py_class_instance == NULL) { py_srna = pyrna_struct_CreatePyObject(ptr); + } if (py_class_instance) { /* special case, instance is cached */ @@ -8055,8 +8217,9 @@ static void bpy_class_free(void *pyob_ptr) /* remove the rna attribute instead. */ PyDict_DelItem(((PyTypeObject *)self)->tp_dict, bpy_intern_str_bl_rna); - if (PyErr_Occurred()) + if (PyErr_Occurred()) { PyErr_Clear(); + } #if 0 /* needs further investigation, too annoying so quiet for now */ if (G.debug & G_DEBUG_PYTHON) { @@ -8197,8 +8360,9 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class /* warning: gets parent classes srna, only for the register function */ srna = pyrna_struct_as_srna(py_class, true, "register_class(...):"); - if (srna == NULL) + if (srna == NULL) { return NULL; + } /* fails in cases, cant use this check but would like to :| */ #if 0 @@ -8245,8 +8409,9 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class /* python errors validating are not converted into reports so the check above will fail. * the cause for returning NULL will be printed as an error */ - if (srna_new == NULL) + if (srna_new == NULL) { return NULL; + } pyrna_subtype_set_rna(py_class, srna_new); /* takes a ref to py_class */ @@ -8260,8 +8425,9 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class * * item = PyObject_GetAttrString(py_class, "__dict__"); */ - if (pyrna_deferred_register_class(srna_new, (PyTypeObject *)py_class) != 0) + if (pyrna_deferred_register_class(srna_new, (PyTypeObject *)py_class) != 0) { return NULL; + } /* call classed register method () */ switch (_PyObject_LookupAttr(py_class, bpy_intern_str_register, &py_cls_meth)) { @@ -8354,8 +8520,9 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla } srna = pyrna_struct_as_srna(py_class, false, "unregister_class(...):"); - if (srna == NULL) + if (srna == NULL) { return NULL; + } /* check that we have a unregister callback for this type */ unreg = RNA_struct_unregister(srna); @@ -8423,8 +8590,9 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla unreg(CTX_data_main(C), srna); /* calls bpy_class_free, this decref's py_class */ PyDict_DelItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna); - if (PyErr_Occurred()) + if (PyErr_Occurred()) { PyErr_Clear(); //return NULL; + } Py_RETURN_NONE; } diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c index faead661f1f..a25906ac9a1 100644 --- a/source/blender/python/intern/bpy_rna_anim.c +++ b/source/blender/python/intern/bpy_rna_anim.c @@ -339,8 +339,9 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb } MEM_freeN((void *)path_full); - if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) + if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { return NULL; + } return PyBool_FromLong(result); } @@ -356,8 +357,9 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb result = insert_keyframe(G_MAIN, depsgraph, &reports, id, NULL, group_name, path_full, index, cfra, keytype, NULL, options); MEM_freeN((void *)path_full); - if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) + if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { return NULL; + } return PyBool_FromLong(result); } @@ -452,8 +454,9 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb } MEM_freeN((void *)path_full); - if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) + if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { return NULL; + } return PyBool_FromLong(result); } @@ -466,8 +469,9 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb result = delete_keyframe(G.main, &reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0); MEM_freeN((void *)path_full); - if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) + if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { return NULL; + } return PyBool_FromLong(result); } @@ -493,8 +497,9 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args) PYRNA_STRUCT_CHECK_OBJ(self); - if (!PyArg_ParseTuple(args, "s|i:driver_add", &path, &index)) + if (!PyArg_ParseTuple(args, "s|i:driver_add", &path, &index)) { return NULL; + } if (pyrna_struct_anim_args_parse( &self->ptr, "bpy_struct.driver_add():", path, @@ -512,8 +517,9 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args) result = ANIM_add_driver(&reports, (ID *)self->ptr.id.data, path_full, index, CREATEDRIVER_WITH_FMODIFIER, DRIVER_TYPE_PYTHON); - if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) + if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { return NULL; + } if (result) { ID *id = self->ptr.id.data; @@ -592,8 +598,9 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args) MEM_freeN((void *)path_full); } - if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) + if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { return NULL; + } WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION | ND_FCURVES_ORDER, NULL); diff --git a/source/blender/python/intern/bpy_rna_array.c b/source/blender/python/intern/bpy_rna_array.c index a87da8782bc..4cc3c4c0fae 100644 --- a/source/blender/python/intern/bpy_rna_array.c +++ b/source/blender/python/intern/bpy_rna_array.c @@ -276,8 +276,9 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA * * arr[2][3][4] = x * lvalue_dim = 2 */ - for (i = lvalue_dim; i < totdim; i++) + for (i = lvalue_dim; i < totdim; i++) { len *= dimsize[i]; + } } if (tot != len) { @@ -308,8 +309,9 @@ static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop, if (MatrixObject_Check(rvalue)) { MatrixObject *pymat = (MatrixObject *)rvalue; - if (BaseMath_ReadCallback(pymat) == -1) + if (BaseMath_ReadCallback(pymat) == -1) { return -1; + } if (RNA_property_type(prop) != PROP_FLOAT) { PyErr_Format(PyExc_ValueError, "%s %.200s.%.200s, matrix assign to non float array", @@ -512,8 +514,9 @@ static int py_to_array_index( lvalue_dim++; - for (i = lvalue_dim; i < totdim; i++) + for (i = lvalue_dim; i < totdim; i++) { index *= dimsize[i]; + } index += arrayoffset; @@ -751,8 +754,9 @@ static PyObject *pyrna_py_from_array_internal(PointerRNA *ptr, PropertyRNA *prop for (i = 0; i < len; i++) { PyObject *item; - if (dim + 1 < totdim) + if (dim + 1 < totdim) { item = pyrna_py_from_array_internal(ptr, prop, dim + 1, index); + } else { item = pyrna_array_index(ptr, prop, *index); *index = *index + 1; @@ -802,8 +806,9 @@ PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, * x = arr[2][3] * index = offset + 3 * 5 */ - for (i = arraydim + 1; i < totdim; i++) + for (i = arraydim + 1; i < totdim; i++) { index *= dimsize[i]; + } ret->arrayoffset = arrayoffset + index; } @@ -822,7 +827,9 @@ PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop) ret = pyrna_math_object_from_array(ptr, prop); /* is this a maths object? */ - if (ret) return ret; + if (ret) { + return ret; + } return pyrna_prop_CreatePyObject(ptr, prop); } @@ -834,8 +841,10 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) int type; int i; - if (len == 0) /* possible with dynamic arrays */ + if (len == 0) { + /* possible with dynamic arrays */ return 0; + } if (RNA_property_array_dimension(ptr, prop, NULL) > 1) { PyErr_SetString(PyExc_TypeError, "PropertyRNA - multi dimensional arrays not supported yet"); @@ -871,8 +880,9 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) } } - if (tmp_arr != tmp) + if (tmp_arr != tmp) { PyMem_FREE(tmp_arr); + } return i < len ? 1 : 0; } @@ -904,8 +914,9 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) } } - if (tmp_arr != tmp) + if (tmp_arr != tmp) { PyMem_FREE(tmp_arr); + } return i < len ? 1 : 0; } @@ -937,8 +948,9 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) } } - if (tmp_arr != tmp) + if (tmp_arr != tmp) { PyMem_FREE(tmp_arr); + } return i < len ? 1 : 0; } diff --git a/source/blender/python/intern/bpy_rna_callback.c b/source/blender/python/intern/bpy_rna_callback.c index 025ea586fee..30ea657200c 100644 --- a/source/blender/python/intern/bpy_rna_callback.c +++ b/source/blender/python/intern/bpy_rna_callback.c @@ -136,8 +136,9 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args) char *cb_event_str = NULL; int cb_event; - if (!PyArg_ParseTuple(args, "OO!|s:bpy_struct.callback_add", &cb_func, &PyTuple_Type, &cb_args, &cb_event_str)) + if (!PyArg_ParseTuple(args, "OO!|s:bpy_struct.callback_add", &cb_func, &PyTuple_Type, &cb_args, &cb_event_str)) { return NULL; + } if (!PyCallable_Check(cb_func)) { PyErr_SetString(PyExc_TypeError, "callback_add(): first argument isn't callable"); @@ -174,8 +175,9 @@ PyObject *pyrna_callback_remove(BPy_StructRNA *self, PyObject *args) void *handle; void *customdata; - if (!PyArg_ParseTuple(args, "O!:callback_remove", &PyCapsule_Type, &py_handle)) + if (!PyArg_ParseTuple(args, "O!:callback_remove", &PyCapsule_Type, &py_handle)) { return NULL; + } handle = PyCapsule_GetPointer(py_handle, rna_capsual_id); @@ -205,21 +207,21 @@ PyObject *pyrna_callback_remove(BPy_StructRNA *self, PyObject *args) /* reverse of rna_Space_refine() */ static eSpace_Type rna_Space_refine_reverse(StructRNA *srna) { - if (srna == &RNA_SpaceView3D) return SPACE_VIEW3D; - if (srna == &RNA_SpaceGraphEditor) return SPACE_GRAPH; - if (srna == &RNA_SpaceOutliner) return SPACE_OUTLINER; - if (srna == &RNA_SpaceProperties) return SPACE_PROPERTIES; - if (srna == &RNA_SpaceFileBrowser) return SPACE_FILE; - if (srna == &RNA_SpaceImageEditor) return SPACE_IMAGE; - if (srna == &RNA_SpaceInfo) return SPACE_INFO; - if (srna == &RNA_SpaceSequenceEditor) return SPACE_SEQ; - if (srna == &RNA_SpaceTextEditor) return SPACE_TEXT; - if (srna == &RNA_SpaceDopeSheetEditor) return SPACE_ACTION; - if (srna == &RNA_SpaceNLA) return SPACE_NLA; - if (srna == &RNA_SpaceNodeEditor) return SPACE_NODE; - if (srna == &RNA_SpaceConsole) return SPACE_CONSOLE; - if (srna == &RNA_SpacePreferences) return SPACE_USERPREF; - if (srna == &RNA_SpaceClipEditor) return SPACE_CLIP; + if (srna == &RNA_SpaceView3D) { return SPACE_VIEW3D; } + if (srna == &RNA_SpaceGraphEditor) { return SPACE_GRAPH; } + if (srna == &RNA_SpaceOutliner) { return SPACE_OUTLINER; } + if (srna == &RNA_SpaceProperties) { return SPACE_PROPERTIES; } + if (srna == &RNA_SpaceFileBrowser) { return SPACE_FILE; } + if (srna == &RNA_SpaceImageEditor) { return SPACE_IMAGE; } + if (srna == &RNA_SpaceInfo) { return SPACE_INFO; } + if (srna == &RNA_SpaceSequenceEditor) { return SPACE_SEQ; } + if (srna == &RNA_SpaceTextEditor) { return SPACE_TEXT; } + if (srna == &RNA_SpaceDopeSheetEditor) { return SPACE_ACTION; } + if (srna == &RNA_SpaceNLA) { return SPACE_NLA; } + if (srna == &RNA_SpaceNodeEditor) { return SPACE_NODE; } + if (srna == &RNA_SpaceConsole) { return SPACE_CONSOLE; } + if (srna == &RNA_SpacePreferences) { return SPACE_USERPREF; } + if (srna == &RNA_SpaceClipEditor) { return SPACE_CLIP; } return SPACE_EMPTY; } diff --git a/source/blender/python/intern/bpy_traceback.c b/source/blender/python/intern/bpy_traceback.c index dd4d96cb806..77cd8d8a9b7 100644 --- a/source/blender/python/intern/bpy_traceback.c +++ b/source/blender/python/intern/bpy_traceback.c @@ -58,17 +58,20 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, /* new style errors. `err' is an instance */ *message = _PyObject_GetAttrId(err, &PyId_msg); - if (!*message) + if (!*message) { goto finally; + } v = _PyObject_GetAttrId(err, &PyId_filename); - if (!v) + if (!v) { goto finally; + } if (v == Py_None) { Py_DECREF(v); *filename = _PyUnicode_FromId(&PyId_string); - if (*filename == NULL) + if (*filename == NULL) { goto finally; + } Py_INCREF(*filename); } else { @@ -76,31 +79,36 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, } v = _PyObject_GetAttrId(err, &PyId_lineno); - if (!v) + if (!v) { goto finally; + } hold = PyLong_AsLong(v); Py_DECREF(v); - if (hold < 0 && PyErr_Occurred()) + if (hold < 0 && PyErr_Occurred()) { goto finally; + } *lineno = (int)hold; v = _PyObject_GetAttrId(err, &PyId_offset); - if (!v) + if (!v) { goto finally; + } if (v == Py_None) { *offset = -1; Py_DECREF(v); } else { hold = PyLong_AsLong(v); Py_DECREF(v); - if (hold < 0 && PyErr_Occurred()) + if (hold < 0 && PyErr_Occurred()) { goto finally; + } *offset = (int)hold; } v = _PyObject_GetAttrId(err, &PyId_text); - if (!v) + if (!v) { goto finally; + } if (v == Py_None) { Py_DECREF(v); *text = NULL; |