From 383a00c5ce6b5fc05b9a00661b088efcef1afcb9 Mon Sep 17 00:00:00 2001 From: Brian Mastenbrook Date: Mon, 20 Dec 2004 13:10:38 +0000 Subject: [PATCH] 0.8.17.31: "dlerror and a tale of woe" Fix two bugs relating to dlerror() in the OS X dl* shim: * dlerror() should return NULL when there is no error * dlerror() should return an error when dlsym() returns NULL Also, fix a call to cerror with only one argument. Restores support for OS X 10.2 "Jaguar": * Use a header file with constants for the dl* shim instead of the OS dlfcn.h, which doesn't exist under 10.2 and does under 10.3 * Include a fake nl_langinfo which returns a codeset of UTF-8 unless neither LC_CALL or LANG are set to C. OS X uses UTF-8 everywhere, so this is arguably the right behavior. --- src/code/foreign-load.lisp | 2 +- src/runtime/Config.ppc-darwin | 2 +- src/runtime/ppc-darwin-dlshim.c | 21 ++++++++++++----- src/runtime/ppc-darwin-dlshim.h | 24 ++++++++++++++++++++ src/runtime/ppc-darwin-langinfo.c | 45 +++++++++++++++++++++++++++++++++++++ src/runtime/ppc-darwin-langinfo.h | 20 +++++++++++++++++ tools-for-build/grovel-headers.c | 9 ++++++-- version.lisp-expr | 2 +- 8 files changed, 114 insertions(+), 11 deletions(-) create mode 100644 src/runtime/ppc-darwin-dlshim.h create mode 100644 src/runtime/ppc-darwin-langinfo.c create mode 100644 src/runtime/ppc-darwin-langinfo.h diff --git a/src/code/foreign-load.lisp b/src/code/foreign-load.lisp index d8723f2..4a8d2d1 100644 --- a/src/code/foreign-load.lisp +++ b/src/code/foreign-load.lisp @@ -75,7 +75,7 @@ (setf dlerror (dlerror) (shared-object-sap obj) nil))) (when dlerror - (cerror dlerror)))) + (cerror "Ignore the error and continue anyway" "dlerror returned an error: ~S" dlerror)))) (defun load-shared-object (file) "Load a shared library/dynamic shared object file/general dlopenable diff --git a/src/runtime/Config.ppc-darwin b/src/runtime/Config.ppc-darwin index d911ab9..0b136ab 100644 --- a/src/runtime/Config.ppc-darwin +++ b/src/runtime/Config.ppc-darwin @@ -1,6 +1,6 @@ # -*- makefile -*- CFLAGS = -Dppc -g -Wall -O2 -no-cpp-precomp -OS_SRC = bsd-os.c os-common.c ppc-darwin-os.c ppc-darwin-dlshim.c +OS_SRC = bsd-os.c os-common.c ppc-darwin-os.c ppc-darwin-dlshim.c ppc-darwin-langinfo.c OS_LIBS = -lSystem -lc -lm # Avoid the gcc 3.3 prerelease tarpit of death! diff --git a/src/runtime/ppc-darwin-dlshim.c b/src/runtime/ppc-darwin-dlshim.c index 9187ef2..c6c16f3 100644 --- a/src/runtime/ppc-darwin-dlshim.c +++ b/src/runtime/ppc-darwin-dlshim.c @@ -19,6 +19,7 @@ #include #include #include +#include "ppc-darwin-dlshim.h" /* Darwin does not define the standard ELF * dlopen/dlclose/dlsym/dlerror interface to shared libraries, so this @@ -30,12 +31,9 @@ static char dl_self; /* I'm going to abuse this */ -#define RTLD_LAZY 1 -#define RTLD_NOW 2 -#define RTLD_GLOBAL 0x100 - static int callback_count; static struct mach_header* last_header; +static int last_was_error = 0; void dlshim_image_callback(struct mach_header* ptr, unsigned long phooey) { @@ -157,8 +155,17 @@ const char* dlerror() if (!errbuf) { errbuf = (char*) malloc(256*sizeof(char)); } - snprintf(errbuf, 255, "%s in %s: %d %d", c, d, a, b); - return errbuf; + if (!(c || d)) { + last_was_error = 0; + snprintf(errbuf, 255, "%s in %s: %d %d", c, d, a, b); + return errbuf; + } else if (last_was_error) { + last_was_error = 0; + snprintf(errbuf, 255, "Can't find symbol"); + return errbuf; + } + last_was_error = 0; + return NULL; } void* dlsym(void* handle, char* symbol) @@ -169,6 +176,7 @@ void* dlsym(void* handle, char* symbol) retsym = NSLookupAndBindSymbol(symbol); return NSAddressOfSymbol(retsym); } else { + last_was_error = 1; return NULL; } } else { @@ -177,6 +185,7 @@ void* dlsym(void* handle, char* symbol) retsym = NSLookupSymbolInImage(handle, symbol, 0); return NSAddressOfSymbol(retsym); } else { + last_was_error = 1; return NULL; } } diff --git a/src/runtime/ppc-darwin-dlshim.h b/src/runtime/ppc-darwin-dlshim.h new file mode 100644 index 0000000..1c9128e --- /dev/null +++ b/src/runtime/ppc-darwin-dlshim.h @@ -0,0 +1,24 @@ +/* + * These functions emulate a small subset of the dlopen / dlsym + * functionality under Darwin's Mach-O dyld system. + */ + +/* + * This software is part of the SBCL system. See the README file for + * more information. + * + * This software is derived from the CMU CL system, which was + * written at Carnegie Mellon University and released into the + * public domain. The software is in the public domain and is + * provided with absolutely no warranty. See the COPYING and CREDITS + * files for more information. + */ + +#ifndef PPC_DARWIN_DLSHIM_H +#define PPC_DARWIN_DLSHIM_H + +#define RTLD_LAZY 1 +#define RTLD_NOW 2 +#define RTLD_GLOBAL 0x100 + +#endif /* PPC_DARWIN_DLSHIM_H */ diff --git a/src/runtime/ppc-darwin-langinfo.c b/src/runtime/ppc-darwin-langinfo.c new file mode 100644 index 0000000..08ef419 --- /dev/null +++ b/src/runtime/ppc-darwin-langinfo.c @@ -0,0 +1,45 @@ +/* + * This is a minimal nl_langinfo replacement that only handles CODESET. + * By default, it returns UTF-8. It checks if LC_CTYPE or LANG are set, and + * uses LATIN-1 if it finds one set to C, or UTF-8 if it finds one set to + * anything else. + */ + +/* + * This software is part of the SBCL system. See the README file for + * more information. + * + * This software is derived from the CMU CL system, which was + * written at Carnegie Mellon University and released into the + * public domain. The software is in the public domain and is + * provided with absolutely no warranty. See the COPYING and CREDITS + * files for more information. + */ + +#include +#include "ppc-darwin-langinfo.h" + +char *nl_langinfo(nl_item item) +{ + char *nada = "", *utf8 = "UTF-8", *latin1 = "LATIN-1"; + + if (item != CODESET) { + return nada; + } else { + char *ctype = getenv ("LC_CTYPE"); + + if ((ctype != NULL) && (!strcmp(ctype, "C"))) { + return latin1; + } else if (ctype != NULL) { + return utf8; + } else { + char *lang = getenv ("LANG"); + + if ((lang != NULL) && (!strcmp(lang, "C"))) { + return latin1; + } else { + return utf8; + } + } + } +} diff --git a/src/runtime/ppc-darwin-langinfo.h b/src/runtime/ppc-darwin-langinfo.h new file mode 100644 index 0000000..bb96a8a --- /dev/null +++ b/src/runtime/ppc-darwin-langinfo.h @@ -0,0 +1,20 @@ +/* + * This software is part of the SBCL system. See the README file for + * more information. + * + * This software is derived from the CMU CL system, which was + * written at Carnegie Mellon University and released into the + * public domain. The software is in the public domain and is + * provided with absolutely no warranty. See the COPYING and CREDITS + * files for more information. + */ + +#ifndef PPC_DARWIN_LANGINFO_H +#define PPC_DARWIN_LANGINFO_H + +#define CODESET 49 + +typedef int nl_item; +char *nl_langinfo (nl_item); + +#endif /* PPC_DARWIN_LANGINFO_H */ diff --git a/tools-for-build/grovel-headers.c b/tools-for-build/grovel-headers.c index b117233..5a78c71 100644 --- a/tools-for-build/grovel-headers.c +++ b/tools-for-build/grovel-headers.c @@ -29,8 +29,13 @@ #include #include #include -#include -#include +#ifdef __APPLE_CC__ + #include "../src/runtime/ppc-darwin-dlshim.h" + #include "../src/runtime/ppc-darwin-langinfo.h" +#else + #include + #include +#endif #include "genesis/config.h" diff --git a/version.lisp-expr b/version.lisp-expr index bb83dce..c7d37d7 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"0.8.17.30" +"0.8.17.31" -- 1.7.10.4