summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/emacs-module.c46
-rw-r--r--src/emacs-module.h14
-rw-r--r--src/lread.c4
3 files changed, 26 insertions, 38 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c
index 166f6ddf93c..8992840307f 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -78,7 +78,7 @@ struct emacs_value_frame
struct emacs_value_tag objects[value_frame_size];
/* Index of the next free value in `objects'. */
- size_t offset;
+ int offset;
/* Pointer to next frame, if any. */
struct emacs_value_frame *next;
@@ -263,13 +263,13 @@ module_make_global_ref (emacs_env *env, emacs_value ref)
{
Lisp_Object value = HASH_VALUE (h, i);
eassert (NATNUMP (value));
- EMACS_UINT refcount = XFASTINT (value);
- if (refcount >= MOST_POSITIVE_FIXNUM)
+ EMACS_INT refcount = XFASTINT (value) + 1;
+ if (refcount > MOST_POSITIVE_FIXNUM)
{
module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
return NULL;
}
- XSETFASTINT (value, refcount + 1);
+ value = make_natnum (refcount);
set_hash_value_slot (h, i, value);
}
else
@@ -297,15 +297,15 @@ module_free_global_ref (emacs_env *env, emacs_value ref)
{
Lisp_Object value = HASH_VALUE (h, i);
eassert (NATNUMP (value));
- EMACS_UINT refcount = XFASTINT (value);
- eassert (refcount > 0);
- if (refcount > 1)
+ EMACS_INT refcount = XFASTINT (value) - 1;
+ if (refcount > 0)
{
- XSETFASTINT (value, refcount - 1);
+ value = make_natnum (refcount - 1);
set_hash_value_slot (h, i, value);
}
else
{
+ eassert (refcount == 0);
hash_remove_from_table (h, value);
}
}
@@ -503,7 +503,7 @@ module_make_float (emacs_env *env, double d)
static bool
module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
- size_t *length)
+ ptrdiff_t *length)
{
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
@@ -515,7 +515,7 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
return false;
}
- size_t raw_size = SBYTES (lisp_str);
+ ptrdiff_t raw_size = SBYTES (lisp_str);
/* Emacs internal encoding is more-or-less UTF8, let's assume utf8
encoded emacs string are the same byte size. */
@@ -536,7 +536,7 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
}
static emacs_value
-module_make_string (emacs_env *env, const char *str, size_t length)
+module_make_string (emacs_env *env, const char *str, ptrdiff_t length)
{
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
@@ -609,7 +609,7 @@ module_set_user_finalizer (emacs_env *env, emacs_value uptr,
}
static void
-module_vec_set (emacs_env *env, emacs_value vec, size_t i, emacs_value val)
+module_vec_set (emacs_env *env, emacs_value vec, ptrdiff_t i, emacs_value val)
{
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
@@ -633,41 +633,29 @@ module_vec_set (emacs_env *env, emacs_value vec, size_t i, emacs_value val)
}
static emacs_value
-module_vec_get (emacs_env *env, emacs_value vec, size_t i)
+module_vec_get (emacs_env *env, emacs_value vec, ptrdiff_t i)
{
- /* Type of ASIZE (lvec) is ptrdiff_t, make sure it fits. */
- verify (PTRDIFF_MAX <= SIZE_MAX);
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
- if (i > MOST_POSITIVE_FIXNUM)
- {
- module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
- return NULL;
- }
Lisp_Object lvec = value_to_lisp (vec);
if (! VECTORP (lvec))
{
module_wrong_type (env, Qvectorp, lvec);
return NULL;
}
- /* Prevent error-prone comparison between types of different signedness. */
- size_t size = ASIZE (lvec);
+ ptrdiff_t size = ASIZE (lvec);
eassert (size >= 0);
- if (i >= size)
+ if (! (0 <= i && i < size))
{
- if (i > MOST_POSITIVE_FIXNUM)
- i = (size_t) MOST_POSITIVE_FIXNUM;
module_args_out_of_range (env, lvec, make_number (i));
return NULL;
}
return lisp_to_value (env, AREF (lvec, i));
}
-static size_t
+static ptrdiff_t
module_vec_size (emacs_env *env, emacs_value vec)
{
- /* Type of ASIZE (lvec) is ptrdiff_t, make sure it fits. */
- verify (PTRDIFF_MAX <= SIZE_MAX);
check_main_thread ();
eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
Lisp_Object lvec = value_to_lisp (vec);
@@ -947,7 +935,7 @@ void mark_modules (void)
for (struct emacs_value_frame *frame = &env->priv.storage.initial;
frame != NULL;
frame = frame->next)
- for (size_t i = 0; i < frame->offset; ++i)
+ for (int i = 0; i < frame->offset; ++i)
mark_object (frame->objects[i].v);
}
}
diff --git a/src/emacs-module.h b/src/emacs-module.h
index 2759b1cb0f0..a2edf8c0eb3 100644
--- a/src/emacs-module.h
+++ b/src/emacs-module.h
@@ -46,7 +46,7 @@ enum emacs_arity { emacs_variadic_function = -2 };
struct emacs_runtime
{
/* Structure size (for version checking). */
- size_t size;
+ ptrdiff_t size;
/* Private data; users should not touch this. */
struct emacs_runtime_private *private_members;
@@ -82,7 +82,7 @@ enum emacs_funcall_exit
struct emacs_env_25
{
/* Structure size (for version checking). */
- size_t size;
+ ptrdiff_t size;
/* Private data; users should not touch this. */
struct emacs_env_private *private_members;
@@ -165,11 +165,11 @@ struct emacs_env_25
bool (*copy_string_contents) (emacs_env *env,
emacs_value value,
char *buffer,
- size_t *size_inout);
+ ptrdiff_t *size_inout);
/* Create a Lisp string from a utf8 encoded string. */
emacs_value (*make_string) (emacs_env *env,
- const char *contents, size_t length);
+ const char *contents, ptrdiff_t length);
/* Embedded pointer type. */
emacs_value (*make_user_ptr) (emacs_env *env,
@@ -186,12 +186,12 @@ struct emacs_env_25
void (*fin) (void *) EMACS_NOEXCEPT);
/* Vector functions. */
- emacs_value (*vec_get) (emacs_env *env, emacs_value vec, size_t i);
+ emacs_value (*vec_get) (emacs_env *env, emacs_value vec, ptrdiff_t i);
- void (*vec_set) (emacs_env *env, emacs_value vec, size_t i,
+ void (*vec_set) (emacs_env *env, emacs_value vec, ptrdiff_t i,
emacs_value val);
- size_t (*vec_size) (emacs_env *env, emacs_value vec);
+ ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vec);
};
#ifdef __cplusplus
diff --git a/src/lread.c b/src/lread.c
index f7ce0daf1fa..43100d9f699 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -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)
{
- size_t suffix_len = strlen (suffix);
- size_t string_len = SBYTES (string);
+ ptrdiff_t suffix_len = strlen (suffix);
+ ptrdiff_t string_len = SBYTES (string);
return string_len >= suffix_len && !strcmp (SSDATA (string) + string_len - suffix_len, suffix);
}