{
/* Make a big string and make it global. */
char str[26 * 100];
- for (size_t i = 0; i < sizeof str; i++)
+ for (int i = 0; i < sizeof str; i++)
str[i] = 'a' + (i % 26);
/* We don't need to null-terminate str. */
void *data)
{
emacs_value lisp_str = args[0];
- size_t size = 0;
+ ptrdiff_t size = 0;
char * buf = NULL;
env->copy_string_contents (env, lisp_str, buf, &size);
buf = malloc (size);
env->copy_string_contents (env, lisp_str, buf, &size);
- for (size_t i = 0; i + 1 < size; i++)
+ for (ptrdiff_t i = 0; i + 1 < size; i++)
if (buf[i] == 'a')
buf[i] = 'b';
{
emacs_value vec = args[0];
emacs_value val = args[1];
- size_t size = env->vec_size (env, vec);
- for (size_t i = 0; i < size; i++)
+ ptrdiff_t size = env->vec_size (env, vec);
+ for (ptrdiff_t i = 0; i < size; i++)
env->vec_set (env, vec, i, val);
return env->intern (env, "t");
}
{
emacs_value vec = args[0];
emacs_value val = args[1];
- size_t size = env->vec_size (env, vec);
- for (size_t i = 0; i < size; i++)
+ ptrdiff_t size = env->vec_size (env, vec);
+ for (ptrdiff_t i = 0; i < size; i++)
if (!env->eq (env, env->vec_get (env, vec, i), val))
return env->intern (env, "nil");
return env->intern (env, "t");
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;
{
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
{
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);
}
}
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);
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. */
}
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);
}
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);
}
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);
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);
}
}
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;
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;
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,
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