diff options
author | Raymond Hettinger <python@rcn.com> | 2004-11-05 07:02:59 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-11-05 07:02:59 (GMT) |
commit | ec6eb369d518994e9616e0515056ac0f2cff00a6 (patch) | |
tree | 0870d38d1344a0b69904c009d21f7f411b10cf42 /Mac/Modules | |
parent | e0bdaefaf43abaca4fb30e739768fcfbfd494139 (diff) | |
download | cpython-ec6eb369d518994e9616e0515056ac0f2cff00a6.zip cpython-ec6eb369d518994e9616e0515056ac0f2cff00a6.tar.gz cpython-ec6eb369d518994e9616e0515056ac0f2cff00a6.tar.bz2 |
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
Diffstat (limited to 'Mac/Modules')
-rw-r--r-- | Mac/Modules/file/_Filemodule.c | 45 | ||||
-rw-r--r-- | Mac/Modules/macosmodule.c | 59 |
2 files changed, 100 insertions, 4 deletions
diff --git a/Mac/Modules/file/_Filemodule.c b/Mac/Modules/file/_Filemodule.c index 79929c5..c1b4310 100644 --- a/Mac/Modules/file/_Filemodule.c +++ b/Mac/Modules/file/_Filemodule.c @@ -1253,6 +1253,49 @@ static PyObject *FSSpec_IsAliasFile(FSSpecObject *_self, PyObject *_args) 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 @@ static PyObject *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args) 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; diff --git a/Mac/Modules/macosmodule.c b/Mac/Modules/macosmodule.c index 298aa0c..ed86fd0 100644 --- a/Mac/Modules/macosmodule.c +++ b/Mac/Modules/macosmodule.c @@ -338,11 +338,64 @@ static char geterr_doc[] = "Convert OSErr number to string"; 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)"; |