>From a527e5ddab0a54ada101eac9ffbf35bd0a80539e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 7 Jun 2018 19:12:28 -0700 Subject: [PATCH 09/10] New type Lisp_Misc_Ptr This is a streamlined version of Lisp_Save_Value, which contains just a pointer, as that is all Lisp_Save_Values are used for any more. With the previous changes, these objects are not primarily used as save values, so just call them "Misc" rather than "Save". * src/alloc.c (make_misc_ptr): New function. (mark_object): Mark Lisp_Misc_Ptr too. * src/lisp.h (Lisp_Misc_Ptr): New constant. (struct Lisp_Misc_Ptr): New type. (make_mint_ptr, mint_ptrp, xmint_pointer): Use Lisp_Misc_Ptr, not Lisp_Save_Value. (union Lisp_Misc): Add Lisp_Misc_Ptr. * src/print.c (print_object): Print Lisp_Misc_Ptr. --- src/alloc.c | 13 +++++++++++++ src/font.h | 2 +- src/lisp.h | 30 +++++++++++++++++++++--------- src/print.c | 7 +++++++ src/w32font.c | 2 +- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index a68759feb5..62a3a1a09f 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3834,6 +3834,15 @@ free_save_value (Lisp_Object save) free_misc (save); } +Lisp_Object +make_misc_ptr (void *a) +{ + Lisp_Object val = allocate_misc (Lisp_Misc_Ptr); + struct Lisp_Misc_Ptr *p = XUNTAG (val, Lisp_Misc); + p->pointer = a; + return val; +} + /* Return a Lisp_Misc_Overlay object with specified START, END and PLIST. */ Lisp_Object @@ -6697,6 +6706,10 @@ mark_object (Lisp_Object arg) mark_save_value (XSAVE_VALUE (obj)); break; + case Lisp_Misc_Ptr: + XMISCANY (obj)->gcmarkbit = true; + break; + case Lisp_Misc_Overlay: mark_overlay (XOVERLAY (obj)); break; diff --git a/src/font.h b/src/font.h index 469431fee6..8c8eb9582a 100644 --- a/src/font.h +++ b/src/font.h @@ -613,7 +613,7 @@ struct font_driver (symbols). */ Lisp_Object (*list_family) (struct frame *f); - /* Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value). + /* Optional. Free FONT_EXTRA_INDEX field of FONT_ENTITY. */ void (*free_entity) (Lisp_Object font_entity); diff --git a/src/lisp.h b/src/lisp.h index a0211966f7..625d6f13f3 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -514,6 +514,7 @@ enum Lisp_Misc_Type Lisp_Misc_Overlay, Lisp_Misc_Save_Value, Lisp_Misc_Finalizer, + Lisp_Misc_Ptr, #ifdef HAVE_MODULES Lisp_Misc_User_Ptr, #endif @@ -540,10 +541,11 @@ enum Lisp_Fwd_Type First, there are already a couple of Lisp types that can be used if your new type does not need to be exposed to Lisp programs nor - displayed to users. These are Lisp_Save_Value, a Lisp_Misc + displayed to users. These are Lisp_Misc_Ptr, a Lisp_Misc subtype; and PVEC_OTHER, a kind of vectorlike object. The former - is suitable for temporarily stashing away pointers and integers in - a Lisp object. The latter is useful for vector-like Lisp objects + is suitable for stashing a pointer in a Lisp object; the pointer + might be to some low-level C object that contains auxiliary + information. The latter is useful for vector-like Lisp objects that need to be used as part of other objects, but which are never shown to users or Lisp code (search for PVEC_OTHER in xterm.c for an example). @@ -2502,12 +2504,20 @@ XSAVE_FUNCPOINTER (Lisp_Object obj, int n) return XSAVE_VALUE (obj)->data[n].funcpointer; } -extern Lisp_Object make_save_ptr (void *); +struct Lisp_Misc_Ptr + { + ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Ptr */ + bool_bf gcmarkbit : 1; + unsigned spacer : 15; + void *pointer; + }; + +extern Lisp_Object make_misc_ptr (void *); /* A mint_ptr object OBJ represents a pointer P. OBJ is preferably a Lisp integer I such that XINTPTR (i) == P, as this is more efficient. However, if P would be damaged by being tagged as an integer and - then untagged via XINTPTR, then OBJ is a Lisp_Save_Value with + then untagged via XINTPTR, then OBJ is a Lisp_Misc_Ptr with pointer component P. C code should never blindly accept a mint_ptr object from Lisp code, as that would allow Lisp code to coin pointers from integers and could lead to crashes. */ @@ -2516,14 +2526,13 @@ INLINE Lisp_Object make_mint_ptr (void *a) { Lisp_Object val = TAG_PTR (Lisp_Int0, a); - return INTEGERP (val) && XINTPTR (val) == a ? val : make_save_ptr (a); + return INTEGERP (val) && XINTPTR (val) == a ? val : make_misc_ptr (a); } INLINE bool mint_ptrp (Lisp_Object x) { - return (INTEGERP (x) - || (SAVE_VALUEP (x) && XSAVE_VALUE (x)->save_type == SAVE_POINTER)); + return INTEGERP (x) || (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Ptr); } INLINE void * @@ -2532,7 +2541,8 @@ xmint_pointer (Lisp_Object a) eassert (mint_ptrp (a)); if (INTEGERP (a)) return XINTPTR (a); - return XSAVE_POINTER (a, 0); + struct Lisp_Misc_Ptr *p = XUNTAG (a, Lisp_Misc); + return p->pointer; } /* Get and set the Nth saved integer. */ @@ -2619,6 +2629,7 @@ union Lisp_Misc struct Lisp_Overlay u_overlay; struct Lisp_Save_Value u_save_value; struct Lisp_Finalizer u_finalizer; + struct Lisp_Misc_Ptr u_misc_ptr; #ifdef HAVE_MODULES struct Lisp_User_Ptr u_user_ptr; #endif @@ -3856,6 +3867,7 @@ extern ptrdiff_t inhibit_garbage_collection (void); extern Lisp_Object make_save_int_int_int (ptrdiff_t, ptrdiff_t, ptrdiff_t); extern Lisp_Object make_save_obj_obj_obj_obj (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object); +extern Lisp_Object make_save_ptr (void *); extern Lisp_Object make_save_ptr_int (void *, ptrdiff_t); extern Lisp_Object make_save_ptr_ptr (void *, void *); extern Lisp_Object make_save_funcptr_ptr_obj (void (*) (void), void *, diff --git a/src/print.c b/src/print.c index 8394375220..a991f3ffa3 100644 --- a/src/print.c +++ b/src/print.c @@ -2167,6 +2167,13 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) print_c_string ("#", printcharfun); break; + case Lisp_Misc_Ptr: + { + int i = sprintf (buf, "#", xmint_pointer (obj)); + strout (buf, i, i, printcharfun); + } + break; + case Lisp_Misc_Save_Value: { int i; diff --git a/src/w32font.c b/src/w32font.c index 9cbc3ee14b..65409b92d2 100644 --- a/src/w32font.c +++ b/src/w32font.c @@ -718,7 +718,7 @@ w32font_draw (struct glyph_string *s, int from, int to, } /* w32 implementation of free_entity for font backend. - Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value). + Optional. Free FONT_EXTRA_INDEX field of FONT_ENTITY. static void w32font_free_entity (Lisp_Object entity); -- 2.17.1