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

Skip to content

Commit ac82b6a

Browse files
committed
If the preference filename resource is empty don't try to open or
create the preferences file. This is so that frozen programs don't interfere with an existing Python installation, or leave turds in the Preferences folder.
1 parent 1e2260f commit ac82b6a

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

Mac/Python/macgetpath.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ PERFORMANCE OF THIS SOFTWARE.
6565
:Lib:test\n\
6666
:Lib:mac"
6767

68-
static void
68+
static int
6969
getpreffilefss(FSSpec *fssp)
7070
{
7171
static int diditbefore=0;
72+
static int rv = 1;
7273
static FSSpec fss;
7374
short prefdirRefNum;
7475
long prefdirDirID;
@@ -88,12 +89,19 @@ getpreffilefss(FSSpec *fssp)
8889
}
8990

9091
HLock(namehandle);
91-
(void)FSMakeFSSpec(prefdirRefNum, prefdirDirID, (unsigned char *)*namehandle, &fss);
92+
if ( **namehandle == '\0' ) {
93+
/* Empty string means don't use preferences file */
94+
rv = 0;
95+
} else {
96+
/* There is a filename, construct the fsspec */
97+
(void)FSMakeFSSpec(prefdirRefNum, prefdirDirID, (unsigned char *)*namehandle, &fss);
98+
}
9299
HUnlock(namehandle);
93100
ReleaseResource(namehandle);
94101
diditbefore = 1;
95102
}
96103
*fssp = fss;
104+
return rv;
97105
}
98106

99107
char *
@@ -162,7 +170,8 @@ PyMac_OpenPrefFile()
162170
short prefrh;
163171
OSErr err;
164172

165-
getpreffilefss(&dirspec);
173+
if ( !getpreffilefss(&dirspec))
174+
return -1;
166175
prefrh = FSpOpenResFile(&dirspec, fsRdWrShPerm);
167176
if ( prefrh < 0 ) {
168177
#if 0
@@ -225,7 +234,7 @@ PyMac_GetPythonDir()
225234
prefrh = PyMac_OpenPrefFile();
226235
handle = (AliasHandle)Get1Resource('alis', PYTHONHOME_ID);
227236
if ( handle == NULL ) {
228-
(void)StopAlert(BADPREFFILE_ID, NULL);
237+
/* (void)StopAlert(BADPREFFILE_ID, NULL); */
229238
diditbefore=1;
230239
return ":";
231240
}

0 commit comments

Comments
 (0)