aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2019-03-19 12:37:13 -0700
committerPaul Eggert2019-03-19 12:37:36 -0700
commit53914a10558a0a579bb30d95da93d677901bc4a9 (patch)
tree7fc6c0c091b7d380fbfc9b7411b3b646eed59fde /src
parent3ed1621d843e057ad879fbed3605d32f55a065b9 (diff)
downloademacs-53914a10558a0a579bb30d95da93d677901bc4a9.tar.gz
emacs-53914a10558a0a579bb30d95da93d677901bc4a9.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c30
-rw-r--r--src/lisp.h24
-rw-r--r--src/pdumper.c9
-rw-r--r--src/sysdep.c4
-rw-r--r--src/thread.c2
-rw-r--r--src/thread.h4
6 files changed, 37 insertions, 36 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 5244fb190fe..8fb514f78fb 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -508,7 +508,7 @@ static struct mem_node *mem_find (void *);
508 value if we might unexec; otherwise some compilers put it into 508 value if we might unexec; otherwise some compilers put it into
509 BSS. */ 509 BSS. */
510 510
511Lisp_Object *staticvec[NSTATICS] 511Lisp_Object const *staticvec[NSTATICS]
512#ifdef HAVE_UNEXEC 512#ifdef HAVE_UNEXEC
513= {&Vpurify_flag} 513= {&Vpurify_flag}
514#endif 514#endif
@@ -4829,9 +4829,9 @@ mark_maybe_object (Lisp_Object obj)
4829} 4829}
4830 4830
4831void 4831void
4832mark_maybe_objects (Lisp_Object *array, ptrdiff_t nelts) 4832mark_maybe_objects (Lisp_Object const *array, ptrdiff_t nelts)
4833{ 4833{
4834 for (Lisp_Object *lim = array + nelts; array < lim; array++) 4834 for (Lisp_Object const *lim = array + nelts; array < lim; array++)
4835 mark_maybe_object (*array); 4835 mark_maybe_object (*array);
4836} 4836}
4837 4837
@@ -4943,15 +4943,15 @@ mark_maybe_pointer (void *p)
4943 or END+OFFSET..START. */ 4943 or END+OFFSET..START. */
4944 4944
4945static void ATTRIBUTE_NO_SANITIZE_ADDRESS 4945static void ATTRIBUTE_NO_SANITIZE_ADDRESS
4946mark_memory (void *start, void *end) 4946mark_memory (void const *start, void const *end)
4947{ 4947{
4948 char *pp; 4948 char const *pp;
4949 4949
4950 /* Make START the pointer to the start of the memory region, 4950 /* Make START the pointer to the start of the memory region,
4951 if it isn't already. */ 4951 if it isn't already. */
4952 if (end < start) 4952 if (end < start)
4953 { 4953 {
4954 void *tem = start; 4954 void const *tem = start;
4955 start = end; 4955 start = end;
4956 end = tem; 4956 end = tem;
4957 } 4957 }
@@ -4976,14 +4976,14 @@ mark_memory (void *start, void *end)
4976 away. The only reference to the life string is through the 4976 away. The only reference to the life string is through the
4977 pointer `s'. */ 4977 pointer `s'. */
4978 4978
4979 for (pp = start; (void *) pp < end; pp += GC_POINTER_ALIGNMENT) 4979 for (pp = start; (void const *) pp < end; pp += GC_POINTER_ALIGNMENT)
4980 { 4980 {
4981 mark_maybe_pointer (*(void **) pp); 4981 mark_maybe_pointer (*(void *const *) pp);
4982 4982
4983 verify (alignof (Lisp_Object) % GC_POINTER_ALIGNMENT == 0); 4983 verify (alignof (Lisp_Object) % GC_POINTER_ALIGNMENT == 0);
4984 if (alignof (Lisp_Object) == GC_POINTER_ALIGNMENT 4984 if (alignof (Lisp_Object) == GC_POINTER_ALIGNMENT
4985 || (uintptr_t) pp % alignof (Lisp_Object) == 0) 4985 || (uintptr_t) pp % alignof (Lisp_Object) == 0)
4986 mark_maybe_object (*(Lisp_Object *) pp); 4986 mark_maybe_object (*(Lisp_Object const *) pp);
4987 } 4987 }
4988} 4988}
4989 4989
@@ -5185,7 +5185,7 @@ typedef union
5185 from the stack start. */ 5185 from the stack start. */
5186 5186
5187void 5187void
5188mark_stack (char *bottom, char *end) 5188mark_stack (char const *bottom, char const *end)
5189{ 5189{
5190 /* This assumes that the stack is a contiguous region in memory. If 5190 /* This assumes that the stack is a contiguous region in memory. If
5191 that's not the case, something has to be done here to iterate 5191 that's not the case, something has to be done here to iterate
@@ -5726,7 +5726,7 @@ purecopy (Lisp_Object obj)
5726 VARADDRESS. */ 5726 VARADDRESS. */
5727 5727
5728void 5728void
5729staticpro (Lisp_Object *varaddress) 5729staticpro (Lisp_Object const *varaddress)
5730{ 5730{
5731 for (int i = 0; i < staticidx; i++) 5731 for (int i = 0; i < staticidx; i++)
5732 eassert (staticvec[i] != varaddress); 5732 eassert (staticvec[i] != varaddress);
@@ -5979,7 +5979,7 @@ visit_static_gc_roots (struct gc_root_visitor visitor)
5979} 5979}
5980 5980
5981static void 5981static void
5982mark_object_root_visitor (Lisp_Object *root_ptr, 5982mark_object_root_visitor (Lisp_Object const *root_ptr,
5983 enum gc_root_type type, 5983 enum gc_root_type type,
5984 void *data) 5984 void *data)
5985{ 5985{
@@ -6074,7 +6074,7 @@ garbage_collect_1 (struct gcstat *gcst)
6074#if MAX_SAVE_STACK > 0 6074#if MAX_SAVE_STACK > 0
6075 if (NILP (Vpurify_flag)) 6075 if (NILP (Vpurify_flag))
6076 { 6076 {
6077 char *stack; 6077 char const *stack;
6078 ptrdiff_t stack_size; 6078 ptrdiff_t stack_size;
6079 if (&stack_top_variable < stack_bottom) 6079 if (&stack_top_variable < stack_bottom)
6080 { 6080 {
@@ -6110,9 +6110,7 @@ garbage_collect_1 (struct gcstat *gcst)
6110 6110
6111 /* Mark all the special slots that serve as the roots of accessibility. */ 6111 /* Mark all the special slots that serve as the roots of accessibility. */
6112 6112
6113 struct gc_root_visitor visitor; 6113 struct gc_root_visitor visitor = { .visit = mark_object_root_visitor };
6114 memset (&visitor, 0, sizeof (visitor));
6115 visitor.visit = mark_object_root_visitor;
6116 visit_static_gc_roots (visitor); 6114 visit_static_gc_roots (visitor);
6117 6115
6118 mark_pinned_objects (); 6116 mark_pinned_objects ();
diff --git a/src/lisp.h b/src/lisp.h
index cb142b9d8ad..8ec892f17b9 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -631,7 +631,8 @@ extern _Noreturn void wrong_type_argument (Lisp_Object, Lisp_Object);
631 subsequent starts. */ 631 subsequent starts. */
632extern bool initialized; 632extern bool initialized;
633 633
634extern struct gflags { 634extern struct gflags
635{
635 /* True means this Emacs instance was born to dump. */ 636 /* True means this Emacs instance was born to dump. */
636#if defined HAVE_PDUMPER || defined HAVE_UNEXEC 637#if defined HAVE_PDUMPER || defined HAVE_UNEXEC
637 bool will_dump_ : 1; 638 bool will_dump_ : 1;
@@ -3316,10 +3317,10 @@ extern Lisp_Object Vascii_canon_table;
3316 3317
3317/* Call staticpro (&var) to protect static variable `var'. */ 3318/* Call staticpro (&var) to protect static variable `var'. */
3318 3319
3319void staticpro (Lisp_Object *); 3320void staticpro (Lisp_Object const *);
3320 3321
3321enum { NSTATICS = 2048 }; 3322enum { NSTATICS = 2048 };
3322extern Lisp_Object *staticvec[NSTATICS]; 3323extern Lisp_Object const *staticvec[NSTATICS];
3323extern int staticidx; 3324extern int staticidx;
3324 3325
3325 3326
@@ -3341,7 +3342,8 @@ struct frame;
3341/* Copy COUNT Lisp_Objects from ARGS to contents of V starting from OFFSET. */ 3342/* Copy COUNT Lisp_Objects from ARGS to contents of V starting from OFFSET. */
3342 3343
3343INLINE void 3344INLINE void
3344vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count) 3345vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object const *args,
3346 ptrdiff_t count)
3345{ 3347{
3346 eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v)); 3348 eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v));
3347 memcpy (XVECTOR (v)->contents + offset, args, count * sizeof *args); 3349 memcpy (XVECTOR (v)->contents + offset, args, count * sizeof *args);
@@ -3771,8 +3773,8 @@ extern void refill_memory_reserve (void);
3771#endif 3773#endif
3772extern void alloc_unexec_pre (void); 3774extern void alloc_unexec_pre (void);
3773extern void alloc_unexec_post (void); 3775extern void alloc_unexec_post (void);
3774extern void mark_maybe_objects (Lisp_Object *, ptrdiff_t); 3776extern void mark_maybe_objects (Lisp_Object const *, ptrdiff_t);
3775extern void mark_stack (char *, char *); 3777extern void mark_stack (char const *, char const *);
3776extern void flush_stack_call_func (void (*func) (void *arg), void *arg); 3778extern void flush_stack_call_func (void (*func) (void *arg), void *arg);
3777extern void garbage_collect (void); 3779extern void garbage_collect (void);
3778extern const char *pending_malloc_warning; 3780extern const char *pending_malloc_warning;
@@ -3800,17 +3802,17 @@ extern Lisp_Object pure_listn (ptrdiff_t, Lisp_Object, ...);
3800#define pure_list(...) \ 3802#define pure_list(...) \
3801 pure_listn (ARRAYELTS (((Lisp_Object []) {__VA_ARGS__})), __VA_ARGS__) 3803 pure_listn (ARRAYELTS (((Lisp_Object []) {__VA_ARGS__})), __VA_ARGS__)
3802 3804
3803enum gc_root_type { 3805enum gc_root_type
3806{
3804 GC_ROOT_STATICPRO, 3807 GC_ROOT_STATICPRO,
3805 GC_ROOT_BUFFER_LOCAL_DEFAULT, 3808 GC_ROOT_BUFFER_LOCAL_DEFAULT,
3806 GC_ROOT_BUFFER_LOCAL_NAME, 3809 GC_ROOT_BUFFER_LOCAL_NAME,
3807 GC_ROOT_C_SYMBOL 3810 GC_ROOT_C_SYMBOL
3808}; 3811};
3809 3812
3810struct gc_root_visitor { 3813struct gc_root_visitor
3811 void (*visit)(Lisp_Object *root_ptr, 3814{
3812 enum gc_root_type type, 3815 void (*visit) (Lisp_Object const *, enum gc_root_type, void *);
3813 void *data);
3814 void *data; 3816 void *data;
3815}; 3817};
3816extern void visit_static_gc_roots (struct gc_root_visitor visitor); 3818extern void visit_static_gc_roots (struct gc_root_visitor visitor);
diff --git a/src/pdumper.c b/src/pdumper.c
index 92e19497e59..fbf17d1629e 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -674,7 +674,7 @@ DUMP_CLEAR_REFERRER (struct dump_context *ctx)
674} 674}
675 675
676static Lisp_Object 676static Lisp_Object
677dump_ptr_referrer (const char *label, void *address) 677dump_ptr_referrer (const char *label, void const *address)
678{ 678{
679 char buf[128]; 679 char buf[128];
680 buf[0] = '\0'; 680 buf[0] = '\0';
@@ -1631,7 +1631,7 @@ dump_emacs_reloc_to_dump_ptr_raw (struct dump_context *ctx,
1631 automatically queues the value for dumping if necessary. */ 1631 automatically queues the value for dumping if necessary. */
1632static void 1632static void
1633dump_emacs_reloc_to_lv (struct dump_context *ctx, 1633dump_emacs_reloc_to_lv (struct dump_context *ctx,
1634 Lisp_Object *emacs_ptr, 1634 Lisp_Object const *emacs_ptr,
1635 Lisp_Object value) 1635 Lisp_Object value)
1636{ 1636{
1637 if (dump_object_self_representing_p (value)) 1637 if (dump_object_self_representing_p (value))
@@ -1659,7 +1659,7 @@ dump_emacs_reloc_to_lv (struct dump_context *ctx,
1659 back into the Emacs image. */ 1659 back into the Emacs image. */
1660static void 1660static void
1661dump_emacs_reloc_to_emacs_ptr_raw (struct dump_context *ctx, void *emacs_ptr, 1661dump_emacs_reloc_to_emacs_ptr_raw (struct dump_context *ctx, void *emacs_ptr,
1662 void *target_emacs_ptr) 1662 void const *target_emacs_ptr)
1663{ 1663{
1664 if (!ctx->flags.dump_object_contents) 1664 if (!ctx->flags.dump_object_contents)
1665 return; 1665 return;
@@ -1738,7 +1738,8 @@ dump_remember_fixup_ptr_raw (struct dump_context *ctx,
1738} 1738}
1739 1739
1740static void 1740static void
1741dump_root_visitor (Lisp_Object *root_ptr, enum gc_root_type type, void *data) 1741dump_root_visitor (Lisp_Object const *root_ptr, enum gc_root_type type,
1742 void *data)
1742{ 1743{
1743 struct dump_context *ctx = data; 1744 struct dump_context *ctx = data;
1744 Lisp_Object value = *root_ptr; 1745 Lisp_Object value = *root_ptr;
diff --git a/src/sysdep.c b/src/sysdep.c
index 6d85692ab11..fe5a44ea2da 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1850,8 +1850,8 @@ stack_overflow (siginfo_t *siginfo)
1850 1850
1851 /* The known top and bottom of the stack. The actual stack may 1851 /* The known top and bottom of the stack. The actual stack may
1852 extend a bit beyond these boundaries. */ 1852 extend a bit beyond these boundaries. */
1853 char *bot = stack_bottom; 1853 char const *bot = stack_bottom;
1854 char *top = current_thread->stack_top; 1854 char const *top = current_thread->stack_top;
1855 1855
1856 /* Log base 2 of the stack heuristic ratio. This ratio is the size 1856 /* Log base 2 of the stack heuristic ratio. This ratio is the size
1857 of the known stack divided by the size of the guard area past the 1857 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 33d113295ba..59e5b6617e3 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -617,7 +617,7 @@ static void
617mark_one_thread (struct thread_state *thread) 617mark_one_thread (struct thread_state *thread)
618{ 618{
619 /* Get the stack top now, in case mark_specpdl changes it. */ 619 /* Get the stack top now, in case mark_specpdl changes it. */
620 void *stack_top = thread->stack_top; 620 void const *stack_top = thread->stack_top;
621 621
622 mark_specpdl (thread->m_specpdl, thread->m_specpdl_ptr); 622 mark_specpdl (thread->m_specpdl, thread->m_specpdl_ptr);
623 623
diff --git a/src/thread.h b/src/thread.h
index e46545baf27..cb7e60f21f8 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -65,7 +65,7 @@ struct thread_state
65 /* m_stack_bottom must be the first non-Lisp field. */ 65 /* m_stack_bottom must be the first non-Lisp field. */
66 /* An address near the bottom of the stack. 66 /* An address near the bottom of the stack.
67 Tells GC how to save a copy of the stack. */ 67 Tells GC how to save a copy of the stack. */
68 char *m_stack_bottom; 68 char const *m_stack_bottom;
69#define stack_bottom (current_thread->m_stack_bottom) 69#define stack_bottom (current_thread->m_stack_bottom)
70 70
71 /* The address of an object near the C stack top, used to determine 71 /* The address of an object near the C stack top, used to determine
@@ -75,7 +75,7 @@ struct thread_state
75 error in Emacs. If the C function F calls G which calls H which 75 error in Emacs. If the C function F calls G which calls H which
76 calls ... F, then at least one of the functions in the chain 76 calls ... F, then at least one of the functions in the chain
77 should set this to the address of a local variable. */ 77 should set this to the address of a local variable. */
78 void *stack_top; 78 void const *stack_top;
79 79
80 struct catchtag *m_catchlist; 80 struct catchtag *m_catchlist;
81#define catchlist (current_thread->m_catchlist) 81#define catchlist (current_thread->m_catchlist)