[Bf-blender-cvs] [24e3a930f14] master: Fix T51444: Unit tests don't run on Windows

Campbell Barton noreply at git.blender.org
Thu May 25 10:53:07 CEST 2017


Commit: 24e3a930f14a7bfc1ea16350b4e2c9585aa0f7c3
Author: Campbell Barton
Date:   Thu May 25 18:56:00 2017 +1000
Branches: master
https://developer.blender.org/rB24e3a930f14a7bfc1ea16350b4e2c9585aa0f7c3

Fix T51444: Unit tests don't run on Windows

===================================================================

M	source/blender/python/intern/bpy_interface.c

===================================================================

diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 55e477b0214..7b0daa91523 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -480,11 +480,20 @@ static bool python_script_exec(
 			 * 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 */
+			 * So now we load the script file data to a buffer.
+			 *
+			 * Note on use of 'globals()', it's important not copy the dictionary because
+			 * tools may inspect 'sys.modules["__main__"]' for variables defined in the code
+			 * where using a copy of 'globals()' causes code execution
+			 * to leave the main namespace untouched. see: T51444
+			 *
+			 * This leaves us with the problem of variables being included,
+			 * currently this is worked around using 'dict.__del__' it's ugly but works.
+			 */
 			{
 				const char *pystring =
-				        "ns = globals().copy()\n"
-				        "with open(__file__, 'rb') as f: exec(compile(f.read(), __file__, 'exec'), ns)";
+				        "with open(__file__, 'rb') as f:"
+				        "exec(compile(f.read(), __file__, 'exec'), globals().__delitem__('f') or globals())";
 
 				fclose(fp);




More information about the Bf-blender-cvs mailing list