MCPcopy Create free account
hub / github.com/blender/blender / bpy_run_string_impl

Function bpy_run_string_impl

source/blender/python/intern/bpy_interface_run.cc:257–304  ·  view source on GitHub ↗

* \param mode: Passed to #PyRun_String, matches Python's `compile` functions mode argument. * #Py_eval_input for `eval`, #Py_file_input for `exec`. */

Source from the content-addressed store, hash-verified

255 * #Py_eval_input for `eval`, #Py_file_input for `exec`.
256 */
257static bool bpy_run_string_impl(bContext *C,
258 const char *imports[],
259 const char *expr,
260 const int mode)
261{
262 BLI_assert(expr);
263 PyGILState_STATE gilstate;
264 PyObject *py_dict, *retval;
265 bool ok = true;
266
267 if (expr[0] == '\0') {
268 return ok;
269 }
270
271 bpy_context_set(C, &gilstate);
272
273 PyObject *main_mod = PyC_MainModule_Backup();
274
275 py_dict = PyC_DefaultNameSpace("<blender string>");
276
277 if (imports && !PyC_NameSpace_ImportArray(py_dict, imports)) {
278 Py_DECREF(py_dict);
279 retval = nullptr;
280 }
281 else {
282 retval = PyRun_String(expr, mode, py_dict, py_dict);
283 }
284
285 if (retval == nullptr) {
286 ok = false;
287 if (ReportList *wm_reports = C ? CTX_wm_reports(C) : nullptr) {
288 BPy_errors_to_report(wm_reports);
289 }
290 else {
291 PyC_Err_CaptureSystemExitCode();
292 }
293 PyErr_Print();
294 }
295 else {
296 Py_DECREF(retval);
297 }
298
299 PyC_MainModule_Restore(main_mod);
300
301 bpy_context_clear(C, &gilstate);
302
303 return ok;
304}
305
306bool BPY_run_string_eval(bContext *C, const char *imports[], const char *expr)
307{

Callers 2

BPY_run_string_evalFunction · 0.85
BPY_run_string_execFunction · 0.85

Calls 9

bpy_context_setFunction · 0.85
PyC_MainModule_BackupFunction · 0.85
PyC_DefaultNameSpaceFunction · 0.85
CTX_wm_reportsFunction · 0.85
BPy_errors_to_reportFunction · 0.85
PyC_MainModule_RestoreFunction · 0.85
bpy_context_clearFunction · 0.85

Tested by

no test coverage detected