32 #include "../generic/py_capi_utils.h"
40 int lineno, lineno_end;
46 txt_move_to(text, lineno_end - 1, offset_end - 1,
false);
55 const size_t filepath_maxlen,
68 #define PYMODULE_CLEAR_WORKAROUND
70 #ifdef PYMODULE_CLEAR_WORKAROUND
95 PyObject *main_mod =
NULL;
96 PyObject *py_dict =
NULL, *py_result =
NULL;
97 PyGILState_STATE gilstate;
101 const char *filepath_namespace =
NULL;
105 if (filepath ==
NULL && text ==
NULL) {
115 filepath_namespace = filepath_dummy;
119 PyObject *filepath_dummy_py;
123 size_t buf_len_dummy;
125 text->
compiled = Py_CompileStringObject(buf, filepath_dummy_py, Py_file_input,
NULL, -1);
128 Py_DECREF(filepath_dummy_py);
130 if (PyErr_Occurred()) {
137 py_result = PyEval_EvalCode(text->
compiled, py_dict, py_dict);
142 filepath_namespace = filepath;
163 const char *pystring =
164 "with open(__file__, 'rb') as f:"
165 "exec(compile(f.read(), __file__, 'exec'), globals().__delitem__('f') or globals())";
169 py_result = PyRun_String(pystring, Py_file_input, py_dict, py_dict);
172 py_result = PyRun_File(fp, filepath, Py_file_input, py_dict, py_dict);
178 PyExc_IOError,
"Python file \"%s\" could not be opened: %s", filepath, strerror(errno));
197 Py_DECREF(py_result);
201 #ifdef PYMODULE_CLEAR_WORKAROUND
204 PyObject *dict_back = mmod->
md_dict;
208 Py_DECREF(dict_back);
211 #undef PYMODULE_CLEAR_WORKAROUND
218 return (py_result !=
NULL);
242 const char *imports[],
247 PyGILState_STATE gilstate;
248 PyObject *main_mod =
NULL;
249 PyObject *py_dict, *retval;
252 if (expr[0] ==
'\0') {
267 retval = PyRun_String(expr, mode, py_dict, py_dict);
270 if (retval ==
NULL) {
323 if (err_info ==
NULL) {
337 const char *err_str = py_err_str ? PyUnicode_AsUTF8(py_err_str) :
"Unable to extract exception";
354 fprintf(stderr,
"%s\n", err_str);
361 Py_XDECREF(py_err_str);
365 const char *imports[],
370 PyGILState_STATE gilstate;
373 if (expr[0] ==
'\0') {
392 const char *imports[],
396 size_t *r_value_size)
398 PyGILState_STATE gilstate;
401 if (expr[0] ==
'\0') {
420 const char *imports[],
425 size_t value_dummy_size;
430 const char *imports[],
435 PyGILState_STATE gilstate;
438 if (expr[0] ==
'\0') {
struct ReportList * CTX_wm_reports(const bContext *C)
struct 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_reports_clear(ReportList *reports)
void BKE_report(ReportList *reports, eReportType type, const char *message)
void BKE_reports_init(ReportList *reports, int flag)
void BKE_reports_print(ReportList *reports, eReportType level)
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()
void void void BLI_movelisttolist(struct ListBase *dst, struct ListBase *src) ATTR_NONNULL(1
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 void bpy_text_filepath_get(char *filepath, const size_t filepath_maxlen, const Main *bmain, const Text *text)
static bool python_script_exec(bContext *C, const char *filepath, struct Text *text, struct ReportList *reports, const bool do_jump)
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_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)
PyObject * bpy_intern_str___main__
bool python_script_error_jump(const char *filepath, int *r_lineno, int *r_offset, int *r_lineno_end, int *r_offset_end)
ccl_gpu_kernel_postfix ccl_global float int int int int float bool 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