@@ -33,6 +33,12 @@ safe_realpath(const char* src, char *buf, size_t buf_sz) {
3333 return true;
3434}
3535
36+ static inline void
37+ set_bundle_exe_dir (const wchar_t * exe_dir ) {
38+ wchar_t buf [PATH_MAX + 1 ] = {0 };
39+ swprintf (buf , PATH_MAX , L"bundle_exe_dir=%ls" , exe_dir );
40+ PySys_AddXOption (buf );
41+ }
3642
3743#ifdef FOR_BUNDLE
3844static int run_embedded (const char * exe_dir_ , int argc , wchar_t * * argv ) {
@@ -48,7 +54,7 @@ static int run_embedded(const char* exe_dir_, int argc, wchar_t **argv) {
4854 int ret = 1 ;
4955 wchar_t * exe_dir = Py_DecodeLocale (exe_dir_ , NULL );
5056 if (exe_dir == NULL ) { fprintf (stderr , "Fatal error: cannot decode exe_dir\n" ); return 1 ; }
51- PyObject * ed = PyUnicode_FromWideChar (exe_dir , -1 );
57+ set_bundle_exe_dir (exe_dir );
5258 wchar_t stdlib [PATH_MAX + 1 ] = {0 };
5359#ifdef __APPLE__
5460 const char * python_relpath = "../Resources/Python/lib" ;
@@ -72,7 +78,6 @@ static int run_embedded(const char* exe_dir_, int argc, wchar_t **argv) {
7278 Py_Initialize ();
7379 PySys_SetArgvEx (argc - 1 , argv + 1 , 0 );
7480 PySys_SetObject ("frozen" , Py_True );
75- if (ed ) { PySys_SetObject ("bundle_exe_dir" , ed ); Py_CLEAR (ed ); }
7681 PyObject * kitty = PyUnicode_FromWideChar (stdlib , -1 );
7782 if (kitty == NULL ) { fprintf (stderr , "Failed to allocate python kitty lib object\n" ); goto end ; }
7883 PyObject * runpy = PyImport_ImportModule ("runpy" );
@@ -89,8 +94,13 @@ static int run_embedded(const char* exe_dir_, int argc, wchar_t **argv) {
8994}
9095
9196#else
92- static int run_embedded (const char * exe_dir , int argc , wchar_t * * argv ) {
93- (void )exe_dir ;
97+ static int run_embedded (const char * exe_dir_ , int argc , wchar_t * * argv ) {
98+ (void )exe_dir_ ;
99+ #ifdef __APPLE__
100+ wchar_t * exe_dir = Py_DecodeLocale (exe_dir_ , NULL );
101+ if (exe_dir == NULL ) { fprintf (stderr , "Fatal error: cannot decode exe_dir\n" ); return 1 ; }
102+ set_bundle_exe_dir (exe_dir );
103+ #endif
94104 return Py_Main (argc , argv );
95105}
96106
0 commit comments