diff options
Diffstat (limited to 'src/emacs-module.c')
| -rw-r--r-- | src/emacs-module.c | 46 |
1 files changed, 17 insertions, 29 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 | |||
| 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 | ||
| 504 | static bool | 504 | static bool |
| 505 | module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer, | 505 | module_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 | ||
| 538 | static emacs_value | 538 | static emacs_value |
| 539 | module_make_string (emacs_env *env, const char *str, size_t length) | 539 | module_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 | ||
| 611 | static void | 611 | static void |
| 612 | module_vec_set (emacs_env *env, emacs_value vec, size_t i, emacs_value val) | 612 | module_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 | ||
| 635 | static emacs_value | 635 | static emacs_value |
| 636 | module_vec_get (emacs_env *env, emacs_value vec, size_t i) | 636 | module_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 | ||
| 666 | static size_t | 656 | static ptrdiff_t |
| 667 | module_vec_size (emacs_env *env, emacs_value vec) | 657 | module_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 | } |