Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 660bb1d

Browse files
committed
MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
1 parent 574c0e2 commit 660bb1d

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

Mac/Python/macmain.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,22 @@ init_common(int *argcp, char ***argvp, int embedded)
256256
} else {
257257
/* Create argc/argv. Do it before we go into the options event loop. */
258258
*argcp = PyMac_GetArgv(argvp, options.noargs);
259-
259+
#ifdef USE_ARGV0_CHDIR
260+
printf("argc=%d, argv[0]=%x=%s\n", *argcp, (*argvp)[0], (*argvp)[0]);
261+
if (*argcp >= 1 && (*argvp)[0] && (*argvp)[0][0]) {
262+
/* Workaround for MacOS X, which currently (DP4) doesn't set
263+
** the working folder correctly
264+
*/
265+
char app_wd[256], *p;
266+
267+
strncpy(app_wd, (*argvp)[0], 256);
268+
printf("Modifying dir, argv[0]=%s\n", (*argvp)[0]);
269+
p = strrchr(app_wd, ':');
270+
if ( p ) *p = 0;
271+
printf("app_wd=%s\n", app_wd);
272+
chdir(app_wd);
273+
}
274+
#endif
260275
/* Do interactive option setting, if allowed and <option> depressed */
261276
PyMac_InteractiveOptions(&options, argcp, argvp);
262277
}

Mac/mwerks/mwerks_carbon_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define TARGET_API_MAC_CARBON 1
1010
#define TARGET_API_MAC_CARBON_NOTYET 1 /* Things we should do eventually, but not now */
1111

12+
#define USE_ARGV0_CHDIR /* Workaround for OSXDP4: change dir to argv[0] dir */
1213
/* #define USE_GUSI2 /* Stdio implemented with GUSI 2 */
1314
/* # define USE_GUSI1 /* Stdio implemented with GUSI 1 */
1415
#define USE_MSL /* Use Mw Standard Library (as opposed to Plaugher C libraries) */

0 commit comments

Comments
 (0)