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

Skip to content

Commit ec6eb36

Browse files
committed
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
1 parent e0bdaef commit ec6eb36

5 files changed

Lines changed: 188 additions & 187 deletions

File tree

Include/pymactoolbox.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
/*
1414
** Helper routines for error codes and such.
1515
*/
16-
char *PyMac_StrError(int); /* strerror with mac errors */
16+
char *PyMac_StrError(int); /* strerror with mac errors */
1717
extern PyObject *PyMac_OSErrException; /* Exception for OSErr */
1818
PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */
1919
PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */
20-
PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */
21-
extern OSErr PyMac_GetFullPathname(FSSpec *, char *, int); /* convert fsspec->path */
22-
#ifdef WITH_NEXT_FRAMEWORK
23-
extern char *PyMac_GetAppletScriptFile(void); /* Return applet script file or NULL */
24-
#endif
20+
PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */
21+
extern OSErr PyMac_GetFullPathname(FSSpec *, char *, int); /* convert
22+
fsspec->path */
2523
/*
2624
** These conversion routines are defined in mactoolboxglue.c itself.
2725
*/
@@ -32,21 +30,24 @@ PyObject *PyMac_BuildNumVersion(NumVersion);/* Convert NumVersion to PyObject */
3230

3331
int PyMac_GetStr255(PyObject *, Str255); /* argument parser for Str255 */
3432
PyObject *PyMac_BuildStr255(Str255); /* Convert Str255 to PyObject */
35-
PyObject *PyMac_BuildOptStr255(Str255); /* Convert Str255 to PyObject, NULL to None */
33+
PyObject *PyMac_BuildOptStr255(Str255); /* Convert Str255 to PyObject,
34+
NULL to None */
3635

3736
int PyMac_GetRect(PyObject *, Rect *); /* argument parser for Rect */
38-
PyObject *PyMac_BuildRect(Rect *); /* Convert Rect to PyObject */
37+
PyObject *PyMac_BuildRect(Rect *); /* Convert Rect to PyObject */
3938

4039
int PyMac_GetPoint(PyObject *, Point *); /* argument parser for Point */
41-
PyObject *PyMac_BuildPoint(Point); /* Convert Point to PyObject */
40+
PyObject *PyMac_BuildPoint(Point); /* Convert Point to PyObject */
4241

43-
int PyMac_GetEventRecord(PyObject *, EventRecord *); /* argument parser for EventRecord */
44-
PyObject *PyMac_BuildEventRecord(EventRecord *); /* Convert EventRecord to PyObject */
42+
int PyMac_GetEventRecord(PyObject *, EventRecord *); /* argument parser for
43+
EventRecord */
44+
PyObject *PyMac_BuildEventRecord(EventRecord *); /* Convert EventRecord to
45+
PyObject */
4546

4647
int PyMac_GetFixed(PyObject *, Fixed *); /* argument parser for Fixed */
47-
PyObject *PyMac_BuildFixed(Fixed); /* Convert Fixed to PyObject */
48+
PyObject *PyMac_BuildFixed(Fixed); /* Convert Fixed to PyObject */
4849
int PyMac_Getwide(PyObject *, wide *); /* argument parser for wide */
49-
PyObject *PyMac_Buildwide(wide *); /* Convert wide to PyObject */
50+
PyObject *PyMac_Buildwide(wide *); /* Convert wide to PyObject */
5051

5152
/*
5253
** The rest of the routines are implemented by extension modules. If they are

Mac/Modules/file/_Filemodule.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,49 @@ static PyObject *FSSpec_IsAliasFile(FSSpecObject *_self, PyObject *_args)
12531253
return _res;
12541254
}
12551255

1256+
static OSErr
1257+
_PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
1258+
{
1259+
FSRef fsr;
1260+
OSErr err;
1261+
1262+
*path = '\0';
1263+
err = FSpMakeFSRef(fss, &fsr);
1264+
if (err == fnfErr) {
1265+
/* FSSpecs can point to non-existing files, fsrefs can't. */
1266+
FSSpec fss2;
1267+
int tocopy;
1268+
1269+
err = FSMakeFSSpec(fss->vRefNum, fss->parID, "", &fss2);
1270+
if (err)
1271+
return err;
1272+
err = FSpMakeFSRef(&fss2, &fsr);
1273+
if (err)
1274+
return err;
1275+
err = (OSErr)FSRefMakePath(&fsr, path, len-1);
1276+
if (err)
1277+
return err;
1278+
/* This part is not 100% safe: we append the filename part, but
1279+
** I'm not sure that we don't run afoul of the various 8bit
1280+
** encodings here. Will have to look this up at some point...
1281+
*/
1282+
strcat(path, "/");
1283+
tocopy = fss->name[0];
1284+
if ((strlen(path) + tocopy) >= len)
1285+
tocopy = len - strlen(path) - 1;
1286+
if (tocopy > 0)
1287+
strncat(path, fss->name+1, tocopy);
1288+
}
1289+
else {
1290+
if (err)
1291+
return err;
1292+
err = (OSErr)FSRefMakePath(&fsr, path, len);
1293+
if (err)
1294+
return err;
1295+
}
1296+
return 0;
1297+
}
1298+
12561299
static PyObject *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args)
12571300
{
12581301
PyObject *_res = NULL;
@@ -1262,7 +1305,7 @@ static PyObject *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args)
12621305

12631306
if (!PyArg_ParseTuple(_args, ""))
12641307
return NULL;
1265-
err = PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf));
1308+
err = _PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf));
12661309
if ( err ) {
12671310
PyMac_Error(err);
12681311
return NULL;

Mac/Modules/macosmodule.c

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,64 @@ static char geterr_doc[] = "Convert OSErr number to string";
338338
static PyObject *
339339
MacOS_GetErrorString(PyObject *self, PyObject *args)
340340
{
341-
int errn;
341+
int err;
342+
char buf[256];
343+
Handle h;
344+
char *str;
345+
static int errors_loaded;
342346

343-
if (!PyArg_ParseTuple(args, "i", &errn))
347+
if (!PyArg_ParseTuple(args, "i", &err))
344348
return NULL;
345-
return Py_BuildValue("s", PyMac_StrError(errn));
349+
350+
h = GetResource('Estr', err);
351+
if (!h && !errors_loaded) {
352+
/*
353+
** Attempt to open the resource file containing the
354+
** Estr resources. We ignore all errors. We also try
355+
** this only once.
356+
*/
357+
PyObject *m, *rv;
358+
errors_loaded = 1;
359+
360+
m = PyImport_ImportModule("macresource");
361+
if (!m) {
362+
if (Py_VerboseFlag)
363+
PyErr_Print();
364+
PyErr_Clear();
365+
}
366+
else {
367+
rv = PyObject_CallMethod(m, "open_error_resource", "");
368+
if (!rv) {
369+
if (Py_VerboseFlag)
370+
PyErr_Print();
371+
PyErr_Clear();
372+
}
373+
else {
374+
Py_DECREF(rv);
375+
/* And try again... */
376+
h = GetResource('Estr', err);
377+
}
378+
}
379+
}
380+
/*
381+
** Whether the code above succeeded or not, we won't try
382+
** again.
383+
*/
384+
errors_loaded = 1;
385+
386+
if (h) {
387+
HLock(h);
388+
str = (char *)*h;
389+
memcpy(buf, str+1, (unsigned char)str[0]);
390+
buf[(unsigned char)str[0]] = '\0';
391+
HUnlock(h);
392+
ReleaseResource(h);
393+
}
394+
else {
395+
PyOS_snprintf(buf, sizeof(buf), "Mac OS error code %d", err);
396+
}
397+
398+
return Py_BuildValue("s", buf);
346399
}
347400

348401
static char splash_doc[] = "Open a splash-screen dialog by resource-id (0=close)";

0 commit comments

Comments
 (0)