[Python-checkins] python/dist/src/Mac/Modules/file _Filemodule.c, 1.24, 1.25 filesupport.py, 1.21, 1.22
jackjansen@users.sourceforge.net
jackjansen at users.sourceforge.net
Tue Jul 12 23:25:08 CEST 2005
Update of /cvsroot/python/python/dist/src/Mac/Modules/file
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8264
Modified Files:
_Filemodule.c filesupport.py
Log Message:
Fix for #1236090: FSSpec.as_pathname() crashes.
Turns out patch #1035255 was incomplete, it only patched _Filemodule.c
and not filesupport.py. So regenerating caused as_pathname() to go into
an infinite loop.
Index: _Filemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/file/_Filemodule.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- _Filemodule.c 3 Jul 2005 20:59:40 -0000 1.24
+++ _Filemodule.c 12 Jul 2005 21:24:52 -0000 1.25
@@ -92,6 +92,50 @@
return Py_BuildValue("u#", itself->unicode, itself->length);
}
+static OSErr
+_PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
+{
+ FSRef fsr;
+ OSErr err;
+
+ *path = '\0';
+ err = FSpMakeFSRef(fss, &fsr);
+ if (err == fnfErr) {
+ /* FSSpecs can point to non-existing files, fsrefs can't. */
+ FSSpec fss2;
+ int tocopy;
+
+ err = FSMakeFSSpec(fss->vRefNum, fss->parID, "", &fss2);
+ if (err)
+ return err;
+ err = FSpMakeFSRef(&fss2, &fsr);
+ if (err)
+ return err;
+ err = (OSErr)FSRefMakePath(&fsr, path, len-1);
+ if (err)
+ return err;
+ /* This part is not 100% safe: we append the filename part, but
+ ** I'm not sure that we don't run afoul of the various 8bit
+ ** encodings here. Will have to look this up at some point...
+ */
+ strcat(path, "/");
+ tocopy = fss->name[0];
+ if ((strlen(path) + tocopy) >= len)
+ tocopy = len - strlen(path) - 1;
+ if (tocopy > 0)
+ strncat(path, fss->name+1, tocopy);
+ }
+ else {
+ if (err)
+ return err;
+ err = (OSErr)FSRefMakePath(&fsr, path, len);
+ if (err)
+ return err;
+ }
+ return 0;
+}
+
+
static PyObject *File_Error;
/* ------------------- Object type FSCatalogInfo -------------------- */
@@ -1265,7 +1309,7 @@
if (!PyArg_ParseTuple(_args, ""))
return NULL;
- err = PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf));
+ err = _PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf));
if ( err ) {
PyMac_Error(err);
return NULL;
Index: filesupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/file/filesupport.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- filesupport.py 3 Jul 2005 20:59:40 -0000 1.21
+++ filesupport.py 12 Jul 2005 21:25:05 -0000 1.22
@@ -198,6 +198,53 @@
return Py_BuildValue("u#", itself->unicode, itself->length);
}
+
+/*
+** Get pathname for a given FSSpec
+*/
+static OSErr
+_PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
+{
+ FSRef fsr;
+ OSErr err;
+
+ *path = '\0';
+ err = FSpMakeFSRef(fss, &fsr);
+ if (err == fnfErr) {
+ /* FSSpecs can point to non-existing files, fsrefs can't. */
+ FSSpec fss2;
+ int tocopy;
+
+ err = FSMakeFSSpec(fss->vRefNum, fss->parID, "", &fss2);
+ if (err)
+ return err;
+ err = FSpMakeFSRef(&fss2, &fsr);
+ if (err)
+ return err;
+ err = (OSErr)FSRefMakePath(&fsr, path, len-1);
+ if (err)
+ return err;
+ /* This part is not 100% safe: we append the filename part, but
+ ** I'm not sure that we don't run afoul of the various 8bit
+ ** encodings here. Will have to look this up at some point...
+ */
+ strcat(path, "/");
+ tocopy = fss->name[0];
+ if ((strlen(path) + tocopy) >= len)
+ tocopy = len - strlen(path) - 1;
+ if (tocopy > 0)
+ strncat(path, fss->name+1, tocopy);
+ }
+ else {
+ if (err)
+ return err;
+ err = (OSErr)FSRefMakePath(&fsr, path, len);
+ if (err)
+ return err;
+ }
+ return 0;
+}
+
"""
finalstuff = finalstuff + """
@@ -798,7 +845,7 @@
if (!PyArg_ParseTuple(_args, ""))
return NULL;
-err = PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf));
+err = _PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf));
if ( err ) {
PyMac_Error(err);
return NULL;
More information about the Python-checkins
mailing list