diff options
| author | Philipp Stephani | 2019-04-22 17:29:06 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2019-04-22 17:36:52 +0200 |
| commit | 4e2ea400cbd78fa791fb897938a6dcb099401a25 (patch) | |
| tree | bf386a4685abccf8ffc6ad6cf907e18671f0f405 /src/json.c | |
| parent | 3b4e312cfe1e0b185fea58bc35fa951a8389c144 (diff) | |
| download | emacs-4e2ea400cbd78fa791fb897938a6dcb099401a25.tar.gz emacs-4e2ea400cbd78fa791fb897938a6dcb099401a25.zip | |
Introduce a helper macro to convert a Lisp integer to a C integer.
This is similar to CONS_TO_INTEGER. The inverse (INT_TO_INTEGER)
already exists.
* src/lisp.h (INTEGER_TO_INT): New macro.
(ranged_integer_to_int, ranged_integer_to_uint): New
functions.
* src/json.c (lisp_to_json): Use helper macro.
Diffstat (limited to 'src/json.c')
| -rw-r--r-- | src/json.c | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/src/json.c b/src/json.c index 928825e034c..16500bce72d 100644 --- a/src/json.c +++ b/src/json.c | |||
| @@ -495,14 +495,7 @@ lisp_to_json (Lisp_Object lisp, struct json_configuration *conf) | |||
| 495 | else if (EQ (lisp, Qt)) | 495 | else if (EQ (lisp, Qt)) |
| 496 | return json_check (json_true ()); | 496 | return json_check (json_true ()); |
| 497 | else if (INTEGERP (lisp)) | 497 | else if (INTEGERP (lisp)) |
| 498 | { | 498 | return json_check (json_integer (INTEGER_TO_INT (lisp, json_int_t))); |
| 499 | intmax_t low = TYPE_MINIMUM (json_int_t); | ||
| 500 | intmax_t high = TYPE_MAXIMUM (json_int_t); | ||
| 501 | intmax_t value; | ||
| 502 | if (! integer_to_intmax (lisp, &value) || value < low || high < value) | ||
| 503 | args_out_of_range_3 (lisp, make_int (low), make_int (high)); | ||
| 504 | return json_check (json_integer (value)); | ||
| 505 | } | ||
| 506 | else if (FLOATP (lisp)) | 499 | else if (FLOATP (lisp)) |
| 507 | return json_check (json_real (XFLOAT_DATA (lisp))); | 500 | return json_check (json_real (XFLOAT_DATA (lisp))); |
| 508 | else if (STRINGP (lisp)) | 501 | else if (STRINGP (lisp)) |