Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-05-04 08:26:42 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-05-04 08:29:05 +0300
commitf3c5b0394f095bb017c19c5a945c8e7714205bf2 (patch)
tree7d137f466a762e013216381ccf747951ded466c2 /source/blender/python/generic/idprop_py_api.c
parent16253285ff66039b2e861422e96a102e3118205a (diff)
IDProp API: expose repr utility function
Useful for logging properties passed to operators.
Diffstat (limited to 'source/blender/python/generic/idprop_py_api.c')
-rw-r--r--source/blender/python/generic/idprop_py_api.c58
1 files changed, 34 insertions, 24 deletions
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index 1153e0176df..164fe656129 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -30,6 +30,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
+#include "BLI_string.h"
#include "idprop_py_api.h"
@@ -1804,39 +1805,48 @@ PyObject *BPyInit_idprop(void)
return mod;
}
-
-#ifndef NDEBUG
/* -------------------------------------------------------------------- */
/* debug only function */
-void IDP_spit(IDProperty *prop)
+char *IDP_reprN(const IDProperty *prop)
{
- if (prop) {
- PyGILState_STATE gilstate;
- bool use_gil = true; /* !PyC_IsInterpreterActive(); */
- PyObject *ret_dict;
- PyObject *ret_str;
+ if (prop == NULL) {
+ return BLI_strdup("None");
+ }
- if (use_gil) {
- gilstate = PyGILState_Ensure();
- }
+ PyGILState_STATE gilstate;
+ bool use_gil = true; /* !PyC_IsInterpreterActive(); */
+ PyObject *ret_dict;
+ PyObject *ret_str;
- /* to_dict() */
- ret_dict = BPy_IDGroup_MapDataToPy(prop);
- ret_str = PyObject_Repr(ret_dict);
- Py_DECREF(ret_dict);
+ if (use_gil) {
+ gilstate = PyGILState_Ensure();
+ }
- printf("IDProperty(%p): %s\n", prop, _PyUnicode_AsString(ret_str));
+ /* Note: non-const cast is safe here since we only repr the result. */
+ /* to_dict() */
+ ret_dict = BPy_IDGroup_MapDataToPy((IDProperty *)prop);
+ ret_str = PyObject_Repr(ret_dict);
+ Py_DECREF(ret_dict);
- Py_DECREF(ret_str);
+ Py_ssize_t res_str_len = 0;
+ char *res_str_bytes = _PyUnicode_AsStringAndSize(ret_str, &res_str_len);
- if (use_gil) {
- PyGILState_Release(gilstate);
- }
- }
- else {
- printf("IDProperty: <NIL>\n");
+ res_str_bytes = BLI_strdupn(res_str_bytes, res_str_len);
+
+ Py_DECREF(ret_str);
+
+ if (use_gil) {
+ PyGILState_Release(gilstate);
}
+ return res_str_bytes;
+}
+
+
+void IDP_print(const IDProperty *prop)
+{
+ char *repr = IDP_reprN(prop);
+ printf("IDProperty(%p): %s\n", prop, repr);
+ MEM_freeN(repr);
}
-#endif