PyAPI: add utility functions get the size from an evaluated string

Allows including null bytes in the resulting string.
This commit is contained in:
2019-12-11 18:04:44 +11:00
parent f52d60a21d
commit 576d385ddb
4 changed files with 41 additions and 7 deletions

View File

@@ -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.
*