[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 9f10e1a: Support bignums when serializing JSON
From: |
Philipp Stephani |
Subject: |
[Emacs-diffs] master 9f10e1a: Support bignums when serializing JSON |
Date: |
Fri, 21 Sep 2018 15:52:51 -0400 (EDT) |
branch: master
commit 9f10e1a0eef0dd5572a34a76617d50df0e3dd357
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>
Support bignums when serializing JSON
* src/json.c (lisp_to_json): Support bignums.
* test/src/json-tests.el (json-serialize/bignum): New test.
---
src/json.c | 10 +++++++---
test/src/json-tests.el | 8 ++++++++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/json.c b/src/json.c
index 976783d..8b365e3 100644
--- a/src/json.c
+++ b/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)));
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 8bd679b..911bc49 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 9f10e1a: Support bignums when serializing JSON,
Philipp Stephani <=