emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 53914a1: Use ‘const’ to clarify GC marking


From: Paul Eggert
Subject: [Emacs-diffs] master 53914a1: Use ‘const’ to clarify GC marking
Date: Tue, 19 Mar 2019 15:37:41 -0400 (EDT)

branch: master
commit 53914a10558a0a579bb30d95da93d677901bc4a9
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Use ‘const’ to clarify GC marking
    
    Add ‘const’ to make the GC marking code a bit clearer.
    This can also help the compiler in some cases, I think because
    GCC can now determine more often that the value of a static C
    variable can be cached when its address is now converted to
    ‘Lisp Object const *’ before escaping.
    * src/alloc.c (staticvec, mark_maybe_objects, mark_memory)
    (mark_stack, staticpro, mark_object_root_visitor)
    (garbage_collect_1):
    * src/pdumper.c (dump_ptr_referrer, dump_emacs_reloc_to_lv)
    (dump_emacs_reloc_to_emacs_ptr_raw, dump_root_visitor):
    * src/lisp.h (vcopy, struct gc_root_visitor):
    * src/sysdep.c (stack_overflow):
    * src/thread.c (mark_one_thread):
    * src/thread.h (struct thread_state):
    Use pointer-to-const instead of plain pointer in some
    GC-related places where either will do.
---
 src/alloc.c   | 30 ++++++++++++++----------------
 src/lisp.h    | 24 +++++++++++++-----------
 src/pdumper.c |  9 +++++----
 src/sysdep.c  |  4 ++--
 src/thread.c  |  2 +-
 src/thread.h  |  4 ++--
 6 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/src/alloc.c b/src/alloc.c
index 5244fb1..8fb514f 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -508,7 +508,7 @@ static struct mem_node *mem_find (void *);
    value if we might unexec; otherwise some compilers put it into
    BSS.  */
 
-Lisp_Object *staticvec[NSTATICS]
+Lisp_Object const *staticvec[NSTATICS]
 #ifdef HAVE_UNEXEC
 = {&Vpurify_flag}
 #endif
@@ -4829,9 +4829,9 @@ mark_maybe_object (Lisp_Object obj)
 }
 
 void
-mark_maybe_objects (Lisp_Object *array, ptrdiff_t nelts)
+mark_maybe_objects (Lisp_Object const *array, ptrdiff_t nelts)
 {
-  for (Lisp_Object *lim = array + nelts; array < lim; array++)
+  for (Lisp_Object const *lim = array + nelts; array < lim; array++)
     mark_maybe_object (*array);
 }
 
@@ -4943,15 +4943,15 @@ mark_maybe_pointer (void *p)
    or END+OFFSET..START.  */
 
 static void ATTRIBUTE_NO_SANITIZE_ADDRESS
-mark_memory (void *start, void *end)
+mark_memory (void const *start, void const *end)
 {
-  char *pp;
+  char const *pp;
 
   /* Make START the pointer to the start of the memory region,
      if it isn't already.  */
   if (end < start)
     {
-      void *tem = start;
+      void const *tem = start;
       start = end;
       end = tem;
     }
@@ -4976,14 +4976,14 @@ mark_memory (void *start, void *end)
      away.  The only reference to the life string is through the
      pointer `s'.  */
 
-  for (pp = start; (void *) pp < end; pp += GC_POINTER_ALIGNMENT)
+  for (pp = start; (void const *) pp < end; pp += GC_POINTER_ALIGNMENT)
     {
-      mark_maybe_pointer (*(void **) pp);
+      mark_maybe_pointer (*(void *const *) pp);
 
       verify (alignof (Lisp_Object) % GC_POINTER_ALIGNMENT == 0);
       if (alignof (Lisp_Object) == GC_POINTER_ALIGNMENT
          || (uintptr_t) pp % alignof (Lisp_Object) == 0)
-       mark_maybe_object (*(Lisp_Object *) pp);
+       mark_maybe_object (*(Lisp_Object const *) pp);
     }
 }
 
@@ -5185,7 +5185,7 @@ typedef union
    from the stack start.  */
 
 void
-mark_stack (char *bottom, char *end)
+mark_stack (char const *bottom, char const *end)
 {
   /* This assumes that the stack is a contiguous region in memory.  If
      that's not the case, something has to be done here to iterate
@@ -5726,7 +5726,7 @@ purecopy (Lisp_Object obj)
    VARADDRESS.  */
 
 void
-staticpro (Lisp_Object *varaddress)
+staticpro (Lisp_Object const *varaddress)
 {
   for (int i = 0; i < staticidx; i++)
     eassert (staticvec[i] != varaddress);
@@ -5979,7 +5979,7 @@ visit_static_gc_roots (struct gc_root_visitor visitor)
 }
 
 static void
-mark_object_root_visitor (Lisp_Object *root_ptr,
+mark_object_root_visitor (Lisp_Object const *root_ptr,
                           enum gc_root_type type,
                           void *data)
 {
@@ -6074,7 +6074,7 @@ garbage_collect_1 (struct gcstat *gcst)
 #if MAX_SAVE_STACK > 0
   if (NILP (Vpurify_flag))
     {
-      char *stack;
+      char const *stack;
       ptrdiff_t stack_size;
       if (&stack_top_variable < stack_bottom)
        {
@@ -6110,9 +6110,7 @@ garbage_collect_1 (struct gcstat *gcst)
 
   /* Mark all the special slots that serve as the roots of accessibility.  */
 
-  struct gc_root_visitor visitor;
-  memset (&visitor, 0, sizeof (visitor));
-  visitor.visit = mark_object_root_visitor;
+  struct gc_root_visitor visitor = { .visit = mark_object_root_visitor };
   visit_static_gc_roots (visitor);
 
   mark_pinned_objects ();
diff --git a/src/lisp.h b/src/lisp.h
index cb142b9..8ec892f 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -631,7 +631,8 @@ extern _Noreturn void wrong_type_argument (Lisp_Object, 
Lisp_Object);
    subsequent starts.  */
 extern bool initialized;
 
-extern struct gflags {
+extern struct gflags
+{
   /* True means this Emacs instance was born to dump.  */
 #if defined HAVE_PDUMPER || defined HAVE_UNEXEC
   bool will_dump_ : 1;
@@ -3316,10 +3317,10 @@ extern Lisp_Object Vascii_canon_table;
 
 /* Call staticpro (&var) to protect static variable `var'.  */
 
-void staticpro (Lisp_Object *);
+void staticpro (Lisp_Object const *);
 
 enum { NSTATICS = 2048 };
-extern Lisp_Object *staticvec[NSTATICS];
+extern Lisp_Object const *staticvec[NSTATICS];
 extern int staticidx;
 
 
@@ -3341,7 +3342,8 @@ struct frame;
 /* Copy COUNT Lisp_Objects from ARGS to contents of V starting from OFFSET.  */
 
 INLINE void
-vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count)
+vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object const *args,
+       ptrdiff_t count)
 {
   eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v));
   memcpy (XVECTOR (v)->contents + offset, args, count * sizeof *args);
@@ -3771,8 +3773,8 @@ extern void refill_memory_reserve (void);
 #endif
 extern void alloc_unexec_pre (void);
 extern void alloc_unexec_post (void);
-extern void mark_maybe_objects (Lisp_Object *, ptrdiff_t);
-extern void mark_stack (char *, char *);
+extern void mark_maybe_objects (Lisp_Object const *, ptrdiff_t);
+extern void mark_stack (char const *, char const *);
 extern void flush_stack_call_func (void (*func) (void *arg), void *arg);
 extern void garbage_collect (void);
 extern const char *pending_malloc_warning;
@@ -3800,17 +3802,17 @@ extern Lisp_Object pure_listn (ptrdiff_t, Lisp_Object, 
...);
 #define pure_list(...) \
   pure_listn (ARRAYELTS (((Lisp_Object []) {__VA_ARGS__})), __VA_ARGS__)
 
-enum gc_root_type {
+enum gc_root_type
+{
   GC_ROOT_STATICPRO,
   GC_ROOT_BUFFER_LOCAL_DEFAULT,
   GC_ROOT_BUFFER_LOCAL_NAME,
   GC_ROOT_C_SYMBOL
 };
 
-struct gc_root_visitor {
-  void (*visit)(Lisp_Object *root_ptr,
-                enum gc_root_type type,
-                void *data);
+struct gc_root_visitor
+{
+  void (*visit) (Lisp_Object const *, enum gc_root_type, void *);
   void *data;
 };
 extern void visit_static_gc_roots (struct gc_root_visitor visitor);
diff --git a/src/pdumper.c b/src/pdumper.c
index 92e1949..fbf17d1 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -674,7 +674,7 @@ DUMP_CLEAR_REFERRER (struct dump_context *ctx)
 }
 
 static Lisp_Object
-dump_ptr_referrer (const char *label, void *address)
+dump_ptr_referrer (const char *label, void const *address)
 {
   char buf[128];
   buf[0] = '\0';
@@ -1631,7 +1631,7 @@ dump_emacs_reloc_to_dump_ptr_raw (struct dump_context 
*ctx,
    automatically queues the value for dumping if necessary.  */
 static void
 dump_emacs_reloc_to_lv (struct dump_context *ctx,
-                        Lisp_Object *emacs_ptr,
+                       Lisp_Object const *emacs_ptr,
                         Lisp_Object value)
 {
   if (dump_object_self_representing_p (value))
@@ -1659,7 +1659,7 @@ dump_emacs_reloc_to_lv (struct dump_context *ctx,
    back into the Emacs image.  */
 static void
 dump_emacs_reloc_to_emacs_ptr_raw (struct dump_context *ctx, void *emacs_ptr,
-                                   void *target_emacs_ptr)
+                                  void const *target_emacs_ptr)
 {
   if (!ctx->flags.dump_object_contents)
     return;
@@ -1738,7 +1738,8 @@ dump_remember_fixup_ptr_raw (struct dump_context *ctx,
 }
 
 static void
-dump_root_visitor (Lisp_Object *root_ptr, enum gc_root_type type, void *data)
+dump_root_visitor (Lisp_Object const *root_ptr, enum gc_root_type type,
+                  void *data)
 {
   struct dump_context *ctx = data;
   Lisp_Object value = *root_ptr;
diff --git a/src/sysdep.c b/src/sysdep.c
index 6d85692..fe5a44e 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1850,8 +1850,8 @@ stack_overflow (siginfo_t *siginfo)
 
   /* The known top and bottom of the stack.  The actual stack may
      extend a bit beyond these boundaries.  */
-  char *bot = stack_bottom;
-  char *top = current_thread->stack_top;
+  char const *bot = stack_bottom;
+  char const *top = current_thread->stack_top;
 
   /* Log base 2 of the stack heuristic ratio.  This ratio is the size
      of the known stack divided by the size of the guard area past the
diff --git a/src/thread.c b/src/thread.c
index 33d1132..59e5b66 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -617,7 +617,7 @@ static void
 mark_one_thread (struct thread_state *thread)
 {
   /* Get the stack top now, in case mark_specpdl changes it.  */
-  void *stack_top = thread->stack_top;
+  void const *stack_top = thread->stack_top;
 
   mark_specpdl (thread->m_specpdl, thread->m_specpdl_ptr);
 
diff --git a/src/thread.h b/src/thread.h
index e46545b..cb7e60f 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -65,7 +65,7 @@ struct thread_state
   /* m_stack_bottom must be the first non-Lisp field.  */
   /* An address near the bottom of the stack.
      Tells GC how to save a copy of the stack.  */
-  char *m_stack_bottom;
+  char const *m_stack_bottom;
 #define stack_bottom (current_thread->m_stack_bottom)
 
   /* The address of an object near the C stack top, used to determine
@@ -75,7 +75,7 @@ struct thread_state
      error in Emacs.  If the C function F calls G which calls H which
      calls ... F, then at least one of the functions in the chain
      should set this to the address of a local variable.  */
-  void *stack_top;
+  void const *stack_top;
 
   struct catchtag *m_catchlist;
 #define catchlist (current_thread->m_catchlist)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]