41 int lineno, lineno_end;
42 int offset, offset_end;
47 txt_move_to(text, lineno_end - 1, offset_end - 1,
false);
56 const size_t filepath_maxncpy,
77 PyCompilerFlags *flags)
84 bool use_file_handle_workaround =
true;
86 bool use_file_handle_workaround =
false;
89 if (!use_file_handle_workaround) {
90 return PyRun_FileExFlags(fp, filepath, start, globals, locals, closeit, flags);
93 PyObject *py_result =
nullptr;
101 PyErr_Format(PyExc_IOError,
"Python file \"%s\" could not read buffer", filepath);
106 PyObject *compiled = Py_CompileStringObject(buf, filepath_py, Py_file_input, flags, -1);
108 Py_DECREF(filepath_py);
110 if (compiled ==
nullptr) {
115 py_result = PyEval_EvalCode(compiled, globals, locals);
134 if (filepath ==
nullptr && text ==
nullptr) {
138 PyGILState_STATE gilstate;
142 PyObject *py_dict =
nullptr, *py_result =
nullptr;
146 const char *filepath_namespace =
nullptr;
152 filepath_namespace = filepath_dummy;
156 size_t buf_len_dummy;
158 text->
compiled = Py_CompileStringObject(buf, filepath_dummy_py, Py_file_input,
nullptr, -1);
160 Py_DECREF(filepath_dummy_py);
165 py_result = PyEval_EvalCode(
static_cast<PyObject *
>(text->
compiled), py_dict, py_dict);
170 filepath_namespace = filepath;
177 PyErr_Format(PyExc_IsADirectoryError,
"Python file \"%s\" is a directory", filepath);
183 const int closeit = 1;
186 fp, filepath, Py_file_input, py_dict, py_dict, closeit,
nullptr);
191 PyExc_IOError,
"Python file \"%s\" could not be opened: %s", filepath, strerror(errno));
215 Py_DECREF(py_result);
226 return (py_result !=
nullptr);
250 const char *imports[],
255 PyGILState_STATE gilstate;
256 PyObject *py_dict, *retval;
259 if (expr[0] ==
'\0') {
274 retval = PyRun_String(expr, mode, py_dict, py_dict);
277 if (retval ==
nullptr) {
319 if (err_info ==
nullptr) {
333 const char *err_str = PyUnicode_AsUTF8(py_err_str);
336 if (err_info->
reports !=
nullptr) {
350 fprintf(stderr,
"%s\n", err_str);
353 if (err_info->
r_string !=
nullptr) {
357 Py_XDECREF(py_err_str);
361 const char *imports[],
368 if (expr[0] ==
'\0') {
373 PyGILState_STATE gilstate;
388 const char *imports[],
396 if (expr[0] ==
'\0') {
401 PyGILState_STATE gilstate;
418 size_t value_dummy_len;
423 const char *imports[],
431 if (expr[0] ==
'\0') {
436 PyGILState_STATE gilstate;
440 imports, expr,
"<expr as str or none>", r_value, r_value_len);
454 size_t value_dummy_len;
456 C, imports, expr, err_info, r_value, &value_dummy_len);
460 const char *imports[],
467 if (expr[0] ==
'\0') {
472 PyGILState_STATE gilstate;
ReportList * CTX_wm_reports(const bContext *C)
Main * CTX_data_main(const bContext *C)
bool BKE_reports_print_test(const ReportList *reports, eReportType type)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
char * txt_to_buf(struct Text *text, size_t *r_buf_strlen) ATTR_NONNULL(1
void txt_move_to(struct Text *text, unsigned int line, unsigned int ch, bool sel)
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_fstat(int fd, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void * BLI_file_read_data_as_mem_from_handle(FILE *fp, bool read_size_exact, size_t pad_bytes, size_t *r_size)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
Read Guarded memory(de)allocation.
bool BPy_errors_to_report(ReportList *reports)
void bpy_context_clear(struct bContext *C, const PyGILState_STATE *gilstate)
void bpy_context_set(struct bContext *C, PyGILState_STATE *gilstate)
bool BPY_run_string_as_string(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value)
bool BPY_run_filepath(bContext *C, const char *filepath, ReportList *reports)
bool BPY_run_string_as_number(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, double *r_value)
static void python_script_error_jump_text(Text *text, const char *filepath)
bool BPY_run_string_eval(bContext *C, const char *imports[], const char *expr)
bool BPY_run_string_as_string_and_len_or_none(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_len)
static PyObject * python_compat_wrapper_PyRun_FileExFlags(FILE *fp, const char *filepath, const int start, PyObject *globals, PyObject *locals, const int closeit, PyCompilerFlags *flags)
bool BPY_run_string_exec(bContext *C, const char *imports[], const char *expr)
bool BPY_run_string_as_intptr(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, intptr_t *r_value)
static bool python_script_exec(bContext *C, const char *filepath, Text *text, ReportList *reports, const bool do_jump)
static void run_string_handle_error(BPy_RunErrInfo *err_info)
bool BPY_run_string_as_string_and_len(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_len)
bool BPY_run_string_as_string_or_none(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value)
bool BPY_run_text(bContext *C, Text *text, ReportList *reports, const bool do_jump)
static void bpy_text_filepath_get(char *filepath, const size_t filepath_maxncpy, const Main *bmain, const Text *text)
static bool bpy_run_string_impl(bContext *C, const char *imports[], const char *expr, const int mode)
bool python_script_error_jump(const char *filepath, int *r_lineno, int *r_offset, int *r_lineno_end, int *r_offset_end)
#define ID_BLEND_PATH(_bmain, _id)
void MEM_freeN(void *vmemh)
PyObject * PyC_DefaultNameSpace(const char *filename)
bool PyC_RunString_AsStringAndSizeOrNone(const char *imports[], const char *expr, const char *filename, char **r_value, size_t *r_value_size)
PyObject * PyC_UnicodeFromBytes(const char *str)
PyObject * PyC_ExceptionBuffer()
bool PyC_RunString_AsNumber(const char *imports[], const char *expr, const char *filename, double *r_value)
PyObject * PyC_ExceptionBuffer_Simple()
PyObject * PyC_MainModule_Backup()
bool PyC_RunString_AsStringAndSize(const char *imports[], const char *expr, const char *filename, char **r_value, size_t *r_value_size)
bool PyC_NameSpace_ImportArray(PyObject *py_dict, const char *imports[])
void PyC_MainModule_Restore(PyObject *main_mod)
bool PyC_RunString_AsIntPtr(const char *imports[], const char *expr, const char *filename, intptr_t *r_value)
const char * report_prefix
bool use_single_line_error