diff options
Diffstat (limited to 'source/blender/python/generic')
-rw-r--r-- | source/blender/python/generic/idprop_py_api.c | 27 | ||||
-rw-r--r-- | source/blender/python/generic/py_capi_utils.c | 2 |
2 files changed, 24 insertions, 5 deletions
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c index 8c9e84af8ed..7fe282b2d71 100644 --- a/source/blender/python/generic/idprop_py_api.c +++ b/source/blender/python/generic/idprop_py_api.c @@ -296,10 +296,10 @@ static PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item) } /* returns NULL on success, error string on failure */ -static int idp_sequence_type(PyObject *seq_fast) +static char idp_sequence_type(PyObject *seq_fast) { PyObject *item; - int type = IDP_INT; + char type = IDP_INT; Py_ssize_t i, len = PySequence_Fast_GET_SIZE(seq_fast); for (i = 0; i < len; i++) { @@ -403,7 +403,7 @@ bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty *group, return false; } - if ((val.array.type = idp_sequence_type(ob_seq_fast)) == -1) { + if ((val.array.type = idp_sequence_type(ob_seq_fast)) == (char)-1) { Py_DECREF(ob_seq_fast); PyErr_SetString(PyExc_TypeError, "only floats, ints and dicts are allowed in ID property arrays"); return false; @@ -510,7 +510,26 @@ bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty *group, MEM_freeN(prop); } else { - IDP_ReplaceInGroup(group, prop); + IDProperty *prop_exist; + + /* avoid freeing when types match in case they are referenced by the UI, see: T37073 + * obviously this isn't a complete solution, but helps for common cases. */ + prop_exist = IDP_GetPropertyFromGroup(group, prop->name); + if ((prop_exist != NULL) && + (prop_exist->type == prop->type) && + (prop_exist->subtype == prop->subtype)) + { + /* Preserve prev/next links!!! See T42593. */ + prop->prev = prop_exist->prev; + prop->next = prop_exist->next; + + IDP_FreeProperty(prop_exist); + *prop_exist = *prop; + MEM_freeN(prop); + } + else { + IDP_ReplaceInGroup_ex(group, prop, prop_exist); + } } return true; diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 36ae30ada22..26deaf8d033 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -568,7 +568,7 @@ void PyC_MainModule_Restore(PyObject *main_mod) Py_XDECREF(main_mod); } -/* must be called before Py_Initialize, expects output of BLI_get_folder(BLENDER_PYTHON, NULL) */ +/* must be called before Py_Initialize, expects output of BKE_appdir_folder_id(BLENDER_PYTHON, NULL) */ void PyC_SetHomePath(const char *py_path_bundle) { if (py_path_bundle == NULL) { |