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.
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
}
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);
}
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;
}
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);
}
}
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
VARADDRESS. */
void
-staticpro (Lisp_Object *varaddress)
+staticpro (Lisp_Object const *varaddress)
{
for (int i = 0; i < staticidx; i++)
eassert (staticvec[i] != varaddress);
}
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)
{
#if MAX_SAVE_STACK > 0
if (NILP (Vpurify_flag))
{
- char *stack;
+ char const *stack;
ptrdiff_t stack_size;
if (&stack_top_variable < stack_bottom)
{
/* 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 ();
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;
\f
/* 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;
\f
/* 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);
#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;
#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);
}
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';
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))
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;
}
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;
/* 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
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);
/* 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
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)