[Python-checkins] python/dist/src/Mac/Modules macosmodule.c, 1.71, 1.72

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
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8060/Mac/Modules

Modified Files:
	macosmodule.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: macosmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/macosmodule.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- macosmodule.c	2 Jun 2004 13:44:05 -0000	1.71
+++ macosmodule.c	5 Nov 2004 07:02:58 -0000	1.72
@@ -338,11 +338,64 @@
 static PyObject *
 MacOS_GetErrorString(PyObject *self, PyObject *args)
 {
-	int errn;
+	int err;
+	char buf[256];
+	Handle h;
+	char *str;
+	static int errors_loaded;
 	
-	if (!PyArg_ParseTuple(args, "i", &errn))
+	if (!PyArg_ParseTuple(args, "i", &err))
 		return NULL;
-	return Py_BuildValue("s", PyMac_StrError(errn));
+
+	h = GetResource('Estr', err);
+	if (!h && !errors_loaded) {
+		/*
+		** Attempt to open the resource file containing the
+		** Estr resources. We ignore all errors. We also try
+		** this only once.
+		*/
+		PyObject *m, *rv;
+		errors_loaded = 1;
+		
+		m = PyImport_ImportModule("macresource");
+		if (!m) {
+			if (Py_VerboseFlag)
+				PyErr_Print();
+			PyErr_Clear();
+		}
+		else {
+			rv = PyObject_CallMethod(m, "open_error_resource", "");
+			if (!rv) {
+				if (Py_VerboseFlag)
+					PyErr_Print();
+				PyErr_Clear();
+			}
+			else {
+				Py_DECREF(rv);
+				/* And try again... */
+				h = GetResource('Estr', err);
+			}
+		}
+	}
+	/*
+	** Whether the code above succeeded or not, we won't try
+	** again.
+	*/
+	errors_loaded = 1;
+		
+	if (h) {
+		HLock(h);
+		str = (char *)*h;
+		memcpy(buf, str+1, (unsigned char)str[0]);
+		buf[(unsigned char)str[0]] = '\0';
+		HUnlock(h);
+		ReleaseResource(h);
+	}
+	else {
+		PyOS_snprintf(buf, sizeof(buf), "Mac OS error code %d", err);
+	}
+
+	return Py_BuildValue("s", buf);
 }
 
 static char splash_doc[] = "Open a splash-screen dialog by resource-id (0=close)";



More information about the Python-checkins mailing list