Support bignums when serializing JSON
* src/json.c (lisp_to_json): Support bignums. * test/src/json-tests.el (json-serialize/bignum): New test.
This commit is contained in:
parent
7f3877e834
commit
9f10e1a0ee
2 changed files with 15 additions and 3 deletions
10
src/json.c
10
src/json.c
|
@ -488,10 +488,14 @@ lisp_to_json (Lisp_Object lisp, struct json_configuration *conf)
|
|||
return json_check (json_false ());
|
||||
else if (EQ (lisp, Qt))
|
||||
return json_check (json_true ());
|
||||
else if (FIXNUMP (lisp))
|
||||
else if (INTEGERP (lisp))
|
||||
{
|
||||
CHECK_TYPE_RANGED_INTEGER (json_int_t, lisp);
|
||||
return json_check (json_integer (XFIXNUM (lisp)));
|
||||
intmax_t low = TYPE_MINIMUM (json_int_t);
|
||||
intmax_t high = TYPE_MAXIMUM (json_int_t);
|
||||
intmax_t value;
|
||||
if (! integer_to_intmax (lisp, &value) || value < low || high < value)
|
||||
args_out_of_range_3 (lisp, make_int (low), make_int (high));
|
||||
return json_check (json_integer (value));
|
||||
}
|
||||
else if (FLOATP (lisp))
|
||||
return json_check (json_real (XFLOAT_DATA (lisp)));
|
||||
|
|
|
@ -278,5 +278,13 @@ Test with both unibyte and multibyte strings."
|
|||
:type 'no-catch)
|
||||
(should (equal calls 1)))))
|
||||
|
||||
(ert-deftest json-serialize/bignum ()
|
||||
(skip-unless (fboundp 'json-serialize))
|
||||
(should (equal (json-serialize (vector (1+ most-positive-fixnum)
|
||||
(1- most-negative-fixnum)))
|
||||
(format "[%d,%d]"
|
||||
(1+ most-positive-fixnum)
|
||||
(1- most-negative-fixnum)))))
|
||||
|
||||
(provide 'json-tests)
|
||||
;;; json-tests.el ends here
|
||||
|
|
Loading…
Add table
Reference in a new issue