46 #include "../generic/py_capi_utils.h"
71 #define PYMODULE_CLEAR_WORKAROUND
73 #ifdef PYMODULE_CLEAR_WORKAROUND
86 PyObject *main_mod =
NULL;
87 PyObject *py_dict =
NULL, *py_result =
NULL;
88 PyGILState_STATE gilstate;
106 PyObject *fn_dummy_py;
111 text->
compiled = Py_CompileStringObject(buf, fn_dummy_py, Py_file_input,
NULL, -1);
114 Py_DECREF(fn_dummy_py);
116 if (PyErr_Occurred()) {
126 py_result = PyEval_EvalCode(text->
compiled, py_dict, py_dict);
151 const char *pystring =
152 "with open(__file__, 'rb') as f:"
153 "exec(compile(f.read(), __file__, 'exec'), globals().__delitem__('f') or globals())";
157 py_result = PyRun_String(pystring, Py_file_input, py_dict, py_dict);
160 py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);
166 PyExc_IOError,
"Python file \"%s\" could not be opened: %s", fn, strerror(errno));
184 Py_DECREF(py_result);
188 #ifdef PYMODULE_CLEAR_WORKAROUND
191 PyObject *dict_back = mmod->
md_dict;
195 Py_DECREF(dict_back);
198 #undef PYMODULE_CLEAR_WORKAROUND
205 return (py_result !=
NULL);
230 const char *imports[],
235 PyGILState_STATE gilstate;
236 PyObject *main_mod =
NULL;
237 PyObject *py_dict, *retval;
240 if (expr[0] ==
'\0') {
255 retval = PyRun_String(expr, mode, py_dict, py_dict);
258 if (retval ==
NULL) {
300 if (err_info ==
NULL) {
314 const char *err_str = py_err_str ? PyUnicode_AsUTF8(py_err_str) :
"Unable to extract exception";
329 Py_XDECREF(py_err_str);
336 const char *imports[],
341 PyGILState_STATE gilstate;
344 if (!r_value || !expr) {
348 if (expr[0] ==
'\0') {
370 const char *imports[],
374 size_t *r_value_size)
377 PyGILState_STATE gilstate;
380 if (expr[0] ==
'\0') {
399 const char *imports[],
404 size_t value_dummy_size;
414 const char *imports[],
420 PyGILState_STATE gilstate;
423 if (expr[0] ==
'\0') {
struct ReportList * CTX_wm_reports(const bContext *C)
struct Main * CTX_data_main(const bContext *C)
void BKE_report(ReportList *reports, ReportType type, const char *message)
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
char * txt_to_buf(struct Text *text, int *r_buf_strlen)
void txt_move_to(struct Text *text, unsigned int line, unsigned int ch, const bool sel)
File and directory operations.
FILE * BLI_fopen(const char *filename, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
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() ATTR_MALLOC
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
void BPY_text_free_code(struct Text *text)
#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_intptr(bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, intptr_t *r_value)
static bool python_script_exec(bContext *C, const char *fn, struct Text *text, struct ReportList *reports, const bool do_jump)
static void bpy_text_filename_get(char *fn, const Main *bmain, size_t fn_len, const Text *text)
bool BPY_run_string_eval(bContext *C, const char *imports[], const char *expr)
bool BPY_run_string_exec(bContext *C, const char *imports[], const char *expr)
bool BPY_run_string_as_number(bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, double *r_value)
static void run_string_handle_error(struct BPy_RunErrInfo *err_info)
bool BPY_run_string_as_string(bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, char **r_value)
bool BPY_run_filepath(bContext *C, const char *filepath, struct ReportList *reports)
bool BPY_run_string_as_string_and_size(bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_size)
bool BPY_run_text(bContext *C, struct Text *text, struct ReportList *reports, const bool do_jump)
static bool bpy_run_string_impl(bContext *C, const char *imports[], const char *expr, const int mode)
static void python_script_error_jump_text(Text *text)
PyObject * bpy_intern_str___main__
void python_script_error_jump(const char *filepath, int *lineno, int *offset)
void(* MEM_freeN)(void *vmemh)
PyObject * PyC_DefaultNameSpace(const char *filename)
PyObject * PyC_ExceptionBuffer(void)
bool PyC_RunString_AsNumber(const char *imports[], const char *expr, const char *filename, double *r_value)
PyObject * PyC_ExceptionBuffer_Simple(void)
void PyC_MainModule_Backup(PyObject **r_main_mod)
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)
PyObject * PyC_UnicodeFromByte(const char *str)
bool PyC_RunString_AsIntPtr(const char *imports[], const char *expr, const char *filename, intptr_t *r_value)
const char * report_prefix
struct ReportList * reports
bool use_single_line_error
PyObject_HEAD PyObject * md_dict