Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/intern/bpy_interface.c
| Context not available. | |||||
| PyObject *main_mod = NULL; | PyObject *main_mod = NULL; | ||||
| PyObject *py_dict = NULL, *py_result = NULL; | PyObject *py_dict = NULL, *py_result = NULL; | ||||
| PyGILState_STATE gilstate; | PyGILState_STATE gilstate; | ||||
| char fn_fsdefault[FILE_MAXDIR]; /* in the file system default encoding */ | |||||
| BLI_assert(fn || text); | BLI_assert(fn || text); | ||||
| Context not available. | |||||
| char fn_dummy[FILE_MAXDIR]; | char fn_dummy[FILE_MAXDIR]; | ||||
| bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text); | bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text); | ||||
| if (text->compiled == NULL) { /* if it wasn't already compiled, do it now */ | /* convert fn_dummy to the file system default encoding */ | ||||
| if (!PyC_EncodeFSDefault(fn_dummy, fn_fsdefault, sizeof(fn_fsdefault))) | |||||
| PyErr_SetString(PyExc_SystemError, "internal error: file name encoding conversion failed"); | |||||
| if (!PyErr_Occurred() && text->compiled == NULL) { /* if it wasn't already compiled, do it now */ | |||||
| char *buf = txt_to_buf(text); | char *buf = txt_to_buf(text); | ||||
| text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input); | text->compiled = Py_CompileString(buf, fn_fsdefault, Py_file_input); | ||||
| MEM_freeN(buf); | MEM_freeN(buf); | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| if (text->compiled) { | if (!PyErr_Occurred() && text->compiled) { | ||||
| py_dict = PyC_DefaultNameSpace(fn_dummy); | py_dict = PyC_DefaultNameSpace(fn_fsdefault); | ||||
| py_result = PyEval_EvalCode(text->compiled, py_dict, py_dict); | py_result = PyEval_EvalCode(text->compiled, py_dict, py_dict); | ||||
| } | } | ||||
| Context not available. | |||||
| FILE *fp = BLI_fopen(fn, "r"); | FILE *fp = BLI_fopen(fn, "r"); | ||||
| if (fp) { | if (fp) { | ||||
| py_dict = PyC_DefaultNameSpace(fn); | /* convert fn to the file system default encoding */ | ||||
| if (!PyC_EncodeFSDefault(fn, fn_fsdefault, sizeof(fn_fsdefault))) | |||||
| PyErr_SetString(PyExc_SystemError, "internal error: file name encoding conversion failed"); | |||||
| #ifdef _WIN32 | if (!PyErr_Occurred()) { | ||||
| /* Previously we used PyRun_File to run directly the code on a FILE | py_dict = PyC_DefaultNameSpace(fn_fsdefault); | ||||
| * object, but as written in the Python/C API Ref Manual, chapter 2, | |||||
| * 'FILE structs for different C libraries can be different and | |||||
| * incompatible'. | |||||
| * So now we load the script file data to a buffer */ | |||||
| { | |||||
| char *pystring; | |||||
| fclose(fp); | #ifdef _WIN32 | ||||
| /* Previously we used PyRun_File to run directly the code on a FILE | |||||
| pystring = MEM_mallocN(strlen(fn) + 37, "pystring"); | * object, but as written in the Python/C API Ref Manual, chapter 2, | ||||
| pystring[0] = '\0'; | * 'FILE structs for different C libraries can be different and | ||||
| sprintf(pystring, "f=open(r'%s');exec(f.read());f.close()", fn); | * incompatible'. | ||||
| py_result = PyRun_String(pystring, Py_file_input, py_dict, py_dict); | * So now we load the script file data to a buffer */ | ||||
| MEM_freeN(pystring); | { | ||||
| } | char *pystring; | ||||
| fclose(fp); | |||||
| pystring = MEM_mallocN(strlen(fn) + 37, "pystring"); | |||||
| pystring[0] = '\0'; | |||||
| sprintf(pystring, "f=open(r'%s');exec(f.read());f.close()", fn); | |||||
| py_result = PyRun_String(pystring, Py_file_input, py_dict, py_dict); | |||||
| MEM_freeN(pystring); | |||||
| } | |||||
| #else | #else | ||||
| py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict); | py_result = PyRun_File(fp, fn_fsdefault, Py_file_input, py_dict, py_dict); | ||||
| fclose(fp); | fclose(fp); | ||||
| #endif | #endif | ||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| PyErr_Format(PyExc_IOError, | PyErr_Format(PyExc_IOError, | ||||
| Context not available. | |||||