Commit d9b300af authored by Paul Eggert's avatar Paul Eggert
Browse files

Omit ‘const’ on locals

Remove ‘const’ qualifier from locals that were newly added.
We don’t normally bother declaring locals with ‘const’ even
though they are not modified, for the same reason we don’t
bother declaring them with ‘register’ even though their
addresses are not taken; the advantage in compile-time
checking isn’t worth the loss of readability.
* modules/mod-test/mod-test.c (Fmod_test_non_local_exit_funcall)
(Fmod_test_vector_fill, Fmod_test_vector_eq):
* src/emacs-module.c (MODULE_SETJMP_1)
(module_make_global_ref, module_free_global_ref)
(module_non_local_exit_get, module_make_function)
(module_extract_integer, module_extract_float)
(module_get_user_ptr, module_set_user_ptr)
(module_get_user_finalizer, module_set_user_finalizer)
(module_vec_get, Fmodule_call)
(module_non_local_exit_signal_1)
(module_non_local_exit_throw_1, lisp_to_value)
(finalize_storage, allocate_emacs_value, mark_modules)
(module_handle_signal, module_handle_throw)
(module_format_fun_env):
* src/eval.c (push_handler, push_handler_nosignal)
(init_handler):
* src/lread.c (suffix_p):
Omit unnecessary ‘const’.
parent 68d58e69
......@@ -78,7 +78,7 @@ Fmod_test_non_local_exit_funcall (emacs_env *env, int nargs, emacs_value args[],
void *data)
{
assert (nargs == 1);
const emacs_value result = env->funcall (env, args[0], 0, NULL);
emacs_value result = env->funcall (env, args[0], 0, NULL);
emacs_value non_local_exit_symbol, non_local_exit_data;
enum emacs_funcall_exit code
= env->non_local_exit_get (env, &non_local_exit_symbol,
......@@ -90,7 +90,7 @@ Fmod_test_non_local_exit_funcall (emacs_env *env, int nargs, emacs_value args[],
case emacs_funcall_exit_signal:
{
env->non_local_exit_clear (env);
const emacs_value Flist = env->intern (env, "list");
emacs_value Flist = env->intern (env, "list");
emacs_value list_args[] = {env->intern (env, "signal"),
non_local_exit_symbol, non_local_exit_data};
return env->funcall (env, Flist, 3, list_args);
......@@ -98,7 +98,7 @@ Fmod_test_non_local_exit_funcall (emacs_env *env, int nargs, emacs_value args[],
case emacs_funcall_exit_throw:
{
env->non_local_exit_clear (env);
const emacs_value Flist = env->intern (env, "list");
emacs_value Flist = env->intern (env, "list");
emacs_value list_args[] = {env->intern (env, "throw"),
non_local_exit_symbol, non_local_exit_data};
return env->funcall (env, Flist, 3, list_args);
......@@ -191,7 +191,7 @@ Fmod_test_vector_fill (emacs_env *env, int nargs, emacs_value args[], void *data
{
emacs_value vec = args[0];
emacs_value val = args[1];
const size_t size = env->vec_size (env, vec);
size_t size = env->vec_size (env, vec);
for (size_t i = 0; i < size; i++)
env->vec_set (env, vec, i, val);
return env->intern (env, "t");
......@@ -205,7 +205,7 @@ Fmod_test_vector_eq (emacs_env *env, int nargs, emacs_value args[], void *data)
{
emacs_value vec = args[0];
emacs_value val = args[1];
const size_t size = env->vec_size (env, vec);
size_t size = env->vec_size (env, vec);
for (size_t i = 0; i < size; i++)
if (!env->eq (env, env->vec_get (env, vec, i), val))
return env->intern (env, "nil");
......
......@@ -141,7 +141,7 @@ static void check_main_thread (void);
static void finalize_environment (struct env_storage *);
static void initialize_environment (struct env_storage *);
static void module_args_out_of_range (emacs_env *, Lisp_Object, Lisp_Object);
static void module_handle_signal (emacs_env *, const Lisp_Object);
static void module_handle_signal (emacs_env *, Lisp_Object);
static void module_handle_throw (emacs_env *, Lisp_Object);
static void module_non_local_exit_signal_1 (emacs_env *, Lisp_Object, Lisp_Object);
static void module_non_local_exit_throw_1 (emacs_env *, Lisp_Object, Lisp_Object);
......@@ -201,7 +201,7 @@ static void module_wrong_type (emacs_env *, Lisp_Object, Lisp_Object);
return retval; \
} \
verify (module_has_cleanup); \
const int dummy __attribute__ ((cleanup (module_reset_handlerlist))); \
int dummy __attribute__ ((cleanup (module_reset_handlerlist))); \
if (sys_setjmp (c->jmp)) \
{ \
(handlerfunc) (env, c->val); \
......@@ -263,7 +263,7 @@ module_make_global_ref (emacs_env *env, emacs_value ref)
{
Lisp_Object value = HASH_VALUE (h, i);
eassert (NATNUMP (value));
const EMACS_UINT refcount = XFASTINT (value);
EMACS_UINT refcount = XFASTINT (value);
if (refcount >= MOST_POSITIVE_FIXNUM)
{
module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
......@@ -297,7 +297,7 @@ module_free_global_ref (emacs_env *env, emacs_value ref)
{
Lisp_Object value = HASH_VALUE (h, i);
eassert (NATNUMP (value));
const EMACS_UINT refcount = XFASTINT (value);
EMACS_UINT refcount = XFASTINT (value);
eassert (refcount > 0);
if (refcount > 1)
{
......@@ -329,7 +329,7 @@ static enum emacs_funcall_exit
module_non_local_exit_get (emacs_env *env, emacs_value *sym, emacs_value *data)
{
check_main_thread ();
struct emacs_env_private *const p = env->private_members;
struct emacs_env_private *p = env->private_members;
if (p->pending_non_local_exit != emacs_funcall_exit_return)
{
*sym = &p->non_local_exit_symbol;
......@@ -366,7 +366,7 @@ module_non_local_exit_throw (emacs_env *env, emacs_value tag, emacs_value value)
static emacs_value
module_make_function (emacs_env *env, int min_arity, int max_arity,
emacs_subr subr, const char *const documentation,
emacs_subr subr, const char *documentation,
void *data)
{
check_main_thread ();
......@@ -456,7 +456,7 @@ module_extract_integer (emacs_env *env, emacs_value n)
{
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
const Lisp_Object l = value_to_lisp (n);
Lisp_Object l = value_to_lisp (n);
if (! INTEGERP (l))
{
module_wrong_type (env, Qintegerp, l);
......@@ -483,7 +483,7 @@ module_extract_float (emacs_env *env, emacs_value f)
{
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
const Lisp_Object lisp = value_to_lisp (f);
Lisp_Object lisp = value_to_lisp (f);
if (! FLOATP (lisp))
{
module_wrong_type (env, Qfloatp, lisp);
......@@ -562,7 +562,7 @@ module_get_user_ptr (emacs_env *env, emacs_value uptr)
{
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
const Lisp_Object lisp = value_to_lisp (uptr);
Lisp_Object lisp = value_to_lisp (uptr);
if (! USER_PTRP (lisp))
{
module_wrong_type (env, Quser_ptr, lisp);
......@@ -576,8 +576,9 @@ module_set_user_ptr (emacs_env *env, emacs_value uptr, void *ptr)
{
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
const Lisp_Object lisp = value_to_lisp (uptr);
if (! USER_PTRP (lisp)) module_wrong_type (env, Quser_ptr, lisp);
Lisp_Object lisp = value_to_lisp (uptr);
if (! USER_PTRP (lisp))
module_wrong_type (env, Quser_ptr, lisp);
XUSER_PTR (lisp)->p = ptr;
}
......@@ -586,7 +587,7 @@ module_get_user_finalizer (emacs_env *env, emacs_value uptr)
{
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
const Lisp_Object lisp = value_to_lisp (uptr);
Lisp_Object lisp = value_to_lisp (uptr);
if (! USER_PTRP (lisp))
{
module_wrong_type (env, Quser_ptr, lisp);
......@@ -601,8 +602,9 @@ module_set_user_finalizer (emacs_env *env, emacs_value uptr,
{
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
const Lisp_Object lisp = value_to_lisp (uptr);
if (! USER_PTRP (lisp)) module_wrong_type (env, Quser_ptr, lisp);
Lisp_Object lisp = value_to_lisp (uptr);
if (! USER_PTRP (lisp))
module_wrong_type (env, Quser_ptr, lisp);
XUSER_PTR (lisp)->finalizer = fin;
}
......@@ -649,7 +651,7 @@ module_vec_get (emacs_env *env, emacs_value vec, size_t i)
return NULL;
}
/* Prevent error-prone comparison between types of different signedness. */
const size_t size = ASIZE (lvec);
size_t size = ASIZE (lvec);
eassert (size >= 0);
if (i >= size)
{
......@@ -734,8 +736,8 @@ ENVOBJ is a save pointer to a module_fun_env structure.
ARGLIST is a list of arguments passed to SUBRPTR. */)
(Lisp_Object envobj, Lisp_Object arglist)
{
const struct module_fun_env *const envptr = XSAVE_POINTER (envobj, 0);
const EMACS_INT len = XINT (Flength (arglist));
struct module_fun_env *envptr = XSAVE_POINTER (envobj, 0);
EMACS_INT len = XINT (Flength (arglist));
eassert (len >= 0);
if (len > MOST_POSITIVE_FIXNUM)
xsignal0 (Qoverflow_error);
......@@ -771,14 +773,14 @@ ARGLIST is a list of arguments passed to SUBRPTR. */)
case emacs_funcall_exit_signal:
{
Lisp_Object symbol = value_to_lisp (&env.priv.non_local_exit_symbol);
const Lisp_Object data = value_to_lisp (&env.priv.non_local_exit_data);
Lisp_Object data = value_to_lisp (&env.priv.non_local_exit_data);
finalize_environment (&env);
xsignal (symbol, data);
}
case emacs_funcall_exit_throw:
{
const Lisp_Object tag = value_to_lisp (&env.priv.non_local_exit_symbol);
const Lisp_Object value = value_to_lisp (&env.priv.non_local_exit_data);
Lisp_Object tag = value_to_lisp (&env.priv.non_local_exit_symbol);
Lisp_Object value = value_to_lisp (&env.priv.non_local_exit_data);
finalize_environment (&env);
Fthrow (tag, value);
}
......@@ -810,7 +812,7 @@ static void
module_non_local_exit_signal_1 (emacs_env *env, Lisp_Object sym,
Lisp_Object data)
{
struct emacs_env_private *const p = env->private_members;
struct emacs_env_private *p = env->private_members;
eassert (p->pending_non_local_exit == emacs_funcall_exit_return);
p->pending_non_local_exit = emacs_funcall_exit_signal;
p->non_local_exit_symbol.v = sym;
......@@ -821,7 +823,7 @@ static void
module_non_local_exit_throw_1 (emacs_env *env, Lisp_Object tag,
Lisp_Object value)
{
struct emacs_env_private *const p = env->private_members;
struct emacs_env_private *p = env->private_members;
eassert (p->pending_non_local_exit == emacs_funcall_exit_return);
p->pending_non_local_exit = emacs_funcall_exit_throw;
p->non_local_exit_symbol.v = tag;
......@@ -869,7 +871,7 @@ value_to_lisp (emacs_value v)
static emacs_value
lisp_to_value (emacs_env *env, Lisp_Object o)
{
struct emacs_env_private *const p = env->private_members;
struct emacs_env_private *p = env->private_members;
if (p->pending_non_local_exit != emacs_funcall_exit_return)
return NULL;
return allocate_emacs_value (env, &p->storage, o);
......@@ -903,7 +905,7 @@ finalize_storage (struct emacs_value_storage *storage)
struct emacs_value_frame *next = storage->initial.next;
while (next != NULL)
{
struct emacs_value_frame *const current = next;
struct emacs_value_frame *current = next;
next = current->next;
free (current);
}
......@@ -929,7 +931,7 @@ allocate_emacs_value (emacs_env *env, struct emacs_value_storage *storage,
initialize_frame (storage->current->next);
storage->current = storage->current->next;
}
const emacs_value value = storage->current->objects + storage->current->offset;
emacs_value value = storage->current->objects + storage->current->offset;
value->v = obj;
++storage->current->offset;
return value;
......@@ -941,8 +943,8 @@ void mark_modules (void)
{
for (Lisp_Object tem = Vmodule_environments; CONSP (tem); tem = XCDR (tem))
{
const struct env_storage *const env = XSAVE_POINTER (tem, 0);
for (const struct emacs_value_frame *frame = &env->priv.storage.initial;
struct env_storage *env = XSAVE_POINTER (tem, 0);
for (struct emacs_value_frame *frame = &env->priv.storage.initial;
frame != NULL;
frame = frame->next)
for (size_t i = 0; i < frame->offset; ++i)
......@@ -1016,7 +1018,7 @@ module_reset_handlerlist (const int *dummy)
/* Called on `signal'. ERR is a pair (SYMBOL . DATA), which gets
stored in the environment. Set the pending non-local exit flag. */
static void
module_handle_signal (emacs_env *const env, const Lisp_Object err)
module_handle_signal (emacs_env *env, Lisp_Object err)
{
module_non_local_exit_signal_1 (env, XCAR (err), XCDR (err));
}
......@@ -1024,7 +1026,7 @@ module_handle_signal (emacs_env *const env, const Lisp_Object err)
/* Called on `throw'. TAG_VAL is a pair (TAG . VALUE), which gets
stored in the environment. Set the pending non-local exit flag. */
static void
module_handle_throw (emacs_env *const env, const Lisp_Object tag_val)
module_handle_throw (emacs_env *env, Lisp_Object tag_val)
{
module_non_local_exit_throw_1 (env, XCAR (tag_val), XCDR (tag_val));
}
......@@ -1035,14 +1037,14 @@ module_handle_throw (emacs_env *const env, const Lisp_Object tag_val)
/* Return a string object that contains a user-friendly
representation of the function environment. */
static Lisp_Object
module_format_fun_env (const struct module_fun_env *const env)
module_format_fun_env (const struct module_fun_env *env)
{
/* Try to print a function name if possible. */
const char *path, *sym;
if (dynlib_addr (env->subr, &path, &sym))
{
const char *const format = "#<module function %s from %s>";
const int size = snprintf (NULL, 0, format, sym, path);
static char const format[] = "#<module function %s from %s>";
int size = snprintf (NULL, 0, format, sym, path);
eassert (size > 0);
char buffer[size + 1];
snprintf (buffer, sizeof buffer, format, sym, path);
......@@ -1050,9 +1052,9 @@ module_format_fun_env (const struct module_fun_env *const env)
}
else
{
const char *const format = "#<module function at %p>";
const void *const subr = env->subr;
const int size = snprintf (NULL, 0, format, subr);
static char const format[] = "#<module function at %p>";
void *subr = env->subr;
int size = snprintf (NULL, 0, format, subr);
eassert (size > 0);
char buffer[size + 1];
snprintf (buffer, sizeof buffer, format, subr);
......
......@@ -1399,8 +1399,9 @@ internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
static void init_handler (struct handler *c, Lisp_Object tag_ch_val,
enum handlertype handlertype);
void push_handler (struct handler **const c, const Lisp_Object tag_ch_val,
const enum handlertype handlertype)
void
push_handler (struct handler **c, Lisp_Object tag_ch_val,
enum handlertype handlertype)
{
if (handlerlist->nextfree)
*c = handlerlist->nextfree;
......@@ -1413,14 +1414,15 @@ void push_handler (struct handler **const c, const Lisp_Object tag_ch_val,
init_handler (*c, tag_ch_val, handlertype);
}
bool push_handler_nosignal (struct handler **const c, const Lisp_Object tag_ch_val,
const enum handlertype handlertype)
bool
push_handler_nosignal (struct handler **c, Lisp_Object tag_ch_val,
enum handlertype handlertype)
{
if (handlerlist->nextfree)
*c = handlerlist->nextfree;
else
{
struct handler *const h = malloc (sizeof (struct handler));
struct handler *h = malloc (sizeof (struct handler));
if (! h) return false;
*c = h;
h->nextfree = NULL;
......@@ -1430,8 +1432,9 @@ bool push_handler_nosignal (struct handler **const c, const Lisp_Object tag_ch_v
return true;
}
static void init_handler (struct handler *const c, const Lisp_Object tag_ch_val,
const enum handlertype handlertype)
static void
init_handler (struct handler *c, Lisp_Object tag_ch_val,
enum handlertype handlertype)
{
c->type = handlertype;
c->tag_or_ch = tag_ch_val;
......
......@@ -979,8 +979,8 @@ This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */)
static bool
suffix_p (Lisp_Object string, const char *suffix)
{
const size_t suffix_len = strlen (suffix);
const size_t string_len = SBYTES (string);
size_t suffix_len = strlen (suffix);
size_t string_len = SBYTES (string);
return string_len >= suffix_len && !strcmp (SSDATA (string) + string_len - suffix_len, suffix);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment