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

Skip to content

Commit a0f0a33

Browse files
committed
Mac-specific mod to enable aliases on import paths.
(Jack Jansen and/or Just van Rossum)
1 parent ce11393 commit a0f0a33

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

Python/import.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,27 +1055,44 @@ check_case(char *buf, int len, int namelen, char *name)
10551055

10561056
#ifdef macintosh
10571057
#include <TextUtils.h>
1058+
#ifdef USE_GUSI
1059+
#include "TFileSpec.h" /* for Path2FSSpec() */
1060+
#endif
10581061
static int
10591062
check_case(char *buf, int len, int namelen, char *name)
10601063
{
10611064
FSSpec fss;
10621065
OSErr err;
1063-
unsigned char mybuf[MAXPATHLEN+1];
1064-
1065-
strcpy((char *)mybuf, buf);
1066-
c2pstr((char *)mybuf);
1067-
err = FSMakeFSSpec(0, 0, mybuf, &fss);
1066+
#ifndef USE_GUSI
1067+
err = FSMakeFSSpec(0, 0, Pstring(buf), &fss);
1068+
#else
1069+
/* GUSI's Path2FSSpec() resolves all possible aliases nicely on
1070+
the way, which is fine for all directories, but here we need
1071+
the original name of the alias file (say, Dlg.ppc.slb, not
1072+
toolboxmodules.ppc.slb). */
1073+
char *colon;
1074+
err = Path2FSSpec(buf, &fss);
1075+
if (err == noErr) {
1076+
colon = strrchr(buf, ':'); /* find filename */
1077+
if (colon != NULL)
1078+
err = FSMakeFSSpec(fss.vRefNum, fss.parID,
1079+
Pstring(colon+1), &fss);
1080+
else
1081+
err = FSMakeFSSpec(fss.vRefNum, fss.parID,
1082+
fss.name, &fss);
1083+
}
1084+
#endif
10681085
if (err) {
10691086
PyErr_Format(PyExc_NameError,
1070-
"Can't find file for module %.100s\n(filename %.300s)",
1071-
name, buf);
1087+
"Can't find file for module %.100s\n(filename %.300s)",
1088+
name, buf);
10721089
return 0;
10731090
}
10741091
p2cstr(fss.name);
10751092
if ( strncmp(name, (char *)fss.name, namelen) != 0 ) {
10761093
PyErr_Format(PyExc_NameError,
1077-
"Case mismatch for module name %.100s\n(filename %.300s)",
1078-
name, fss.name);
1094+
"Case mismatch for module name %.100s\n(filename %.300s)",
1095+
name, fss.name);
10791096
return 0;
10801097
}
10811098
return 1;

Python/importdl.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ typedef void (*dl_funcptr)();
249249
#define CFragConnectionID ConnectionID
250250
#define kLoadCFrag 0x01
251251
#endif
252+
#ifdef USE_GUSI
253+
#include "TFileSpec.h" /* for Path2FSSpec() */
254+
#endif
252255
#include <Files.h>
253256
#include "macdefs.h"
254257
#include "macglue.h"
@@ -372,15 +375,21 @@ _PyImport_LoadDynamicModule(name, pathname, fp)
372375
Ptr mainAddr;
373376
Str255 errMessage;
374377
OSErr err;
378+
#ifndef USE_GUSI
375379
Boolean isfolder, didsomething;
380+
#endif
376381
char buf[512];
377382
Str63 fragname;
378383
Ptr symAddr;
379384
CFragSymbolClass class;
380385

381386
/* First resolve any aliases to find the real file */
387+
#ifdef USE_GUSI
388+
err = Path2FSSpec(pathname, &libspec);
389+
#else
382390
(void)FSMakeFSSpec(0, 0, Pstring(pathname), &libspec);
383391
err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething);
392+
#endif
384393
if ( err ) {
385394
sprintf(buf, "%.255s: %.200s",
386395
pathname, PyMac_StrError(err));

0 commit comments

Comments
 (0)