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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-12-11 10:04:44 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-12-11 10:04:44 +0300
commit576d385ddb581190d21febfa724086797c47492a (patch)
tree841744bda1ec26fdd4a9af7113b6fb746a5d53fd /source
parentf52d60a21d4d3551190305549dbb2a647a1ae0c9 (diff)
PyAPI: add utility functions get the size from an evaluated string
Allows including null bytes in the resulting string.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/BPY_extern.h6
-rw-r--r--source/blender/python/generic/py_capi_utils.c19
-rw-r--r--source/blender/python/generic/py_capi_utils.h5
-rw-r--r--source/blender/python/intern/bpy_interface.c18
4 files changed, 41 insertions, 7 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index 11c06f6191e..be2fd6c4e53 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -85,6 +85,12 @@ bool BPY_execute_string_as_intptr(struct bContext *C,
const char *expr,
const bool verbose,
intptr_t *r_value);
+bool BPY_execute_string_as_string_and_size(struct bContext *C,
+ const char *imports[],
+ const char *expr,
+ const bool verbose,
+ char **r_value,
+ size_t *r_value_size);
bool BPY_execute_string_as_string(struct bContext *C,
const char *imports[],
const char *expr,
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
index 8470d1ccdf3..8ea627589f2 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -1257,10 +1257,11 @@ bool PyC_RunString_AsIntPtr(const char *imports[],
return ok;
}
-bool PyC_RunString_AsString(const char *imports[],
- const char *expr,
- const char *filename,
- char **r_value)
+bool PyC_RunString_AsStringAndSize(const char *imports[],
+ const char *expr,
+ const char *filename,
+ char **r_value,
+ size_t *r_value_size)
{
PyObject *py_dict, *retval;
bool ok = true;
@@ -1288,6 +1289,7 @@ bool PyC_RunString_AsString(const char *imports[],
char *val_alloc = MEM_mallocN(val_len + 1, __func__);
memcpy(val_alloc, val, val_len + 1);
*r_value = val_alloc;
+ *r_value_size = val_len;
}
Py_DECREF(retval);
@@ -1298,6 +1300,15 @@ bool PyC_RunString_AsString(const char *imports[],
return ok;
}
+bool PyC_RunString_AsString(const char *imports[],
+ const char *expr,
+ const char *filename,
+ char **r_value)
+{
+ size_t value_size;
+ return PyC_RunString_AsStringAndSize(imports, expr, filename, r_value, &value_size);
+}
+
#endif /* #ifndef MATH_STANDALONE */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h
index 5be44ad1af6..5fb5737e1f9 100644
--- a/source/blender/python/generic/py_capi_utils.h
+++ b/source/blender/python/generic/py_capi_utils.h
@@ -119,6 +119,11 @@ bool PyC_RunString_AsIntPtr(const char **imports,
const char *expr,
const char *filename,
intptr_t *r_value);
+bool PyC_RunString_AsStringAndSize(const char **imports,
+ const char *expr,
+ const char *filename,
+ char **r_value,
+ size_t *r_value_size);
bool PyC_RunString_AsString(const char **imports,
const char *expr,
const char *filename,
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index a69ce068aec..2b9556e998a 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -618,8 +618,12 @@ bool BPY_execute_string_as_number(
/**
* \return success
*/
-bool BPY_execute_string_as_string(
- bContext *C, const char *imports[], const char *expr, const bool verbose, char **r_value)
+bool BPY_execute_string_as_string_and_size(bContext *C,
+ const char *imports[],
+ const char *expr,
+ const bool verbose,
+ char **r_value,
+ size_t *r_value_size)
{
BLI_assert(r_value && expr);
PyGILState_STATE gilstate;
@@ -632,7 +636,7 @@ bool BPY_execute_string_as_string(
bpy_context_set(C, &gilstate);
- ok = PyC_RunString_AsString(imports, expr, "<expr as str>", r_value);
+ ok = PyC_RunString_AsStringAndSize(imports, expr, "<expr as str>", r_value, r_value_size);
if (ok == false) {
if (verbose) {
@@ -648,6 +652,14 @@ bool BPY_execute_string_as_string(
return ok;
}
+bool BPY_execute_string_as_string(
+ bContext *C, const char *imports[], const char *expr, const bool verbose, char **r_value)
+{
+ size_t value_dummy_size;
+ return BPY_execute_string_as_string_and_size(
+ C, imports, expr, verbose, r_value, &value_dummy_size);
+}
+
/**
* Support both int and pointers.
*