Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/generic/bpy_internal_import.c
| Context not available. | |||||
| #include "BKE_text.h" /* txt_to_buf */ | #include "BKE_text.h" /* txt_to_buf */ | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "py_capi_utils.h" | |||||
| static Main *bpy_import_main = NULL; | static Main *bpy_import_main = NULL; | ||||
| static ListBase bpy_import_main_list; | static ListBase bpy_import_main_list; | ||||
| Context not available. | |||||
| BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name + 2); | BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name + 2); | ||||
| } | } | ||||
| PyObject *bpy_text_compile(Text *text) | |||||
| { | |||||
| char fn_dummy[FILE_MAXDIR]; | |||||
| char fn_fsdefault[FILE_MAXDIR]; /* in the file system default encoding */ | |||||
| char *buf; | |||||
| /* get a dummy filename for the textblock */ | |||||
| bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text); | |||||
| /* convert fn_dummy to the file system default encoding if necessary */ | |||||
| if (!PyC_EncodeFSDefault(fn_dummy, fn_fsdefault, sizeof(fn_fsdefault))) { | |||||
| PyErr_SetString(PyExc_SystemError, "internal error: file name encoding conversion failed"); | |||||
| return NULL; | |||||
| } | |||||
| /* if previously compiled, free the object */ | |||||
| free_compiled_text(text); | |||||
| /* compile the buffer */ | |||||
| buf = txt_to_buf(text); | |||||
| text->compiled = Py_CompileString(buf, fn_fsdefault, Py_file_input); | |||||
| MEM_freeN(buf); | |||||
| if (PyErr_Occurred()) { | |||||
| PyErr_Print(); | |||||
| PyErr_Clear(); | |||||
| PySys_SetObject("last_traceback", NULL); | |||||
| free_compiled_text(text); | |||||
| return NULL; | |||||
| } | |||||
| return text->compiled; | |||||
| } | |||||
| PyObject *bpy_text_import(Text *text) | PyObject *bpy_text_import(Text *text) | ||||
| { | { | ||||
| char *buf = NULL; | |||||
| char modulename[MAX_ID_NAME + 2]; | char modulename[MAX_ID_NAME + 2]; | ||||
| int len; | int len; | ||||
| if (!text->compiled) { | if (!text->compiled) { | ||||
| char fn_dummy[256]; | if (!bpy_text_compile(text)) | ||||
| bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text); | |||||
| buf = txt_to_buf(text); | |||||
| text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input); | |||||
| MEM_freeN(buf); | |||||
| if (PyErr_Occurred()) { | |||||
| PyErr_Print(); | |||||
| PyErr_Clear(); | |||||
| PySys_SetObject("last_traceback", NULL); | |||||
| free_compiled_text(text); | |||||
| return NULL; | return NULL; | ||||
| } | |||||
| } | } | ||||
| len = strlen(text->id.name + 2); | len = strlen(text->id.name + 2); | ||||
| Context not available. | |||||
| else | else | ||||
| *found = 1; | *found = 1; | ||||
| /* if previously compiled, free the object */ | |||||
| /* (can't see how could be NULL, but check just in case) */ | |||||
| if (text->compiled) { | |||||
| Py_DECREF((PyObject *)text->compiled); | |||||
| } | |||||
| /* compile the buffer */ | /* compile the buffer */ | ||||
| buf = txt_to_buf(text); | if (!bpy_text_compile(text)) | ||||
| text->compiled = Py_CompileString(buf, text->id.name + 2, Py_file_input); | |||||
| MEM_freeN(buf); | |||||
| /* if compile failed.... return this error */ | |||||
| if (PyErr_Occurred()) { | |||||
| PyErr_Print(); | |||||
| PyErr_Clear(); | |||||
| PySys_SetObject("last_traceback", NULL); | |||||
| free_compiled_text(text); | |||||
| return NULL; | return NULL; | ||||
| } | |||||
| /* make into a module */ | /* make into a module */ | ||||
| return PyImport_ExecCodeModule((char *)name, text->compiled); | return PyImport_ExecCodeModule((char *)name, text->compiled); | ||||
| Context not available. | |||||