PyAPI: support retrieving the exception when running a string

- Optionally get the error as a single line.
- Support access the error as an allocated string.
- PyC_ExceptionBuffer_Simple was always printing to the `stdout` while
  PyC_ExceptionBuffer didn't, now either print to the output.

Without this, callers are unable to do anything with the error string.
This commit is contained in:
2021-04-12 21:39:56 +10:00
parent 8d9fd0427d
commit f5060bc901
8 changed files with 106 additions and 44 deletions

View File

@@ -42,27 +42,43 @@ bool BPY_run_text(struct bContext *C,
bool BPY_run_string_exec(struct bContext *C, const char *imports[], const char *expr);
bool BPY_run_string_eval(struct bContext *C, const char *imports[], const char *expr);
/**
* \note When this struct is passed in as NULL,
* print errors to the `stdout` and clear.
*/
struct BPy_RunErrInfo {
/** Brief text, single line (can show this in status bar for e.g.). */
bool use_single_line_error;
/** Report with optional prefix (when non-NULL). */
struct ReportList *reports;
const char *report_prefix;
/** Allocated exception text (assign when non-NULL). */
char **r_string;
};
/* Run, evaluating to fixed type result. */
bool BPY_run_string_as_number(struct bContext *C,
const char *imports[],
const char *expr,
const char *report_prefix,
struct BPy_RunErrInfo *err_info,
double *r_value);
bool BPY_run_string_as_intptr(struct bContext *C,
const char *imports[],
const char *expr,
const char *report_prefix,
struct BPy_RunErrInfo *err_info,
intptr_t *r_value);
bool BPY_run_string_as_string_and_size(struct bContext *C,
const char *imports[],
const char *expr,
const char *report_prefix,
struct BPy_RunErrInfo *err_info,
char **r_value,
size_t *r_value_size);
bool BPY_run_string_as_string(struct bContext *C,
const char *imports[],
const char *expr,
const char *report_prefix,
struct BPy_RunErrInfo *err_info,
char **r_value);
#ifdef __cplusplus