Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-11-11 16:27:54 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-11-11 16:27:54 +0300
commit872a7aeb5a833413342a5c0a96be72abe3c9d660 (patch)
tree9e8489d0faf1c1858ea997b8a2de037d8e878017 /source/blender/python/intern/bpy_interface.c
parent1bf387ede15fe425a161b8f3f411faedc6f7fc76 (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.c26
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) {