42 int lineno, lineno_end;
43 int offset, offset_end;
48 txt_move_to(text, lineno_end - 1, offset_end - 1,
false);
57 const size_t filepath_maxncpy,
74 PyCompilerFlags *flags)
81 bool use_file_handle_workaround =
true;
83 bool use_file_handle_workaround =
false;
86 if (!use_file_handle_workaround) {
87 return PyRun_FileExFlags(fp, filepath, start, globals, locals, closeit, flags);
90 PyObject *py_result =
nullptr;
98 PyErr_Format(PyExc_IOError,
"Python file \"%s\" could not read buffer", filepath);
103 PyObject *compiled = Py_CompileStringObject(buf, filepath_py, Py_file_input, flags, -1);
107 if (compiled ==
nullptr) {
112 py_result = PyEval_EvalCode(compiled, globals, locals);
131 if (filepath ==
nullptr && text ==
nullptr) {
135 PyGILState_STATE gilstate;
139 PyObject *py_dict =
nullptr, *py_result =
nullptr;
143 const char *filepath_namespace =
nullptr;
149 filepath_namespace = filepath_dummy;
153 size_t buf_len_dummy;
155 text->
compiled = Py_CompileStringObject(buf, filepath_dummy_py, Py_file_input,
nullptr, -1);
162 py_result = PyEval_EvalCode(
static_cast<PyObject *
>(text->
compiled), py_dict, py_dict);
167 filepath_namespace = filepath;
174 PyErr_Format(PyExc_IsADirectoryError,
"Python file \"%s\" is a directory", filepath);
180 const int closeit = 1;
183 fp, filepath, Py_file_input, py_dict, py_dict, closeit,
nullptr);
188 PyExc_IOError,
"Python file \"%s\" could not be opened: %s", filepath, strerror(errno));
225 return (py_result !=
nullptr);
249 const char *imports[],
254 PyGILState_STATE gilstate;
255 PyObject *py_dict, *retval;
258 if (expr[0] ==
'\0') {
273 retval = PyRun_String(expr, mode, py_dict, py_dict);
276 if (retval ==
nullptr) {
317 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[],
365 if (expr[0] ==
'\0') {
370 PyGILState_STATE gilstate;
385 const char *imports[],
393 if (expr[0] ==
'\0') {
398 PyGILState_STATE gilstate;
415 size_t value_dummy_len;
420 const char *imports[],
428 if (expr[0] ==
'\0') {
433 PyGILState_STATE gilstate;
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[],
464 if (expr[0] ==
'\0') {
469 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
#define BLI_string_join_by_sep_char(...)
#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