summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-12-12 12:59:57 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2017-12-12 15:17:12 -0800
commit244346c744a6700d320a0a0fe8c796be3b3ff023 (patch)
tree145dc0ba87fcf82de44e62ecbdeb70fe86c28c7a /src/alloc.c
parentc705f7250d6f17f1682ee5ad7eec516dbf6c3916 (diff)
downloademacs-244346c744a6700d320a0a0fe8c796be3b3ff023.tar.gz
emacs-244346c744a6700d320a0a0fe8c796be3b3ff023.tar.bz2
emacs-244346c744a6700d320a0a0fe8c796be3b3ff023.zip
Reimplement Lisp_Object as pointer-to-incomplete
This makes Lisp_Object values opaque pointers instead of integers, which helps avoid the same sort of typos that CHECK_LISP_OBJECT_TYPE helps to avoid, without having to wrap pointers inside structures. This also looks forward to supporting -fcheck-pointer-bounds. * etc/DEBUG: * src/.gdbinit (Lisp_Object_Printer.to_string): Lisp_Object can be a pointer type now. * src/alloc.c (macro_XPNTR, XPNTR): * src/emacs-module.c (value_to_lisp_bits, lisp_to_value_bits): * src/lisp.h (lisp_h_XLI, lisp_h_XIL): (lisp_h_XUNTAG) [USE_LSB_TAG]: (XUNTAG) [!USE_LSB_TAG]: (Lisp_Object, TAG_PTR, make_lisp_symbol): Support new Lisp_Object implementation as a pointer to an incomplete type. Keep pointers pointers, as much as possible. * src/alloc.c (macro_XPNTR_OR_SYMBOL_OFFSET, XPNTR_OR_SYMBOL_OFFSET): Remove. All uses replaced by plain XPNTR. * src/emacs-module.c: Work around GCC bug 83162. * src/lisp.h (LISP_WORDS_ARE_POINTERS, lisp_h_XLP, lisp_h_XPL): (XLP, XPL) [DEFINE_KEY_OPS_AS_MACROS]: New macros. (Lisp_Word, untagged_ptr, Lisp_Word_tag): New types. (XLP, XPL): New inline functions. (TAG_PTR): Now expands to an initializer, not an expression. All uses changed. (TAG_SYMOFFSET, XLI_BUILTIN_LISPSYM): Remove. All uses removed. (LISPSYM_INITIALLY): Redo in terms of the new TAG_PTR. (NIL_IS_ZERO): Redo without XLI_BUILTIN_LISPSYM. * src/xwidget.c (webkit_javascript_finished_cb): Use XPL instead of XIL with a non-EMACS_INT arg. (Fxwidget_webkit_execute_script): Use XLP instead of XLI followed by two conversions.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 4f3928a4824..38daee065ae 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -502,30 +502,20 @@ pointer_align (void *ptr, int alignment)
return (void *) ROUNDUP ((uintptr_t) ptr, alignment);
}
-/* Extract the pointer hidden within A, if A is not a symbol.
- If A is a symbol, extract the hidden pointer's offset from lispsym,
- converted to void *. */
+/* Extract the pointer hidden within O. Define this as a function, as
+ functions are cleaner and can be used in debuggers. Also, define
+ it as a macro if being compiled with GCC without optimization, for
+ performance in that case. macro_XPNTR is private to this section
+ of code. */
+
+#define macro_XPNTR(o) \
+ ((void *) \
+ (SYMBOLP (o) \
+ ? ((char *) lispsym \
+ - ((EMACS_UINT) Lisp_Symbol << (USE_LSB_TAG ? 0 : VALBITS)) \
+ + XLI (o)) \
+ : (char *) XLP (o) - (XLI (o) & ~VALMASK)))
-#define macro_XPNTR_OR_SYMBOL_OFFSET(a) \
- ((void *) (intptr_t) (USE_LSB_TAG ? XLI (a) - XTYPE (a) : XLI (a) & VALMASK))
-
-/* Extract the pointer hidden within A. */
-
-#define macro_XPNTR(a) \
- ((void *) ((intptr_t) XPNTR_OR_SYMBOL_OFFSET (a) \
- + (SYMBOLP (a) ? (char *) lispsym : NULL)))
-
-/* For pointer access, define XPNTR and XPNTR_OR_SYMBOL_OFFSET as
- functions, as functions are cleaner and can be used in debuggers.
- Also, define them as macros if being compiled with GCC without
- optimization, for performance in that case. The macro_* names are
- private to this section of code. */
-
-static ATTRIBUTE_UNUSED void *
-XPNTR_OR_SYMBOL_OFFSET (Lisp_Object a)
-{
- return macro_XPNTR_OR_SYMBOL_OFFSET (a);
-}
static ATTRIBUTE_UNUSED void *
XPNTR (Lisp_Object a)
{
@@ -533,7 +523,6 @@ XPNTR (Lisp_Object a)
}
#if DEFINE_KEY_OPS_AS_MACROS
-# define XPNTR_OR_SYMBOL_OFFSET(a) macro_XPNTR_OR_SYMBOL_OFFSET (a)
# define XPNTR(a) macro_XPNTR (a)
#endif
@@ -5605,7 +5594,7 @@ static Lisp_Object
purecopy (Lisp_Object obj)
{
if (INTEGERP (obj)
- || (! SYMBOLP (obj) && PURE_P (XPNTR_OR_SYMBOL_OFFSET (obj)))
+ || (! SYMBOLP (obj) && PURE_P (XPNTR (obj)))
|| SUBRP (obj))
return obj; /* Already pure. */