diff options
| author | Paul Eggert | 2019-03-19 12:37:13 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-03-19 12:37:36 -0700 |
| commit | 53914a10558a0a579bb30d95da93d677901bc4a9 (patch) | |
| tree | 7fc6c0c091b7d380fbfc9b7411b3b646eed59fde /src/alloc.c | |
| parent | 3ed1621d843e057ad879fbed3605d32f55a065b9 (diff) | |
| download | emacs-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/alloc.c')
| -rw-r--r-- | src/alloc.c | 30 |
1 files changed, 14 insertions, 16 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 | ||
| 511 | Lisp_Object *staticvec[NSTATICS] | 511 | Lisp_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 | ||
| 4831 | void | 4831 | void |
| 4832 | mark_maybe_objects (Lisp_Object *array, ptrdiff_t nelts) | 4832 | mark_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 | ||
| 4945 | static void ATTRIBUTE_NO_SANITIZE_ADDRESS | 4945 | static void ATTRIBUTE_NO_SANITIZE_ADDRESS |
| 4946 | mark_memory (void *start, void *end) | 4946 | mark_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 | ||
| 5187 | void | 5187 | void |
| 5188 | mark_stack (char *bottom, char *end) | 5188 | mark_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 | ||
| 5728 | void | 5728 | void |
| 5729 | staticpro (Lisp_Object *varaddress) | 5729 | staticpro (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 | ||
| 5981 | static void | 5981 | static void |
| 5982 | mark_object_root_visitor (Lisp_Object *root_ptr, | 5982 | mark_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 (); |