[Python-checkins] python/dist/src/Mac/Modules/file _Filemodule.c, 1.22, 1.23

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Fri Nov 5 08:03:01 CET 2004


Update of /cvsroot/python/python/dist/src/Mac/Modules/file
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8060/Mac/Modules/file

Modified Files:
	_Filemodule.c 
Log Message:
SF patch #1035255: Remove CoreServices / CoreFoundation dependencies in core
(Contributed by Bob Ippolito.)

This patch trims down the Python core on Darwin by making it
independent of CoreFoundation and CoreServices. It does this by:

Changed linker flags in configure/configure.in
Removed the unused PyMac_GetAppletScriptFile
Moved the implementation of PyMac_StrError to the MacOS module
Moved the implementation of PyMac_GetFullPathname to the
Carbon.File module



Index: _Filemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/file/_Filemodule.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- _Filemodule.c	20 Nov 2003 13:30:57 -0000	1.22
+++ _Filemodule.c	5 Nov 2004 07:02:58 -0000	1.23
@@ -1253,6 +1253,49 @@
 	return _res;
 }
 
+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 *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -1262,7 +1305,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