0.8.17.31: "dlerror and a tale of woe"
authorBrian Mastenbrook <bmastenb@cs.indiana.edu>
Mon, 20 Dec 2004 13:10:38 +0000 (13:10 +0000)
committerBrian Mastenbrook <bmastenb@cs.indiana.edu>
Mon, 20 Dec 2004 13:10:38 +0000 (13:10 +0000)
    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
src/runtime/Config.ppc-darwin
src/runtime/ppc-darwin-dlshim.c
src/runtime/ppc-darwin-dlshim.h [new file with mode: 0644]
src/runtime/ppc-darwin-langinfo.c [new file with mode: 0644]
src/runtime/ppc-darwin-langinfo.h [new file with mode: 0644]
tools-for-build/grovel-headers.c
version.lisp-expr

index d8723f2..4a8d2d1 100644 (file)
@@ -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
index d911ab9..0b136ab 100644 (file)
@@ -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!
index 9187ef2..c6c16f3 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "ppc-darwin-dlshim.h"
 
 /* Darwin does not define the standard ELF
  * dlopen/dlclose/dlsym/dlerror interface to shared libraries, so this
 
 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 (file)
index 0000000..1c9128e
--- /dev/null
@@ -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 (file)
index 0000000..08ef419
--- /dev/null
@@ -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 <stdlib.h>
+#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 (file)
index 0000000..bb96a8a
--- /dev/null
@@ -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 */
index b117233..5a78c71 100644 (file)
 #include <unistd.h>
 #include <signal.h>
 #include <errno.h>
-#include <dlfcn.h>
-#include <langinfo.h>
+#ifdef __APPLE_CC__
+  #include "../src/runtime/ppc-darwin-dlshim.h"
+  #include "../src/runtime/ppc-darwin-langinfo.h"
+#else
+  #include <dlfcn.h>
+  #include <langinfo.h>
+#endif
 
 #include "genesis/config.h"
 
index bb83dce..c7d37d7 100644 (file)
@@ -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"