diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-11-11 16:27:54 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-11-11 16:27:54 +0300 |
commit | 872a7aeb5a833413342a5c0a96be72abe3c9d660 (patch) | |
tree | 9e8489d0faf1c1858ea997b8a2de037d8e878017 /source/blender/python/intern/bpy_interface.c | |
parent | 1bf387ede15fe425a161b8f3f411faedc6f7fc76 (diff) |
Fix #19313: running python scripts with PyRun_File could
crash on windows due to incompatible FILE struct between
Blender and python library, which is why it was not used
in 2.4x, so apply the same workaround now.
Diffstat (limited to 'source/blender/python/intern/bpy_interface.c')
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 27aa2744bfa..47505f478af 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -417,24 +417,32 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc py_result = PyEval_EvalCode( text->compiled, py_dict, py_dict ); } else { -#if 0 - char *pystring; - pystring= malloc(strlen(fn) + 32); - pystring[0]= '\0'; - sprintf(pystring, "exec(open(r'%s').read())", fn); - py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict ); - free(pystring); -#else FILE *fp= fopen(fn, "r"); if(fp) { +#ifdef _WIN32 + /* Previously we used PyRun_File to run directly the code on a FILE + * 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); + + pystring= malloc(strlen(fn) + 32); + pystring[0]= '\0'; + sprintf(pystring, "exec(open(r'%s').read())", fn); + py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict ); + free(pystring); +#else py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict); fclose(fp); +#endif } else { PyErr_Format(PyExc_SystemError, "Python file \"%s\" could not be opened: %s", fn, strerror(errno)); py_result= NULL; } -#endif } if (!py_result) { |