aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/mod-test/test.el6
-rw-r--r--src/emacs-module.c24
2 files changed, 19 insertions, 11 deletions
diff --git a/modules/mod-test/test.el b/modules/mod-test/test.el
index a0abdab49e5..eacc6671ead 100644
--- a/modules/mod-test/test.el
+++ b/modules/mod-test/test.el
@@ -42,7 +42,11 @@
42 (nth 1 descr)))) 42 (nth 1 descr))))
43 (should (= (nth 2 descr) 3))) 43 (should (= (nth 2 descr) 3)))
44 (should-error (mod-test-sum "1" 2) :type 'wrong-type-argument) 44 (should-error (mod-test-sum "1" 2) :type 'wrong-type-argument)
45 (should-error (mod-test-sum 1 "2") :type 'wrong-type-argument)) 45 (should-error (mod-test-sum 1 "2") :type 'wrong-type-argument)
46 (should (= (mod-test-sum -1 most-positive-fixnum)
47 (1- most-positive-fixnum)))
48 (should (= (mod-test-sum 1 most-negative-fixnum)
49 (1+ most-negative-fixnum))))
46 50
47(ert-deftest mod-test-sum-docstring () 51(ert-deftest mod-test-sum-docstring ()
48 (should (string= (documentation 'mod-test-sum) "Return A + B"))) 52 (should (string= (documentation 'mod-test-sum) "Return A + B")))
diff --git a/src/emacs-module.c b/src/emacs-module.c
index 67e5eab0110..13f2a1dd98f 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -880,44 +880,48 @@ value_to_lisp (emacs_value v)
880static emacs_value 880static emacs_value
881lisp_to_value (Lisp_Object o) 881lisp_to_value (Lisp_Object o)
882{ 882{
883 EMACS_INT i = XLI (o);
884#ifdef WIDE_EMACS_INT 883#ifdef WIDE_EMACS_INT
885 /* We need to compress the EMACS_INT into the space of a pointer. 884 /* We need to compress the EMACS_INT into the space of a pointer.
886 For most objects, this is just a question of shuffling the tags around. 885 For most objects, this is just a question of shuffling the tags around.
887 But in some cases (e.g. large integers) this can't be done, so we 886 But in some cases (e.g. large integers) this can't be done, so we
888 should allocate a special object to hold the extra data. */ 887 should allocate a special object to hold the extra data. */
888 Lisp_Object orig = o;
889 int tag = XTYPE (o); 889 int tag = XTYPE (o);
890 switch (tag) 890 switch (tag)
891 { 891 {
892 case_Lisp_Int: 892 case_Lisp_Int:
893 { 893 {
894 EMACS_UINT val = i & VALMASK; 894 EMACS_UINT ui = (EMACS_UINT) XINT (o);
895 if (val <= (SIZE_MAX >> GCTYPEBITS)) 895 if (ui <= (SIZE_MAX >> GCTYPEBITS))
896 { 896 {
897 size_t tv = (size_t)val; 897 uintptr_t uv = (uintptr_t) ui;
898 emacs_value v = (emacs_value) ((tv << GCTYPEBITS) | tag); 898 emacs_value v = (emacs_value) ((uv << GCTYPEBITS) | tag);
899 eassert (EQ (value_to_lisp (v), o)); 899 eassert (EQ (value_to_lisp (v), o));
900 return v; 900 return v;
901 } 901 }
902 else 902 else
903 o = Fcons (o, ltv_mark); 903 {
904 o = Fcons (o, ltv_mark);
905 tag = Lisp_Cons;
906 }
904 } /* FALLTHROUGH */ 907 } /* FALLTHROUGH */
905 default: 908 default:
906 { 909 {
907 void *ptr = XUNTAG (o, tag); 910 void *ptr = XUNTAG (o, tag);
908 if (((size_t)ptr) & ((1 << GCTYPEBITS) - 1)) 911 if (((uintptr_t)ptr) & ((1 << GCTYPEBITS) - 1))
909 { /* Pointer is not properly aligned! */ 912 { /* Pointer is not properly aligned! */
910 eassert (!CONSP (o)); /* Cons cells have to always be aligned! */ 913 eassert (!CONSP (o)); /* Cons cells have to always be aligned! */
911 o = Fcons (o, ltv_mark); 914 o = Fcons (o, ltv_mark);
912 ptr = XUNTAG (o, tag); 915 ptr = XUNTAG (o, tag);
913 } 916 }
914 emacs_value v = (emacs_value)(((size_t) ptr) | tag); 917 emacs_value v = (emacs_value) (((uintptr_t) ptr) | tag);
915 eassert (EQ (value_to_lisp (v), o)); 918 eassert (EQ (value_to_lisp (v), orig));
916 return v; 919 return v;
917 } 920 }
918 } 921 }
919#else 922#else
920 emacs_value v = (emacs_value)i; 923 emacs_value v = (emacs_value) XLI (o);
924
921 /* Check the assumption made elsewhere that Lisp_Object and emacs_value 925 /* Check the assumption made elsewhere that Lisp_Object and emacs_value
922 share the same underlying bit representation. */ 926 share the same underlying bit representation. */
923 eassert (v == *(emacs_value*)&o); 927 eassert (v == *(emacs_value*)&o);