aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/mod-test/mod-test.c14
-rw-r--r--src/emacs-module.c46
-rw-r--r--src/emacs-module.h14
-rw-r--r--src/lread.c4
4 files changed, 33 insertions, 45 deletions
diff --git a/modules/mod-test/mod-test.c b/modules/mod-test/mod-test.c
index d1a4ce0d6fa..0160da69d0f 100644
--- a/modules/mod-test/mod-test.c
+++ b/modules/mod-test/mod-test.c
@@ -117,7 +117,7 @@ Fmod_test_globref_make (emacs_env *env, int nargs, emacs_value args[],
117{ 117{
118 /* Make a big string and make it global. */ 118 /* Make a big string and make it global. */
119 char str[26 * 100]; 119 char str[26 * 100];
120 for (size_t i = 0; i < sizeof str; i++) 120 for (int i = 0; i < sizeof str; i++)
121 str[i] = 'a' + (i % 26); 121 str[i] = 'a' + (i % 26);
122 122
123 /* We don't need to null-terminate str. */ 123 /* We don't need to null-terminate str. */
@@ -133,14 +133,14 @@ Fmod_test_string_a_to_b (emacs_env *env, int nargs, emacs_value args[],
133 void *data) 133 void *data)
134{ 134{
135 emacs_value lisp_str = args[0]; 135 emacs_value lisp_str = args[0];
136 size_t size = 0; 136 ptrdiff_t size = 0;
137 char * buf = NULL; 137 char * buf = NULL;
138 138
139 env->copy_string_contents (env, lisp_str, buf, &size); 139 env->copy_string_contents (env, lisp_str, buf, &size);
140 buf = malloc (size); 140 buf = malloc (size);
141 env->copy_string_contents (env, lisp_str, buf, &size); 141 env->copy_string_contents (env, lisp_str, buf, &size);
142 142
143 for (size_t i = 0; i + 1 < size; i++) 143 for (ptrdiff_t i = 0; i + 1 < size; i++)
144 if (buf[i] == 'a') 144 if (buf[i] == 'a')
145 buf[i] = 'b'; 145 buf[i] = 'b';
146 146
@@ -191,8 +191,8 @@ Fmod_test_vector_fill (emacs_env *env, int nargs, emacs_value args[], void *data
191{ 191{
192 emacs_value vec = args[0]; 192 emacs_value vec = args[0];
193 emacs_value val = args[1]; 193 emacs_value val = args[1];
194 size_t size = env->vec_size (env, vec); 194 ptrdiff_t size = env->vec_size (env, vec);
195 for (size_t i = 0; i < size; i++) 195 for (ptrdiff_t i = 0; i < size; i++)
196 env->vec_set (env, vec, i, val); 196 env->vec_set (env, vec, i, val);
197 return env->intern (env, "t"); 197 return env->intern (env, "t");
198} 198}
@@ -205,8 +205,8 @@ Fmod_test_vector_eq (emacs_env *env, int nargs, emacs_value args[], void *data)
205{ 205{
206 emacs_value vec = args[0]; 206 emacs_value vec = args[0];
207 emacs_value val = args[1]; 207 emacs_value val = args[1];
208 size_t size = env->vec_size (env, vec); 208 ptrdiff_t size = env->vec_size (env, vec);
209 for (size_t i = 0; i < size; i++) 209 for (ptrdiff_t i = 0; i < size; i++)
210 if (!env->eq (env, env->vec_get (env, vec, i), val)) 210 if (!env->eq (env, env->vec_get (env, vec, i), val))
211 return env->intern (env, "nil"); 211 return env->intern (env, "nil");
212 return env->intern (env, "t"); 212 return env->intern (env, "t");
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
78 struct emacs_value_tag objects[value_frame_size]; 78 struct emacs_value_tag objects[value_frame_size];
79 79
80 /* Index of the next free value in `objects'. */ 80 /* Index of the next free value in `objects'. */
81 size_t offset; 81 int offset;
82 82
83 /* Pointer to next frame, if any. */ 83 /* Pointer to next frame, if any. */
84 struct emacs_value_frame *next; 84 struct emacs_value_frame *next;
@@ -263,13 +263,13 @@ module_make_global_ref (emacs_env *env, emacs_value ref)
263 { 263 {
264 Lisp_Object value = HASH_VALUE (h, i); 264 Lisp_Object value = HASH_VALUE (h, i);
265 eassert (NATNUMP (value)); 265 eassert (NATNUMP (value));
266 EMACS_UINT refcount = XFASTINT (value); 266 EMACS_INT refcount = XFASTINT (value) + 1;
267 if (refcount >= MOST_POSITIVE_FIXNUM) 267 if (refcount > MOST_POSITIVE_FIXNUM)
268 { 268 {
269 module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil); 269 module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
270 return NULL; 270 return NULL;
271 } 271 }
272 XSETFASTINT (value, refcount + 1); 272 value = make_natnum (refcount);
273 set_hash_value_slot (h, i, value); 273 set_hash_value_slot (h, i, value);
274 } 274 }
275 else 275 else
@@ -297,15 +297,15 @@ module_free_global_ref (emacs_env *env, emacs_value ref)
297 { 297 {
298 Lisp_Object value = HASH_VALUE (h, i); 298 Lisp_Object value = HASH_VALUE (h, i);
299 eassert (NATNUMP (value)); 299 eassert (NATNUMP (value));
300 EMACS_UINT refcount = XFASTINT (value); 300 EMACS_INT refcount = XFASTINT (value) - 1;
301 eassert (refcount > 0); 301 if (refcount > 0)
302 if (refcount > 1)
303 { 302 {
304 XSETFASTINT (value, refcount - 1); 303 value = make_natnum (refcount - 1);
305 set_hash_value_slot (h, i, value); 304 set_hash_value_slot (h, i, value);
306 } 305 }
307 else 306 else
308 { 307 {
308 eassert (refcount == 0);
309 hash_remove_from_table (h, value); 309 hash_remove_from_table (h, value);
310 } 310 }
311 } 311 }
@@ -503,7 +503,7 @@ module_make_float (emacs_env *env, double d)
503 503
504static bool 504static bool
505module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer, 505module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
506 size_t *length) 506 ptrdiff_t *length)
507{ 507{
508 check_main_thread (); 508 check_main_thread ();
509 eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return); 509 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,
515 return false; 515 return false;
516 } 516 }
517 517
518 size_t raw_size = SBYTES (lisp_str); 518 ptrdiff_t raw_size = SBYTES (lisp_str);
519 519
520 /* Emacs internal encoding is more-or-less UTF8, let's assume utf8 520 /* Emacs internal encoding is more-or-less UTF8, let's assume utf8
521 encoded emacs string are the same byte size. */ 521 encoded emacs string are the same byte size. */
@@ -536,7 +536,7 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
536} 536}
537 537
538static emacs_value 538static emacs_value
539module_make_string (emacs_env *env, const char *str, size_t length) 539module_make_string (emacs_env *env, const char *str, ptrdiff_t length)
540{ 540{
541 check_main_thread (); 541 check_main_thread ();
542 eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return); 542 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,
609} 609}
610 610
611static void 611static void
612module_vec_set (emacs_env *env, emacs_value vec, size_t i, emacs_value val) 612module_vec_set (emacs_env *env, emacs_value vec, ptrdiff_t i, emacs_value val)
613{ 613{
614 check_main_thread (); 614 check_main_thread ();
615 eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return); 615 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)
633} 633}
634 634
635static emacs_value 635static emacs_value
636module_vec_get (emacs_env *env, emacs_value vec, size_t i) 636module_vec_get (emacs_env *env, emacs_value vec, ptrdiff_t i)
637{ 637{
638 /* Type of ASIZE (lvec) is ptrdiff_t, make sure it fits. */
639 verify (PTRDIFF_MAX <= SIZE_MAX);
640 check_main_thread (); 638 check_main_thread ();
641 eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return); 639 eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
642 if (i > MOST_POSITIVE_FIXNUM)
643 {
644 module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
645 return NULL;
646 }
647 Lisp_Object lvec = value_to_lisp (vec); 640 Lisp_Object lvec = value_to_lisp (vec);
648 if (! VECTORP (lvec)) 641 if (! VECTORP (lvec))
649 { 642 {
650 module_wrong_type (env, Qvectorp, lvec); 643 module_wrong_type (env, Qvectorp, lvec);
651 return NULL; 644 return NULL;
652 } 645 }
653 /* Prevent error-prone comparison between types of different signedness. */ 646 ptrdiff_t size = ASIZE (lvec);
654 size_t size = ASIZE (lvec);
655 eassert (size >= 0); 647 eassert (size >= 0);
656 if (i >= size) 648 if (! (0 <= i && i < size))
657 { 649 {
658 if (i > MOST_POSITIVE_FIXNUM)
659 i = (size_t) MOST_POSITIVE_FIXNUM;
660 module_args_out_of_range (env, lvec, make_number (i)); 650 module_args_out_of_range (env, lvec, make_number (i));
661 return NULL; 651 return NULL;
662 } 652 }
663 return lisp_to_value (env, AREF (lvec, i)); 653 return lisp_to_value (env, AREF (lvec, i));
664} 654}
665 655
666static size_t 656static ptrdiff_t
667module_vec_size (emacs_env *env, emacs_value vec) 657module_vec_size (emacs_env *env, emacs_value vec)
668{ 658{
669 /* Type of ASIZE (lvec) is ptrdiff_t, make sure it fits. */
670 verify (PTRDIFF_MAX <= SIZE_MAX);
671 check_main_thread (); 659 check_main_thread ();
672 eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return); 660 eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
673 Lisp_Object lvec = value_to_lisp (vec); 661 Lisp_Object lvec = value_to_lisp (vec);
@@ -947,7 +935,7 @@ void mark_modules (void)
947 for (struct emacs_value_frame *frame = &env->priv.storage.initial; 935 for (struct emacs_value_frame *frame = &env->priv.storage.initial;
948 frame != NULL; 936 frame != NULL;
949 frame = frame->next) 937 frame = frame->next)
950 for (size_t i = 0; i < frame->offset; ++i) 938 for (int i = 0; i < frame->offset; ++i)
951 mark_object (frame->objects[i].v); 939 mark_object (frame->objects[i].v);
952 } 940 }
953} 941}
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 };
46struct emacs_runtime 46struct emacs_runtime
47{ 47{
48 /* Structure size (for version checking). */ 48 /* Structure size (for version checking). */
49 size_t size; 49 ptrdiff_t size;
50 50
51 /* Private data; users should not touch this. */ 51 /* Private data; users should not touch this. */
52 struct emacs_runtime_private *private_members; 52 struct emacs_runtime_private *private_members;
@@ -82,7 +82,7 @@ enum emacs_funcall_exit
82struct emacs_env_25 82struct emacs_env_25
83{ 83{
84 /* Structure size (for version checking). */ 84 /* Structure size (for version checking). */
85 size_t size; 85 ptrdiff_t size;
86 86
87 /* Private data; users should not touch this. */ 87 /* Private data; users should not touch this. */
88 struct emacs_env_private *private_members; 88 struct emacs_env_private *private_members;
@@ -165,11 +165,11 @@ struct emacs_env_25
165 bool (*copy_string_contents) (emacs_env *env, 165 bool (*copy_string_contents) (emacs_env *env,
166 emacs_value value, 166 emacs_value value,
167 char *buffer, 167 char *buffer,
168 size_t *size_inout); 168 ptrdiff_t *size_inout);
169 169
170 /* Create a Lisp string from a utf8 encoded string. */ 170 /* Create a Lisp string from a utf8 encoded string. */
171 emacs_value (*make_string) (emacs_env *env, 171 emacs_value (*make_string) (emacs_env *env,
172 const char *contents, size_t length); 172 const char *contents, ptrdiff_t length);
173 173
174 /* Embedded pointer type. */ 174 /* Embedded pointer type. */
175 emacs_value (*make_user_ptr) (emacs_env *env, 175 emacs_value (*make_user_ptr) (emacs_env *env,
@@ -186,12 +186,12 @@ struct emacs_env_25
186 void (*fin) (void *) EMACS_NOEXCEPT); 186 void (*fin) (void *) EMACS_NOEXCEPT);
187 187
188 /* Vector functions. */ 188 /* Vector functions. */
189 emacs_value (*vec_get) (emacs_env *env, emacs_value vec, size_t i); 189 emacs_value (*vec_get) (emacs_env *env, emacs_value vec, ptrdiff_t i);
190 190
191 void (*vec_set) (emacs_env *env, emacs_value vec, size_t i, 191 void (*vec_set) (emacs_env *env, emacs_value vec, ptrdiff_t i,
192 emacs_value val); 192 emacs_value val);
193 193
194 size_t (*vec_size) (emacs_env *env, emacs_value vec); 194 ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vec);
195}; 195};
196 196
197#ifdef __cplusplus 197#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'. */)
979static bool 979static bool
980suffix_p (Lisp_Object string, const char *suffix) 980suffix_p (Lisp_Object string, const char *suffix)
981{ 981{
982 size_t suffix_len = strlen (suffix); 982 ptrdiff_t suffix_len = strlen (suffix);
983 size_t string_len = SBYTES (string); 983 ptrdiff_t string_len = SBYTES (string);
984 984
985 return string_len >= suffix_len && !strcmp (SSDATA (string) + string_len - suffix_len, suffix); 985 return string_len >= suffix_len && !strcmp (SSDATA (string) + string_len - suffix_len, suffix);
986} 986}