aboutsummaryrefslogtreecommitdiffstats
path: root/src/emacs-module.c
diff options
context:
space:
mode:
authorPaul Eggert2017-12-12 12:59:57 -0800
committerPaul Eggert2017-12-12 15:17:12 -0800
commit244346c744a6700d320a0a0fe8c796be3b3ff023 (patch)
tree145dc0ba87fcf82de44e62ecbdeb70fe86c28c7a /src/emacs-module.c
parentc705f7250d6f17f1682ee5ad7eec516dbf6c3916 (diff)
downloademacs-244346c744a6700d320a0a0fe8c796be3b3ff023.tar.gz
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/emacs-module.c')
-rw-r--r--src/emacs-module.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c
index b351515c3bd..9a02e7d4821 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -36,6 +36,11 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
36#include <intprops.h> 36#include <intprops.h>
37#include <verify.h> 37#include <verify.h>
38 38
39/* Work around GCC bug 83162. */
40#if GNUC_PREREQ (4, 3, 0)
41# pragma GCC diagnostic ignored "-Wclobbered"
42#endif
43
39/* We use different strategies for allocating the user-visible objects 44/* We use different strategies for allocating the user-visible objects
40 (struct emacs_runtime, emacs_env, emacs_value), depending on 45 (struct emacs_runtime, emacs_env, emacs_value), depending on
41 whether the user supplied the -module-assertions flag. If 46 whether the user supplied the -module-assertions flag. If
@@ -915,9 +920,8 @@ static Lisp_Object ltv_mark;
915static Lisp_Object 920static Lisp_Object
916value_to_lisp_bits (emacs_value v) 921value_to_lisp_bits (emacs_value v)
917{ 922{
918 intptr_t i = (intptr_t) v;
919 if (plain_values || USE_LSB_TAG) 923 if (plain_values || USE_LSB_TAG)
920 return XIL (i); 924 return XPL (v);
921 925
922 /* With wide EMACS_INT and when tag bits are the most significant, 926 /* With wide EMACS_INT and when tag bits are the most significant,
923 reassembling integers differs from reassembling pointers in two 927 reassembling integers differs from reassembling pointers in two
@@ -926,6 +930,7 @@ value_to_lisp_bits (emacs_value v)
926 integer when restoring, but zero-extend pointers because that 930 integer when restoring, but zero-extend pointers because that
927 makes TAG_PTR faster. */ 931 makes TAG_PTR faster. */
928 932
933 intptr_t i = (intptr_t) v;
929 EMACS_UINT tag = i & (GCALIGNMENT - 1); 934 EMACS_UINT tag = i & (GCALIGNMENT - 1);
930 EMACS_UINT untagged = i - tag; 935 EMACS_UINT untagged = i - tag;
931 switch (tag) 936 switch (tag)
@@ -989,13 +994,22 @@ value_to_lisp (emacs_value v)
989static emacs_value 994static emacs_value
990lisp_to_value_bits (Lisp_Object o) 995lisp_to_value_bits (Lisp_Object o)
991{ 996{
992 EMACS_UINT u = XLI (o); 997 if (plain_values || USE_LSB_TAG)
998 return XLP (o);
993 999
994 /* Compress U into the space of a pointer, possibly losing information. */ 1000 /* Compress O into the space of a pointer, possibly losing information. */
995 uintptr_t p = (plain_values || USE_LSB_TAG 1001 EMACS_UINT u = XLI (o);
996 ? u 1002 if (INTEGERP (o))
997 : (INTEGERP (o) ? u << VALBITS : u & VALMASK) + XTYPE (o)); 1003 {
998 return (emacs_value) p; 1004 uintptr_t i = (u << VALBITS) + XTYPE (o);
1005 return (emacs_value) i;
1006 }
1007 else
1008 {
1009 char *p = XLP (o);
1010 void *v = p - (u & ~VALMASK) + XTYPE (o);
1011 return v;
1012 }
999} 1013}
1000 1014
1001/* Convert O to an emacs_value. Allocate storage if needed; this can 1015/* Convert O to an emacs_value. Allocate storage if needed; this can