Fix T51444: Unit tests don't run on Windows

This commit is contained in:
Campbell Barton 2017-05-25 18:56:00 +10:00
parent bbce6ce249
commit 24e3a930f1

@ -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);