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 PyObject *py_dict =
nullptr, *py_result =
nullptr;
135 PyGILState_STATE gilstate;
139 const char *filepath_namespace =
nullptr;
143 if (filepath ==
nullptr && text ==
nullptr) {
153 filepath_namespace = filepath_dummy;
155 if (text->compiled ==
nullptr) {
157 size_t buf_len_dummy;
159 text->compiled = Py_CompileStringObject(buf, filepath_dummy_py, Py_file_input,
nullptr, -1);
161 Py_DECREF(filepath_dummy_py);
164 if (text->compiled) {
166 py_result = PyEval_EvalCode(
static_cast<PyObject *
>(text->compiled), py_dict, py_dict);
171 filepath_namespace = filepath;
178 PyErr_Format(PyExc_IsADirectoryError,
"Python file \"%s\" is a directory", filepath);
184 const int closeit = 1;
187 fp, filepath, Py_file_input, py_dict, py_dict, closeit,
nullptr);
192 PyExc_IOError,
"Python file \"%s\" could not be opened: %s", filepath, strerror(errno));
216 Py_DECREF(py_result);
223 return (py_result !=
nullptr);
247 const char *imports[],
252 PyGILState_STATE gilstate;
253 PyObject *py_dict, *retval;
256 if (expr[0] ==
'\0') {
271 retval = PyRun_String(expr, mode, py_dict, py_dict);
274 if (retval ==
nullptr) {
316 if (err_info ==
nullptr) {
330 const char *err_str = PyUnicode_AsUTF8(py_err_str);
333 if (err_info->
reports !=
nullptr) {
347 fprintf(stderr,
"%s\n", err_str);
350 if (err_info->
r_string !=
nullptr) {
354 Py_XDECREF(py_err_str);
358 const char *imports[],
363 PyGILState_STATE gilstate;
366 if (expr[0] ==
'\0') {
385 const char *imports[],
391 PyGILState_STATE gilstate;
394 if (expr[0] ==
'\0') {
415 size_t value_dummy_len;
420 const char *imports[],
426 PyGILState_STATE gilstate;
429 if (expr[0] ==
'\0') {
437 imports, expr,
"<expr as str or none>", r_value, r_value_len);
451 size_t value_dummy_len;
453 C, imports, expr, err_info, r_value, &value_dummy_len);
457 const char *imports[],
462 PyGILState_STATE gilstate;
465 if (expr[0] ==
'\0') {
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 struct 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
#define ID_BLEND_PATH(_bmain, _id)
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)
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