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

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