From b5f77973a762b897892a39230095943f23a7f9c6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 22 Oct 2019 17:37:52 +1100 Subject: Cleanup: remove BLI_dynstr use in py_capi_utils Needed for standalone mathutils module. --- source/blender/python/generic/py_capi_utils.c | 34 +++++++++++---------------- source/blender/python/generic/py_capi_utils.h | 2 +- 2 files changed, 15 insertions(+), 21 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; } diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index 1f552c3d78d..5be44ad1af6 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -99,7 +99,7 @@ typedef struct PyC_FlagSet { const char *identifier; } PyC_FlagSet; -char *PyC_FlagSet_AsString(PyC_FlagSet *item); +PyObject *PyC_FlagSet_AsString(PyC_FlagSet *item); int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *r_value); int PyC_FlagSet_ValueFromID(PyC_FlagSet *item, const char *identifier, -- cgit v1.2.3 From bfa9ead12a30aef45592deabaa82d64dd895b5a0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 22 Oct 2019 17:38:55 +1100 Subject: Cleanup: quiet unknown escape warnings Auto-complete showed errors. --- release/scripts/modules/console/intellisense.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/release/scripts/modules/console/intellisense.py b/release/scripts/modules/console/intellisense.py index 84d4bff281d..6dd858f4bdf 100644 --- a/release/scripts/modules/console/intellisense.py +++ b/release/scripts/modules/console/intellisense.py @@ -35,20 +35,20 @@ import re # regular expressions to find out which completer we need # line which starts with an import statement -RE_MODULE = re.compile('^import(\s|$)|from.+') +RE_MODULE = re.compile(r'''^import(\s|$)|from.+''') # The following regular expression means an 'unquoted' word RE_UNQUOTED_WORD = re.compile( # don't start with a quote - '''(?:^|[^"'a-zA-Z0-9_])''' + r'''(?:^|[^"'a-zA-Z0-9_])''' # start with a \w = [a-zA-Z0-9_] - '''((?:\w+''' + r'''((?:\w+''' # allow also dots and closed bracket pairs [] - '''(?:\w|[.]|\[.+?\])*''' + r'''(?:\w|[.]|\[.+?\])*''' # allow empty string - '''|)''' + r'''|)''' # allow an unfinished index at the end (including quotes) - '''(?:\[[^\]]*$)?)$''', + r'''(?:\[[^\]]*$)?)$''', # allow unicode as theoretically this is possible re.UNICODE) -- cgit v1.2.3