diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-10-22 09:37:52 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-10-22 09:38:48 +0300 |
commit | b5f77973a762b897892a39230095943f23a7f9c6 (patch) | |
tree | 217b32d657b609d3e6195f39fbf47282f86ab4ee /source/blender/python/generic/py_capi_utils.c | |
parent | 6f779218fb6d04d5493cf8aff6884ebe18ffdc1e (diff) |
Cleanup: remove BLI_dynstr use in py_capi_utils
Needed for standalone mathutils module.
Diffstat (limited to 'source/blender/python/generic/py_capi_utils.c')
-rw-r--r-- | source/blender/python/generic/py_capi_utils.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index c85a1d9ba05..49e88ac0274 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -43,9 +43,11 @@ #include "python_utildefines.h" -#include "BLI_string.h" - #ifndef MATH_STANDALONE +# include "MEM_guardedalloc.h" + +# include "BLI_string.h" + /* Only for BLI_strncpy_wchar_from_utf8, * should replace with py funcs but too late in release now. */ # include "BLI_string_utf8.h" @@ -1049,23 +1051,15 @@ void *PyC_RNA_AsPointer(PyObject *value, const char *type_name) } } -/* PyC_FlagSet_* functions - so flags/sets can be interchanged in a generic way */ -# include "BLI_dynstr.h" -# include "MEM_guardedalloc.h" - -char *PyC_FlagSet_AsString(PyC_FlagSet *item) +PyObject *PyC_FlagSet_AsString(PyC_FlagSet *item) { - DynStr *dynstr = BLI_dynstr_new(); - PyC_FlagSet *e; - char *cstring; - - for (e = item; item->identifier; item++) { - BLI_dynstr_appendf(dynstr, (e == item) ? "'%s'" : ", '%s'", item->identifier); + PyObject *py_items = PyList_New(0); + for (; item->identifier; item++) { + PyList_APPEND(py_items, PyUnicode_FromString(item->identifier)); } - - cstring = BLI_dynstr_get_cstring(dynstr); - BLI_dynstr_free(dynstr); - return cstring; + PyObject *py_string = PyObject_Repr(py_items); + Py_DECREF(py_items); + return py_string; } int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *r_value) @@ -1086,10 +1080,10 @@ int PyC_FlagSet_ValueFromID(PyC_FlagSet *item, const char *error_prefix) { if (PyC_FlagSet_ValueFromID_int(item, identifier, r_value) == 0) { - const char *enum_str = PyC_FlagSet_AsString(item); + PyObject *enum_str = PyC_FlagSet_AsString(item); PyErr_Format( - PyExc_ValueError, "%s: '%.200s' not found in (%s)", error_prefix, identifier, enum_str); - MEM_freeN((void *)enum_str); + PyExc_ValueError, "%s: '%.200s' not found in (%U)", error_prefix, identifier, enum_str); + Py_DECREF(enum_str); return -1; } |