include objcode cookie in the fallback path
authorAndy Wingo <wingo@pobox.com>
Tue, 11 Aug 2009 18:25:19 +0000 (20:25 +0200)
committerAndy Wingo <wingo@pobox.com>
Tue, 11 Aug 2009 18:25:44 +0000 (20:25 +0200)
* libguile/_scm.h (SCM_OBJCODE_COOKIE): Move the objcode cookie define
  here, so that load.c can use it. This is a private header.

* libguile/load.c (FALLBACK_DIR): Include the objcode cookie in the
  fallback path. Should fix problems when objcode changes incompatibly
  during the 1.9 series.

* libguile/objcodes.c: Adapt to SCM_OBJCODE_COOKIE move.

This should fix http://article.gmane.org/gmane.lisp.guile.devel/9059.

libguile/_scm.h
libguile/load.c
libguile/objcodes.c

index 429e87b..693ec1d 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef SCM__SCM_H
 #define SCM__SCM_H
 
-/* Copyright (C) 1995,1996,2000,2001, 2002, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,2000,2001, 2002, 2006, 2008, 2009 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -59,6 +59,7 @@
 #endif
 
 #include <errno.h>
+#include <verify.h>
 #include "libguile/__scm.h"
 
 /* Include headers for those files central to the implementation.  The
 #define scm_from_off64_t  scm_from_int64
 
 
+/* The endianness marker in objcode.  */
+#ifdef WORDS_BIGENDIAN
+# define SCM_OBJCODE_ENDIANNESS "BE"
+#else
+# define SCM_OBJCODE_ENDIANNESS "LE"
+#endif
+
+#define _SCM_CPP_STRINGIFY(x)  # x
+#define SCM_CPP_STRINGIFY(x)   _SCM_CPP_STRINGIFY (x)
+
+/* The word size marker in objcode.  */
+#define SCM_OBJCODE_WORD_SIZE  SCM_CPP_STRINGIFY (SIZEOF_VOID_P)
+
+/* The objcode magic header.  */
+#define SCM_OBJCODE_COOKIE                                             \
+  "GOOF-0.9-" SCM_OBJCODE_ENDIANNESS "-" SCM_OBJCODE_WORD_SIZE "---"
+
+
 #endif  /* SCM__SCM_H */
 
 /*
index 890b0f8..b27bb82 100644 (file)
@@ -253,7 +253,7 @@ scm_init_load_path ()
     struct passwd *pwd;
 #endif
 
-#define FALLBACK_DIR "guile/ccache/"SCM_EFFECTIVE_VERSION
+#define FALLBACK_DIR "guile/ccache/"SCM_EFFECTIVE_VERSION"/"SCM_OBJCODE_COOKIE
 
     if ((e = getenv ("XDG_CACHE_HOME")))
       snprintf (cachedir, sizeof(cachedir), "%s" FALLBACK_DIR, e);
index 91691a7..19c2406 100644 (file)
 #include <sys/types.h>
 #include <assert.h>
 
-#include <verify.h>
-
 #include "_scm.h"
 #include "vm-bootstrap.h"
 #include "programs.h"
 #include "objcodes.h"
 
-/* The endianness marker in objcode.  */
-#ifdef WORDS_BIGENDIAN
-# define OBJCODE_ENDIANNESS "BE"
-#else
-# define OBJCODE_ENDIANNESS "LE"
-#endif
-
-#define _OBJCODE_STRINGIFY(x)  # x
-#define OBJCODE_STRINGIFY(x)   _OBJCODE_STRINGIFY (x)
-
-/* The word size marker in objcode.  */
-#define OBJCODE_WORD_SIZE  OBJCODE_STRINGIFY (SIZEOF_VOID_P)
-
-/* The objcode magic header.  */
-#define OBJCODE_COOKIE                                         \
-  "GOOF-0.9-" OBJCODE_ENDIANNESS "-" OBJCODE_WORD_SIZE "---"
-
+/* SCM_OBJCODE_COOKIE is defined in _scm.h */
 /* The length of the header must be a multiple of 8 bytes.  */
-verify (((sizeof (OBJCODE_COOKIE) - 1) & 7) == 0);
-
+verify (((sizeof (SCM_OBJCODE_COOKIE) - 1) & 7) == 0);
 
 \f
 /*
@@ -77,7 +58,7 @@ make_objcode_by_mmap (int fd)
   if (ret < 0)
     SCM_SYSERROR;
 
-  if (st.st_size <= sizeof (struct scm_objcode) + strlen (OBJCODE_COOKIE))
+  if (st.st_size <= sizeof (struct scm_objcode) + strlen (SCM_OBJCODE_COOKIE))
     scm_misc_error (FUNC_NAME, "object file too small (~a bytes)",
                    scm_list_1 (SCM_I_MAKINUM (st.st_size)));
 
@@ -88,18 +69,18 @@ make_objcode_by_mmap (int fd)
       SCM_SYSERROR;
     }
 
-  if (memcmp (addr, OBJCODE_COOKIE, strlen (OBJCODE_COOKIE)))
+  if (memcmp (addr, SCM_OBJCODE_COOKIE, strlen (SCM_OBJCODE_COOKIE)))
     {
       SCM args = scm_list_1 (scm_from_locale_stringn
-                             (addr, strlen (OBJCODE_COOKIE)));
+                             (addr, strlen (SCM_OBJCODE_COOKIE)));
       (void) close (fd);
       (void) munmap (addr, st.st_size);
       scm_misc_error (FUNC_NAME, "bad header on object file: ~s", args);
     }
 
-  data = (struct scm_objcode*)(addr + strlen (OBJCODE_COOKIE));
+  data = (struct scm_objcode*)(addr + strlen (SCM_OBJCODE_COOKIE));
 
-  if (data->len + data->metalen != (st.st_size - sizeof (*data) - strlen (OBJCODE_COOKIE)))
+  if (data->len + data->metalen != (st.st_size - sizeof (*data) - strlen (SCM_OBJCODE_COOKIE)))
     {
       (void) close (fd);
       (void) munmap (addr, st.st_size);
@@ -109,7 +90,7 @@ make_objcode_by_mmap (int fd)
                                                   + data->metalen)));
     }
 
-  SCM_NEWSMOB3 (sret, scm_tc16_objcode, addr + strlen (OBJCODE_COOKIE),
+  SCM_NEWSMOB3 (sret, scm_tc16_objcode, addr + strlen (SCM_OBJCODE_COOKIE),
                 SCM_PACK (SCM_BOOL_F), fd);
   SCM_SET_SMOB_FLAGS (sret, SCM_F_OBJCODE_IS_MMAP);
 
@@ -270,7 +251,7 @@ SCM_DEFINE (scm_write_objcode, "write-objcode", 2, 0, 0,
   SCM_VALIDATE_OBJCODE (1, objcode);
   SCM_VALIDATE_OUTPUT_PORT (2, port);
   
-  scm_c_write (port, OBJCODE_COOKIE, strlen (OBJCODE_COOKIE));
+  scm_c_write (port, SCM_OBJCODE_COOKIE, strlen (SCM_OBJCODE_COOKIE));
   scm_c_write (port, SCM_OBJCODE_DATA (objcode),
                sizeof (struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode));