/* Fundamental definitions for GNU Emacs Lisp interpreter. -*- coding: utf-8 -*-
-Copyright (C) 1985-1987, 1993-1995, 1997-2015 Free Software Foundation,
+Copyright (C) 1985-1987, 1993-1995, 1997-2016 Free Software Foundation,
Inc.
This file is part of GNU Emacs.
#define GCTYPEBITS 3
DEFINE_GDB_SYMBOL_END (GCTYPEBITS)
-/* The number of bits needed in an EMACS_INT over and above the number
- of bits in a pointer. This is 0 on systems where:
- 1. We can specify multiple-of-8 alignment on static variables.
- 2. We know malloc returns a multiple of 8. */
-#if (defined alignas \
- && (defined GNU_MALLOC || defined DOUG_LEA_MALLOC || defined __GLIBC__ \
- || defined DARWIN_OS || defined __sun || defined __MINGW32__ \
- || defined CYGWIN))
-# define NONPOINTER_BITS 0
-#else
-# define NONPOINTER_BITS GCTYPEBITS
-#endif
-
/* EMACS_INT - signed integer wide enough to hold an Emacs value
EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
pI - printf length modifier for EMACS_INT
#ifndef EMACS_INT_MAX
# if INTPTR_MAX <= 0
# error "INTPTR_MAX misconfigured"
-# elif INTPTR_MAX <= INT_MAX >> NONPOINTER_BITS && !defined WIDE_EMACS_INT
+# elif INTPTR_MAX <= INT_MAX && !defined WIDE_EMACS_INT
typedef int EMACS_INT;
typedef unsigned int EMACS_UINT;
# define EMACS_INT_MAX INT_MAX
# define pI ""
-# elif INTPTR_MAX <= LONG_MAX >> NONPOINTER_BITS && !defined WIDE_EMACS_INT
+# elif INTPTR_MAX <= LONG_MAX && !defined WIDE_EMACS_INT
typedef long int EMACS_INT;
typedef unsigned long EMACS_UINT;
# define EMACS_INT_MAX LONG_MAX
# define pI "l"
-/* Check versus LLONG_MAX, not LLONG_MAX >> NONPOINTER_BITS.
- In theory this is not safe, but in practice it seems to be OK. */
# elif INTPTR_MAX <= LLONG_MAX
typedef long long int EMACS_INT;
typedef unsigned long long int EMACS_UINT;
error !;
#endif
-#ifndef alignas
-# error "alignas not defined"
-#endif
-
#ifdef HAVE_STRUCT_ATTRIBUTE_ALIGNED
# define GCALIGNED __attribute__ ((aligned (GCALIGNMENT)))
#else
# define lisp_h_XINT(a) (XLI (a) >> INTTYPEBITS)
# define lisp_h_XSYMBOL(a) \
(eassert (SYMBOLP (a)), \
- (struct Lisp_Symbol *) ((uintptr_t) XLI (a) - Lisp_Symbol \
+ (struct Lisp_Symbol *) ((intptr_t) XLI (a) - Lisp_Symbol \
+ (char *) lispsym))
# define lisp_h_XTYPE(a) ((enum Lisp_Type) (XLI (a) & ~VALMASK))
# define lisp_h_XUNTAG(a, type) ((void *) (intptr_t) (XLI (a) - (type)))
#if (defined __NO_INLINE__ \
&& ! defined __OPTIMIZE__ && ! defined __OPTIMIZE_SIZE__ \
&& ! (defined INLINING && ! INLINING))
+# define DEFINE_KEY_OPS_AS_MACROS true
+#else
+# define DEFINE_KEY_OPS_AS_MACROS false
+#endif
+
+#if DEFINE_KEY_OPS_AS_MACROS
# define XLI(o) lisp_h_XLI (o)
# define XIL(i) lisp_h_XIL (i)
# define CHECK_LIST_CONS(x, y) lisp_h_CHECK_LIST_CONS (x, y)
Lisp_Misc_Overlay,
Lisp_Misc_Save_Value,
Lisp_Misc_Finalizer,
+#ifdef HAVE_MODULES
+ Lisp_Misc_User_Ptr,
+#endif
/* Currently floats are not a misc type,
but let's define this in case we want to change that. */
Lisp_Misc_Float,
INLINE bool PSEUDOVECTORP (Lisp_Object, int);
INLINE bool SAVE_VALUEP (Lisp_Object);
INLINE bool FINALIZERP (Lisp_Object);
+
+#ifdef HAVE_MODULES
+INLINE bool USER_PTRP (Lisp_Object);
+INLINE struct Lisp_User_Ptr *(XUSER_PTR) (Lisp_Object);
+#endif
+
INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t,
Lisp_Object);
INLINE bool STRINGP (Lisp_Object);
#define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
-/* Yield an integer that contains TAG along with PTR. */
+/* Yield a signed integer that contains TAG along with PTR.
+
+ Sign-extend pointers when USE_LSB_TAG (this simplifies emacs-module.c),
+ and zero-extend otherwise (that’s a bit faster here).
+ Sign extension matters only when EMACS_INT is wider than a pointer. */
#define TAG_PTR(tag, ptr) \
- ((USE_LSB_TAG ? (tag) : (EMACS_UINT) (tag) << VALBITS) + (uintptr_t) (ptr))
+ (USE_LSB_TAG \
+ ? (intptr_t) (ptr) + (tag) \
+ : (EMACS_INT) (((EMACS_UINT) (tag) << VALBITS) + (uintptr_t) (ptr)))
/* Yield an integer that contains a symbol tag along with OFFSET.
OFFSET should be the offset in bytes from 'lispsym' to the symbol. */
PVEC_WINDOW_CONFIGURATION,
PVEC_SUBR,
PVEC_OTHER,
+ PVEC_XWIDGET,
+ PVEC_XWIDGET_VIEW,
+
/* These should be last, check internal_equal to see why. */
PVEC_COMPILED,
PVEC_CHAR_TABLE,
INLINE EMACS_INT
(XFASTINT) (Lisp_Object a)
{
- return lisp_h_XFASTINT (a);
+ EMACS_INT n = lisp_h_XFASTINT (a);
+ eassume (0 <= n);
+ return n;
}
INLINE struct Lisp_Symbol *
{
EMACS_INT int0 = Lisp_Int0;
EMACS_INT n = USE_LSB_TAG ? XINT (a) : XLI (a) - (int0 << VALBITS);
- eassert (0 <= n);
+ eassume (0 <= n);
return n;
}
-/* Extract A's value as a symbol. */
-INLINE struct Lisp_Symbol *
-XSYMBOL (Lisp_Object a)
-{
- uintptr_t i = (uintptr_t) XUNTAG (a, Lisp_Symbol);
- void *p = (char *) lispsym + i;
- return p;
-}
-
/* Extract A's type. */
INLINE enum Lisp_Type
XTYPE (Lisp_Object a)
return USE_LSB_TAG ? i & ~VALMASK : i >> VALBITS;
}
+/* Extract A's value as a symbol. */
+INLINE struct Lisp_Symbol *
+XSYMBOL (Lisp_Object a)
+{
+ eassert (SYMBOLP (a));
+ intptr_t i = (intptr_t) XUNTAG (a, Lisp_Symbol);
+ void *p = (char *) lispsym + i;
+ return p;
+}
+
/* Extract A's pointer value, assuming A's type is TYPE. */
INLINE void *
XUNTAG (Lisp_Object a, int type)
/* Mark STR as a unibyte string. */
#define STRING_SET_UNIBYTE(STR) \
do { \
- if (EQ (STR, empty_multibyte_string)) \
+ if (XSTRING (STR)->size == 0) \
(STR) = empty_unibyte_string; \
else \
XSTRING (STR)->size_byte = -1; \
ASCII characters in advance. */
#define STRING_SET_MULTIBYTE(STR) \
do { \
- if (EQ (STR, empty_unibyte_string)) \
+ if (XSTRING (STR)->size == 0) \
(STR) = empty_multibyte_string; \
else \
XSTRING (STR)->size_byte = XSTRING (STR)->size; \
INLINE ptrdiff_t
ASIZE (Lisp_Object array)
{
- return XVECTOR (array)->header.size;
+ ptrdiff_t size = XVECTOR (array)->header.size;
+ eassume (0 <= size);
+ return size;
+}
+
+INLINE ptrdiff_t
+gc_asize (Lisp_Object array)
+{
+ /* Like ASIZE, but also can be used in the garbage collector. */
+ return XVECTOR (array)->header.size & ~ARRAY_MARK_FLAG;
}
INLINE void
{
/* Like ASET, but also can be used in the garbage collector:
sweep_weak_table calls set_hash_key etc. while the table is marked. */
- eassert (0 <= idx && idx < (ASIZE (array) & ~ARRAY_MARK_FLAG));
+ eassert (0 <= idx && idx < gc_asize (array));
XVECTOR (array)->contents[idx] = val;
}
};
+INLINE bool
+HASH_TABLE_P (Lisp_Object a)
+{
+ return PSEUDOVECTORP (a, PVEC_HASH_TABLE);
+}
+
INLINE struct Lisp_Hash_Table *
XHASH_TABLE (Lisp_Object a)
{
+ eassert (HASH_TABLE_P (a));
return XUNTAG (a, Lisp_Vectorlike);
}
#define XSET_HASH_TABLE(VAR, PTR) \
(XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
-INLINE bool
-HASH_TABLE_P (Lisp_Object a)
-{
- return PSEUDOVECTORP (a, PVEC_HASH_TABLE);
-}
-
/* Value is the key part of entry IDX in hash table H. */
INLINE Lisp_Object
HASH_KEY (struct Lisp_Hash_Table *h, ptrdiff_t idx)
/* For markers that point somewhere,
this is used to chain of all the markers in a given buffer. */
/* We could remove it and use an array in buffer_text instead.
- That would also allow to preserve it ordered. */
+ That would also allow us to preserve it ordered. */
struct Lisp_Marker *next;
/* This is the char position where the marker points. */
ptrdiff_t charpos;
return XSAVE_VALUE (obj)->data[n].object;
}
+#ifdef HAVE_MODULES
+struct Lisp_User_Ptr
+{
+ ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_User_Ptr */
+ bool_bf gcmarkbit : 1;
+ unsigned spacer : 15;
+
+ void (*finalizer) (void *);
+ void *p;
+};
+#endif
+
/* A finalizer sentinel. */
struct Lisp_Finalizer
{
struct Lisp_Overlay u_overlay;
struct Lisp_Save_Value u_save_value;
struct Lisp_Finalizer u_finalizer;
+#ifdef HAVE_MODULES
+ struct Lisp_User_Ptr u_user_ptr;
+#endif
};
INLINE union Lisp_Misc *
return & XMISC (a)->u_finalizer;
}
+#ifdef HAVE_MODULES
+INLINE struct Lisp_User_Ptr *
+XUSER_PTR (Lisp_Object a)
+{
+ eassert (USER_PTRP (a));
+ return & XMISC (a)->u_user_ptr;
+}
+#endif
+
\f
/* Forwarding pointer to an int variable.
This is allowed only in the value cell of a symbol,
return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Finalizer;
}
+#ifdef HAVE_MODULES
+INLINE bool
+USER_PTRP (Lisp_Object x)
+{
+ return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_User_Ptr;
+}
+#endif
+
INLINE bool
AUTOLOADP (Lisp_Object x)
{
struct byte_stack *byte_stack;
};
-/* Fill in the components of c, and put it on the list. */
-#define PUSH_HANDLER(c, tag_ch_val, handlertype) \
- push_handler(&(c), (tag_ch_val), (handlertype))
-
-extern void push_handler (struct handler **c, Lisp_Object tag_ch_val,
- enum handlertype handlertype);
-
-/* Like push_handler, but don't signal if the handler could not be
- allocated. Instead return false in that case. */
-extern bool push_handler_nosignal (struct handler **c, Lisp_Object tag_ch_val,
- enum handlertype handlertype);
-
extern Lisp_Object memory_signal_data;
/* An address near the bottom of the stack.
ptrdiff_t *, ptrdiff_t *);
/* Defined in alloc.c. */
+extern void *my_heap_start (void);
extern void check_pure_size (void);
extern void free_misc (Lisp_Object);
extern void allocate_string_data (struct Lisp_String *, EMACS_INT, EMACS_INT);
#if defined REL_ALLOC && !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
extern void refill_memory_reserve (void);
#endif
+#ifdef DOUG_LEA_MALLOC
+extern void alloc_unexec_pre (void);
+extern void alloc_unexec_post (void);
+#else
+INLINE void alloc_unexec_pre (void) {}
+INLINE void alloc_unexec_post (void) {}
+#endif
extern const char *pending_malloc_warning;
extern Lisp_Object zero_vector;
extern Lisp_Object *stack_base;
}
/* Defined in eval.c. */
-extern EMACS_INT lisp_eval_depth;
extern Lisp_Object Vautoload_queue;
extern Lisp_Object Vrun_hooks;
extern Lisp_Object Vsignaling_function;
extern Lisp_Object internal_condition_case_n
(Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *,
Lisp_Object, Lisp_Object (*) (Lisp_Object, ptrdiff_t, Lisp_Object *));
+extern struct handler *push_handler (Lisp_Object, enum handlertype);
+extern struct handler *push_handler_nosignal (Lisp_Object, enum handlertype);
extern void specbind (Lisp_Object, Lisp_Object);
extern void record_unwind_protect (void (*) (Lisp_Object), Lisp_Object);
extern void record_unwind_protect_ptr (void (*) (void *), void *);
extern bool let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol);
extern bool let_shadows_global_binding_p (Lisp_Object symbol);
+#ifdef HAVE_MODULES
+/* Defined in alloc.c. */
+extern Lisp_Object make_user_ptr (void (*finalizer) (void *), void *p);
+
+/* Defined in emacs-module.c. */
+extern void module_init (void);
+extern void syms_of_module (void);
+#endif
/* Defined in editfns.c. */
extern void insert1 (Lisp_Object);
extern void syms_of_fontset (void);
#endif
+/* Defined in inotify.c */
+#ifdef HAVE_INOTIFY
+extern void syms_of_inotify (void);
+#endif
+
+/* Defined in kqueue.c */
+#ifdef HAVE_KQUEUE
+extern void globals_of_kqueue (void);
+extern void syms_of_kqueue (void);
+#endif
+
/* Defined in gfilenotify.c */
#ifdef HAVE_GFILENOTIFY
extern void globals_of_gfilenotify (void);
extern void syms_of_gfilenotify (void);
#endif
-/* Defined in inotify.c */
-#ifdef HAVE_INOTIFY
-extern void syms_of_inotify (void);
-#endif
-
#ifdef HAVE_W32NOTIFY
/* Defined on w32notify.c. */
extern void syms_of_w32notify (void);
This feature is experimental and requires careful debugging.
Build with CPPFLAGS='-DUSE_STACK_LISP_OBJECTS=0' to disable it. */
+#if (!defined USE_STACK_LISP_OBJECTS \
+ && defined __GNUC__ && !defined __clang__ \
+ && !(4 < __GNUC__ + (3 < __GNUC_MINOR__ + (2 <= __GNUC_PATCHLEVEL__))))
+ /* Work around GCC bugs 36584 and 35271, which were fixed in GCC 4.3.2. */
+# define USE_STACK_LISP_OBJECTS false
+#endif
#ifndef USE_STACK_LISP_OBJECTS
# define USE_STACK_LISP_OBJECTS true
#endif