aboutsummaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorPhilipp Stephani2017-09-18 10:51:39 +0200
committerPhilipp Stephani2017-12-10 13:49:08 +0100
commitab203e36d5f84a99b6d4b04f1a22ba028be750e3 (patch)
tree660ed9e9cf32973808ace1c5aed572885bafd110 /src/eval.c
parent402e790ad4cff87d0e40e516a15553c408f12de1 (diff)
downloademacs-ab203e36d5f84a99b6d4b04f1a22ba028be750e3.tar.gz
emacs-ab203e36d5f84a99b6d4b04f1a22ba028be750e3.zip
Implement native JSON support using Jansson
* configure.ac: New option --with-json. * src/json.c (Fjson_serialize, Fjson_insert, Fjson_parse_string) (Fjson_parse_buffer): New defuns. (json_malloc, json_free, json_has_prefix, json_has_suffix) (json_make_string, json_build_string, json_encode) (json_out_of_memory, json_parse_error) (json_release_object, check_string_without_embedded_nulls, json_check) (lisp_to_json, lisp_to_json_toplevel, lisp_to_json_toplevel_1) (json_insert, json_insert_callback, json_to_lisp) (json_read_buffer_callback, Fjson_parse_buffer, define_error): New helper functions. (init_json, syms_of_json): New file. * src/lisp.h: Declaration for init_json and syms_of_json. * src/emacs.c (main): Enable JSON functions. * src/eval.c (internal_catch_all, internal_catch_all_1): New helper functions to catch all signals. (syms_of_eval): Add uninterned symbol to signify out of memory. * src/Makefile.in (JSON_LIBS, JSON_CFLAGS, JSON_OBJ, EMACS_CFLAGS) (base_obj, LIBES): Compile json.c if --with-json is enabled. * test/src/json-tests.el (json-serialize/roundtrip) (json-serialize/object, json-parse-string/object) (json-parse-string/string, json-serialize/string) (json-parse-string/incomplete, json-parse-string/trailing) (json-parse-buffer/incomplete, json-parse-buffer/trailing): New unit tests. * doc/lispref/text.texi (Parsing JSON): New manual section.
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/eval.c b/src/eval.c
index 47c4f17eabc..b774fd06139 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1416,6 +1416,57 @@ internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
1416 } 1416 }
1417} 1417}
1418 1418
1419static Lisp_Object
1420internal_catch_all_1 (Lisp_Object (*function) (void *), void *argument)
1421{
1422 struct handler *c = push_handler_nosignal (Qt, CATCHER_ALL);
1423 if (c == NULL)
1424 return Qcatch_all_memory_full;
1425
1426 if (sys_setjmp (c->jmp) == 0)
1427 {
1428 Lisp_Object val = function (argument);
1429 eassert (handlerlist == c);
1430 handlerlist = c->next;
1431 return val;
1432 }
1433 else
1434 {
1435 eassert (handlerlist == c);
1436 Lisp_Object val = c->val;
1437 handlerlist = c->next;
1438 Fsignal (Qno_catch, val);
1439 }
1440}
1441
1442/* Like a combination of internal_condition_case_1 and internal_catch.
1443 Catches all signals and throws. Never exits nonlocally; returns
1444 Qcatch_all_memory_full if no handler could be allocated. */
1445
1446Lisp_Object
1447internal_catch_all (Lisp_Object (*function) (void *), void *argument,
1448 Lisp_Object (*handler) (Lisp_Object))
1449{
1450 struct handler *c = push_handler_nosignal (Qt, CONDITION_CASE);
1451 if (c == NULL)
1452 return Qcatch_all_memory_full;
1453
1454 if (sys_setjmp (c->jmp) == 0)
1455 {
1456 Lisp_Object val = internal_catch_all_1 (function, argument);
1457 eassert (handlerlist == c);
1458 handlerlist = c->next;
1459 return val;
1460 }
1461 else
1462 {
1463 eassert (handlerlist == c);
1464 Lisp_Object val = c->val;
1465 handlerlist = c->next;
1466 return handler (val);
1467 }
1468}
1469
1419struct handler * 1470struct handler *
1420push_handler (Lisp_Object tag_ch_val, enum handlertype handlertype) 1471push_handler (Lisp_Object tag_ch_val, enum handlertype handlertype)
1421{ 1472{
@@ -4067,6 +4118,9 @@ alist of active lexical bindings. */);
4067 4118
4068 inhibit_lisp_code = Qnil; 4119 inhibit_lisp_code = Qnil;
4069 4120
4121 DEFSYM (Qcatch_all_memory_full, "catch-all-memory-full");
4122 Funintern (Qcatch_all_memory_full, Qnil);
4123
4070 defsubr (&Sor); 4124 defsubr (&Sor);
4071 defsubr (&Sand); 4125 defsubr (&Sand);
4072 defsubr (&Sif); 4126 defsubr (&Sif);