-/* Copyright (C) 2001, 2009, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 2001, 2009, 2010, 2011 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
#include "programs.h"
#include "objcodes.h"
-/* SCM_OBJCODE_COOKIE is defined in _scm.h */
-/* The length of the header must be a multiple of 8 bytes. */
+/* SCM_OBJCODE_COOKIE, defined in _scm.h, is a magic value prepended
+ to objcode on disk but not in memory.
+
+ The length of the header must be a multiple of 8 bytes. */
verify (((sizeof (SCM_OBJCODE_COOKIE) - 1) & 7) == 0);
\f
* Objcode type
*/
-scm_t_bits scm_tc16_objcode;
+/* The words in an objcode SCM object are as follows:
+ - scm_tc7_objcode | type | flags
+ - the struct scm_objcode C object
+ - the parent of this objcode: either another objcode, a bytevector,
+ or, in the case of mmap types, file descriptors (as an inum)
+ - "native code" -- not currently used.
+ */
static SCM
make_objcode_by_mmap (int fd)
SCM_SYSERROR;
}
- if (memcmp (addr, SCM_OBJCODE_COOKIE, strlen (SCM_OBJCODE_COOKIE)))
+ /* The cookie ends with a version of the form M.N, where M is the
+ major version and N is the minor version. For this Guile to be
+ able to load an objcode, M must be SCM_OBJCODE_MAJOR_VERSION, and N
+ must be less than or equal to SCM_OBJCODE_MINOR_VERSION. Since N
+ is the last character, we do a strict comparison on all but the
+ last, then a <= on the last one. */
+ if (memcmp (addr, SCM_OBJCODE_COOKIE, strlen (SCM_OBJCODE_COOKIE) - 1))
{
- SCM args = scm_list_1 (scm_from_locale_stringn
+ SCM args = scm_list_1 (scm_from_latin1_stringn
(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);
}
+ {
+ char minor_version = addr[strlen (SCM_OBJCODE_COOKIE) - 1];
+
+ if (minor_version > SCM_OBJCODE_MINOR_VERSION_STRING[0])
+ scm_misc_error (FUNC_NAME, "objcode minor version too new (~a > ~a)",
+ scm_list_2 (scm_from_latin1_stringn (&minor_version, 1),
+ scm_from_latin1_string
+ (SCM_OBJCODE_MINOR_VERSION_STRING)));
+ }
+
data = (struct scm_objcode*)(addr + strlen (SCM_OBJCODE_COOKIE));
if (data->len + data->metalen != (st.st_size - sizeof (*data) - strlen (SCM_OBJCODE_COOKIE)))
+ data->metalen)));
}
- 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);
+ sret = scm_double_cell (SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_MMAP, 0),
+ (scm_t_bits)(addr + strlen (SCM_OBJCODE_COOKIE)),
+ SCM_UNPACK (scm_from_int (fd)), 0);
/* FIXME: we leak ourselves and the file descriptor. but then again so does
dlopen(). */
{
const struct scm_objcode *data, *parent_data;
const scm_t_uint8 *parent_base;
- SCM ret;
SCM_VALIDATE_OBJCODE (1, parent);
parent_data = SCM_OBJCODE_DATA (parent);
if (ptr < parent_base
|| ptr >= (parent_base + parent_data->len + parent_data->metalen
- sizeof (struct scm_objcode)))
- scm_misc_error (FUNC_NAME, "offset out of bounds (~a vs ~a + ~a + ~a)",
- scm_list_4 (scm_from_ulong ((unsigned long) ptr),
- scm_from_ulong ((unsigned long) parent_base),
- scm_from_uint32 (parent_data->len),
- scm_from_uint32 (parent_data->metalen)));
+ scm_misc_error
+ (FUNC_NAME, "offset out of bounds (~a vs ~a + ~a + ~a)",
+ scm_list_4 (scm_from_unsigned_integer ((scm_t_bits) ptr),
+ scm_from_unsigned_integer ((scm_t_bits) parent_base),
+ scm_from_uint32 (parent_data->len),
+ scm_from_uint32 (parent_data->metalen)));
/* Make sure bytecode for the objcode-meta is suitable aligned. Failing to
do so leads to SIGBUS/SIGSEGV on some arches (e.g., SPARC). */
assert (SCM_C_OBJCODE_BASE (data) + data->len + data->metalen
<= parent_base + parent_data->len + parent_data->metalen);
- SCM_NEWSMOB2 (ret, scm_tc16_objcode, data, parent);
- SCM_SET_SMOB_FLAGS (ret, SCM_F_OBJCODE_IS_SLICE);
- return ret;
+ return scm_double_cell (SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_SLICE, 0),
+ (scm_t_bits)data, SCM_UNPACK (parent), 0);
}
#undef FUNC_NAME
size_t size;
const scm_t_uint8 *c_bytecode;
struct scm_objcode *data;
- SCM objcode;
if (!scm_is_bytevector (bytecode))
scm_wrong_type_arg (FUNC_NAME, 1, bytecode);
scm_list_2 (scm_from_size_t (size),
scm_from_uint32 (sizeof (*data) + data->len + data->metalen)));
- SCM_NEWSMOB2 (objcode, scm_tc16_objcode, data, bytecode);
- SCM_SET_SMOB_FLAGS (objcode, SCM_F_OBJCODE_IS_BYTEVECTOR);
-
/* foolishly, we assume that as long as bytecode is around, that c_bytecode
will be of the same length; perhaps a bad assumption? */
-
- return objcode;
+ return scm_double_cell (SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_BYTEVECTOR, 0),
+ (scm_t_bits)data, SCM_UNPACK (bytecode), 0);
}
#undef FUNC_NAME
SCM_VALIDATE_OBJCODE (1, objcode);
- len = sizeof(struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode);
+ len = sizeof (struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode);
s8vector = scm_malloc (len);
memcpy (s8vector, SCM_OBJCODE_DATA (objcode), len);
}
#undef FUNC_NAME
+void
+scm_i_objcode_print (SCM objcode, SCM port, scm_print_state *pstate)
+{
+ scm_puts ("#<objcode ", port);
+ scm_uintprint ((scm_t_bits)SCM_OBJCODE_BASE (objcode), 16, port);
+ scm_puts (">", port);
+}
+
\f
void
scm_bootstrap_objcodes (void)
{
- scm_tc16_objcode = scm_make_smob_type ("objcode", 0);
- scm_c_register_extension ("libguile", "scm_init_objcodes",
+ scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
+ "scm_init_objcodes",
(scm_t_extension_init_func)scm_init_objcodes, NULL);
}