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

Skip to content

Commit 378815c

Browse files
committed
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
after each chdir call.
1 parent 7275561 commit 378815c

4 files changed

Lines changed: 48 additions & 15 deletions

File tree

Mac/Include/macglue.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3939
#pragma lib_export on
4040
#endif
4141

42+
#ifdef USE_GUSI
43+
void PyMac_FixGUSIcd Py_PROTO((void)); /* Workaround for GUSI chdir() call */
44+
#endif
45+
4246
char *PyMac_StrError(int); /* strerror with mac errors */
4347

4448
extern int PyMac_DoYieldEnabled; /* Don't do eventloop when false */

Mac/Modules/macmodule.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,17 @@ mac_chdir(self, args)
176176
object *self;
177177
object *args;
178178
{
179+
#ifdef USE_GUSI
180+
object *rv;
181+
182+
/* Change MacOS's idea of wd too */
183+
rv = mac_1str(args, chdir);
184+
PyMac_FixGUSIcd();
185+
return rv;
186+
#else
179187
return mac_1str(args, chdir);
188+
#endif
189+
180190
}
181191

182192
static object *

Mac/Python/macglue.c

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5151
#endif
5252
#ifdef USE_GUSI
5353
#include <TFileSpec.h> /* For Path2FSSpec */
54+
#include <LowMem.h> /* For SetSFCurDir, etc */
5455
#endif
5556

5657
#ifndef HAVE_UNIVERSAL_HEADERS
@@ -118,6 +119,34 @@ struct hook_args {
118119
static DlgHookYDUPP myhook_upp;
119120
static int upp_inited = 0;
120121

122+
#ifdef USE_GUSI
123+
/*
124+
** GUSI (1.6.0 and earlier, at the least) do not set the MacOS idea of
125+
** the working directory. Hence, we call this routine after each call
126+
** to chdir() to rectify things.
127+
*/
128+
void
129+
PyMac_FixGUSIcd()
130+
{
131+
WDPBRec pb;
132+
FSSpec curdirfss;
133+
134+
if ( Path2FSSpec(":x", &curdirfss) != noErr )
135+
return;
136+
137+
/* Set MacOS "working directory" */
138+
pb.ioNamePtr= "\p";
139+
pb.ioVRefNum= curdirfss.vRefNum;
140+
pb.ioWDDirID= curdirfss.parID;
141+
if (PBHSetVol(&pb, 0) != noErr)
142+
return;
143+
144+
/* Set standard-file working directory */
145+
LMSetSFSaveDisk(-curdirfss.vRefNum);
146+
LMSetCurDirStore(curdirfss.parID);
147+
}
148+
#endif
149+
121150

122151
/* Convert C to Pascal string. Returns pointer to static buffer. */
123152
unsigned char *
@@ -657,21 +686,8 @@ PyMac_GetFSSpec(PyObject *v, FSSpec *fs)
657686
/* It's a pathname */
658687
if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) )
659688
return 0;
660-
#ifdef USE_GUSI
661-
{
662-
FSSpec curdirfss;
663-
664-
if ( Path2FSSpec(":x", &curdirfss) == 0 ) {
665-
refnum = curdirfss.vRefNum;
666-
parid = curdirfss.parID;
667-
} else {
668-
return 0;
669-
}
670-
}
671-
#else
672-
refnum = 0; /* XXXX Should get CurWD here... */
689+
refnum = 0; /* XXXX Should get CurWD here?? */
673690
parid = 0;
674-
#endif
675691
} else {
676692
if( !PyArg_Parse(v, "(hlO&); FSSpec should be fullpath or (vrefnum,dirid,path)",
677693
&refnum, &parid, PyMac_GetStr255, &path)) {
@@ -687,7 +703,6 @@ PyMac_GetFSSpec(PyObject *v, FSSpec *fs)
687703
}
688704

689705

690-
691706
/* Convert a Python object to a Rect.
692707
The object must be a (left, top, right, bottom) tuple.
693708
(This differs from the order in the struct but is consistent with

Mac/Python/macmain.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ PyMac_InitApplication()
192192
*endp = '\0';
193193

194194
chdir(curwd);
195+
#ifdef USE_GUSI
196+
/* Change MacOS's idea of wd too */
197+
PyMac_FixGUSIcd();
198+
#endif
195199
}
196200
}
197201
Py_Main(argc, argv);

0 commit comments

Comments
 (0)