@@ -193,22 +193,7 @@ void FUnrealEnginePythonModule::RunFileSandboxed(char *filename) {
193193 {
194194 full_path = TCHAR_TO_UTF8 (*FPaths::Combine (*FPaths::GameContentDir (), UTF8_TO_TCHAR (" Scripts" ), *FString (" /" ), UTF8_TO_TCHAR (filename)));
195195 }
196- #if PY_MAJOR_VERSION >= 3
197- FILE *fd = nullptr ;
198-
199- #if PLATFORM_WINDOWS
200- if (fopen_s (&fd, full_path, " r" ) != 0 ) {
201- UE_LOG (LogPython, Error, TEXT (" Unable to open file %s" ), UTF8_TO_TCHAR (full_path));
202- return ;
203- }
204- #else
205- fd = fopen (full_path, " r" );
206- if (!fd) {
207- UE_LOG (LogPython, Error, TEXT (" Unable to open file %s" ), UTF8_TO_TCHAR (full_path));
208- return ;
209- }
210- #endif
211-
196+
212197 PyThreadState *_main = PyThreadState_Get ();
213198
214199 PyThreadState *py_new_state = Py_NewInterpreter ();
@@ -229,7 +214,22 @@ void FUnrealEnginePythonModule::RunFileSandboxed(char *filename) {
229214 return ;
230215 }
231216 PyObject *global_dict = PyModule_GetDict (m);
217+
218+ #if PY_MAJOR_VERSION >= 3
219+ FILE *fd = nullptr ;
232220
221+ #if PLATFORM_WINDOWS
222+ if (fopen_s (&fd, full_path, " r" ) != 0 ) {
223+ UE_LOG (LogPython, Error, TEXT (" Unable to open file %s" ), UTF8_TO_TCHAR (full_path));
224+ return ;
225+ }
226+ #else
227+ fd = fopen (full_path, " r" );
228+ if (!fd) {
229+ UE_LOG (LogPython, Error, TEXT (" Unable to open file %s" ), UTF8_TO_TCHAR (full_path));
230+ return ;
231+ }
232+ #endif
233233 PyObject *eval_ret = PyRun_File (fd, full_path, Py_file_input, global_dict, global_dict);
234234 fclose (fd);
235235 if (!eval_ret) {
0 commit comments