Revision: 24494
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24494
Author: blendix
Date: 2009-11-11 14:27:54 +0100 (Wed, 11 Nov 2009)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/source/blender/python/intern/bpy_interface.c
Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c 2009-11-11
13:20:19 UTC (rev 24493)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c 2009-11-11
13:27:54 UTC (rev 24494)
@@ -417,24 +417,32 @@
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) {
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs