summaryrefslogtreecommitdiff
path: root/src/json.c
Commit message (Collapse)AuthorAgeFilesLines
* ; Add 2023 to copyright years.Eli Zaretskii2023-01-011-1/+1
|
* Simplify last change (bug#60311)Eli Zaretskii2022-12-261-14/+26
| | | | | | | | | | | * src/json.c (json_available_p): Use original code. Always return true for !WINDOWSNT. (ensure_json_available): Now defined only on WINDOWSNT. (Fjson_serialize, Fjson_insert, Fjson_parse_string) (Fjson_parse_buffer): Call ensure_json_available only on WINDOWSNT. * lisp/subr.el (json-available-p): Simplify.
* Fix 'json-available-p' on MS-WindowsMattias Engdegård2022-12-261-52/+39
| | | | | | | | | | * src/json.c (json_available_p, ensure_json_available) (Fjson__available_p): New functions. (Fjson_serialize, Fjson_insert, Fjson_parse_string) (Fjson_parse_buffer): Use ensure_json_available. (syms_of_json): Defsubr json--available-p. * lisp/subr.el (json-available-p): Rewrite.
* Merge remote-tracking branch 'origin/master' into feature/tree-sitterYuan Fu2022-08-291-2/+4
|\
| * Allow NUL characters in JSON inputLars Ingebrigtsen2022-07-021-2/+4
| | | | | | | | | | * src/json.c (Fjson_parse_string, Fjson_parse_buffer): Allow NUL characters in JSON (bug#48274).
* | Merge remote-tracking branch 'savannah/master' into feature/tree-sitterYuan Fu2022-06-141-1/+1
|\ \ | |/
| * Use BASE_EQ when comparing with QunboundMattias Engdegård2022-06-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Qunbound is uninterned and can therefore never be EQ to any symbol with position. * src/buffer.c (Fbuffer_local_value, buffer_lisp_local_variables) (buffer_local_variables_1): * src/bytecode.c (exec_byte_code): * src/comp.c (compile_function, Fcomp__compile_ctxt_to_file): * src/composite.c (composition_gstring_cache_clear_font): * src/data.c (Fboundp, Fsymbol_value, set_internal) (Fdefault_boundp, Fdefault_value, Fmake_variable_buffer_local): * src/emacs-module.c (module_global_reference_p): * src/eval.c (Fdefault_toplevel_value, defvar) (run_hook_with_args): * src/fns.c (hash_put, Fmaphash): * src/font.c (font_put_extra): * src/frame.c (gui_set_frame_parameters) (gui_frame_get_and_record_arg, gui_default_parameter) (gui_figure_window_size): * src/haikufns.c (get_geometry_from_preferences) (haiku_create_frame, haiku_create_tip_frame): * src/haikuterm.c (haiku_draw_text_decoration) (haiku_default_font_parameter): * src/json.c (lisp_to_json_nonscalar_1): * src/keymap.c (access_keymap_1, access_keymap, current_minor_maps): * src/lread.c (readevalloop, define_symbol): * src/minibuf.c (read_minibuf, Ftry_completion): (Fall_completions, Ftest_completion): * src/pgtkfns.c (pgtk_default_font_parameter, Fx_create_frame) (x_create_tip_frame): * src/pgtkselect.c (Fpgtk_own_selection_internal): * src/print.c (print): * src/profiler.c (evict_lower_half, record_backtrace): * src/terminal.c (create_terminal): * src/textprop.c (set_properties): * src/w32fns.c (my_create_window, w32_icon) (w32_default_font_parameter, Fx_create_frame) (w32_create_tip_frame): * src/w32term.c (w32_draw_glyph_string): * src/xdisp.c (handle_single_display_spec) (cursor_row_fully_visible_p, calc_pixel_width_or_height): * src/xfns.c (x_default_scroll_bar_color_parameter, x_icon_verify) (x_icon, x_default_font_parameter, Fx_create_frame) (x_create_tip_frame): * src/xselect.c (x_handle_selection_request): * src/xterm.c (x_draw_glyph_string, x_term_init): Use BASE_EQ instead of EQ when comparing with Qunbound.
* | Add tree-sitter intergrationYuan Fu2022-05-071-16/+0
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables. (DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX so the diff looks this way. * doc/lispref/elisp.texi (Top): Add tree-sitter manual. * doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter. (Parser-based Font Lock): New section. (Auto-Indentation): Mention tree-sitter. (Parser-based Indentation): New section. * doc/lispref/parsing.texi (Parsing Program Source): New chapter. * lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add treesit-parser and treesit-node type. * lisp/treesit.el: New file. * src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS, TREE_SITTER_OBJ): New variables. * src/alloc.c: (cleanup_vector): Add cleanup code for treesit-parser and treesit-node. * src/casefiddle.c (casify_region): Notify tree-sitter parser of buffer change. * src/data.c (Ftype_of): Add treesit-parser and treesit-node type (Qtreesit_parser, Qtreesit_node): New symbol. * src/emacs.c (main): Add symbols in treesit.c. * src/eval.c (define_error): Move the function to here. * src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap, insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter parser of buffer change. * src/json.c (define_error): Move this function out. * src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and treesit-node. * src/lread.c (Vdynamic_library_suffixes): New variable. * src/print.c (print_vectorlike): Add code for printing treesit-parser and treesit-node. * src/treesit.c: New file. * src/treesit.h: New file. * test/src/treesit-tests.el: New file.
* Replace ptrdiff_t with new specpdl_ref type for specpdl referencesMattias Engdegård2022-02-121-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The specpdl_ref type is just an alias for ptrdiff_t; the compiled code remains the same. All operations on specpdl_ref (arithmetic, comparison etc) now go through inline functions. The bulk of the change is almost completely mechanical. It is done to prepare for a type-safe representation and subsequent performance improvement. * src/lisp.h (specpdl_ref, specpdl_count_to_ref, specpdl_ref_to_count) (specpdl_ref_eq, specpdl_ref_lt, specpdl_ref_valid_p) (make_invalid_specpdl_ref, specpdl_ref_add, specpdl_ref_to_ptr): New. (SPECPDL_INDEX, struct handler, USE_SAFE_ALLOCA, safe_free) (safe_free_unbind_to): * src/alloc.c (run_finalizer_function, inhibit_garbage_collection) (garbage_collect, Fgarbage_collect, which_symbols): * src/bidi.c (bidi_at_paragraph_end, bidi_find_paragraph_start): * src/buffer.c (Fkill_buffer, Fset_buffer_major_mode, Fmove_overlay) (Fdelete_overlay): * src/bytecode.c (exec_byte_code): * src/callint.c (Ffuncall_interactively, Fcall_interactively): * src/callproc.c (Fcall_process, call_process, create_temp_file) (Fcall_process_region): * src/charset.c (load_charset_map_from_file): * src/coding.c (decode_coding_gap, decode_coding_object) (encode_coding_object, Fread_coding_system): * src/comp.c (emit_static_object, helper_unbind_n, load_comp_unit): * src/composite.c (update_compositions, autocmp_chars): * src/cygw32.c (conv_filename_to_w32_unicode) (conv_filename_from_w32_unicode): * src/data.c (notify_variable_watchers): * src/decompress.c (Fzlib_decompress_region): * src/dired.c (directory_files_internal, file_name_completion) (file_attributes): * src/dispnew.c (Fredisplay): * src/doc.c (get_doc_string, Fsnarf_documentation): * src/editfns.c (Fsave_excursion, Fsave_current_buffer) (Freplace_buffer_contents, Fsubst_char_in_region, Fsave_restriction) (styled_format): * src/emacs-module.c (Fmodule_load, funcall_module): * src/emacs.c (init_cmdargs, Fdump_emacs): * src/eval.c (call_debugger, do_debug_on_call, FletX, Flet) (Ffuncall_with_delayed_message, Funwind_protect) (internal_lisp_condition_case, signal_or_quit) (load_with_autoload_queue, Feval, grow_specpdl_allocation) (record_in_backtrace, eval_sub, Ffuncall, apply_lambda) (funcall_lambda, clear_unwind_protect, set_unwind_protect) (set_unwind_protect_ptr, unbind_to, Fbacktrace_eval): * src/fileio.c (Fmake_temp_file_internal, Fcopy_file, Frename_file) (Finsert_file_contents, write_region, Fdo_auto_save): * src/fns.c (Fyes_or_no_p, Frequire, hash_table_user_defined_call): * src/fringe.c (update_window_fringes): * src/gtkutil.c (xg_dialog_run): * src/haiku_io.c (c_specpdl_idx_from_cxx): * src/haiku_support.cc (be_popup_file_dialog): * src/haiku_support.h (c_specpdl_idx_from_cxx): * src/haikufns.c (haiku_create_frame, haiku_create_tip_frame) (haiku_hide_tip, Fx_show_tip, Fhaiku_read_file_name): * src/haikumenu.c (haiku_popup_dialog, set_frame_menubar): * src/image.c (slurp_file): * src/indent.c (line_number_display_width, Fvertical_motion): * src/insdel.c (signal_before_change, signal_after_change) (Fcombine_after_change_execute): * src/intervals.c (get_local_map): * src/json.c (lisp_to_json_nonscalar_1, Fjson_serialize, Fjson_insert) (Fjson_parse_string, Fjson_parse_buffer): * src/keyboard.c (recursive_edit_1, Frecursive_edit, cmd_error) (Finternal_track_mouse, command_loop_1, read_menu_command) (safe_run_hooks, read_event_from_main_queue, read_char, timer_check_2) (menu_item_eval_property, read_key_sequence, read_key_sequence_vs) (Fsuspend_emacs): * src/keymap.c (Fcurrent_active_maps, Fdescribe_vector) (Fhelp__describe_vector): * src/lread.c (Fload, save_match_data_load, readevalloop) (Feval_buffer, Feval_region, grow_read_buffer, read_integer, read1): * src/macros.c (Fexecute_kbd_macro): * src/menu.c (x_popup_menu_1): * src/minibuf.c (read_minibuf, set_minibuffer_mode) (read_minibuf_unwind, Fread_string, Fread_buffer): * src/nsfns.m (Fx_create_frame, Fx_show_tip): * src/nsmenu.m (ns_update_menubar, ns_menu_show, ns_popup_dialog): * src/pdumper.c (Fdump_emacs_portable): * src/pgtkfns.c (Fx_create_frame, x_create_tip_frame, x_hide_tip) (Fx_show_tip, Fpgtk_print_frames_dialog, Fx_file_dialog, Fx_select_font): * src/pgtkmenu.c (set_frame_menubar, create_and_show_popup_menu) (pgtk_menu_show, create_and_show_dialog, pgtk_dialog_show) (pgtk_popup_dialog): * src/pgtkterm.c (pgtk_cr_export_frames): * src/print.c (PRINTPREPARE, temp_output_buffer_setup) (Fprin1_to_string, print_vectorlike): * src/process.c (Fmake_process, create_process, Fmake_pipe_process) (Fmake_serial_process, connect_network_socket, Fmake_network_process) (network_interface_info, server_accept_connection) (wait_reading_process_output, read_process_output, exec_sentinel): * src/regex-emacs.c (re_match_2_internal): * src/search.c (looking_at_1, fast_looking_at, search_buffer_re): * src/sound.c (Fplay_sound_internal): * src/sysdep.c (system_process_attributes): * src/term.c (tty_menu_show): * src/textprop.c (Fnext_single_char_property_change) (Fprevious_single_char_property_change, add_text_properties_1) (set_text_properties, set_text_properties_1, Fremove_text_properties) (Fremove_list_of_text_properties): * src/thread.c (Fmutex_lock, invoke_thread_function): * src/undo.c (truncate_undo_list): * src/w32fns.c (Fx_create_frame, w32_create_tip_frame, w32_hide_tip) (Fx_show_tip, Fx_file_dialog): * src/w32font.c (Fx_select_font): * src/w32menu.c (set_frame_menubar): * src/window.c (window_list, next_window, window_list_1) (run_window_configuration_change_hook, Frun_window_scroll_functions) (run_window_change_functions, set_window_buffer) (temp_output_buffer_show, window_scroll, scroll_command) (Fscroll_other_window, Fscroll_other_window_down): * src/xdisp.c (safe__call, handle_fontified_prop, handle_face_prop) (handle_single_display_spec, Fbuffer_text_pixel_size) (message_dolog, with_echo_area_buffer, setup_echo_area_for_printing) (display_echo_area, set_message, clear_message, echo_area_display) (gui_consider_frame_title, prepare_menu_bars, update_menu_bar) (update_tab_bar, update_tool_bar, redisplay_internal) (redisplay_preserve_echo_area, run_window_scroll_functions) (redisplay_window, extend_face_to_end_of_line) (display_count_lines_logically, display_count_lines_visually) (display_mode_lines, display_mode_line, Fformat_mode_line) (decode_mode_spec): * src/xfns.c (Fx_create_frame, x_create_tip_frame, x_hide_tip) (Fx_show_tip, Fx_file_dialog, Fx_select_font, Fx_print_frames_dialog): * src/xmenu.c (set_frame_menubar, create_and_show_popup_menu) (x_menu_show, create_and_show_dialog, x_dialog_show) (xw_popup_dialog): * src/xselect.c (x_get_local_selection, x_reply_selection_request) (x_handle_selection_request, wait_for_property_change): * src/xterm.c (x_cr_export_frames, x_connection_closed): Replace ptrdiff_t with specpdl_ref for referencing specpdl and use the corresponding functions instead of direct arithmetic.
* ; Add 2022 to copyright years.Eli Zaretskii2022-01-011-1/+1
|
* Signal an error in json.c function if not availableLars Ingebrigtsen2021-07-201-16/+9
| | | | | | * src/json.c (Fjson_serialize, Fjson_insert) (Fjson_parse_string, Fjson_parse_buffer, syms_of_json): Signal `json-unavailable' if jansson isn't available (bug#48228).
* ; * src/json.c (Fjson_parse_string): Fix the doc string.Eli Zaretskii2021-02-131-8/+8
|
* Pass 'struct json_configuration' as const where possible.Philipp Stephani2021-02-131-5/+6
| | | | | | | | | The JSON serialization and parsing functions don't need to modify these structures. * src/json.c (lisp_to_json_nonscalar_1, lisp_to_json_nonscalar) (lisp_to_json, json_to_lisp): Mark configuration object parameter as const.
* Allow any JSON value at the top level (Bug#42994).Philipp Stephani2021-02-131-37/+37
| | | | | | | | | | | | | | | | | | | | Newer standards like RFC 8259, which obsoletes the earlier RFC 4627, now allow any top-level value unconditionally, so Emacs should too. * src/json.c (Fjson_serialize, Fjson_insert): Pass JSON_ENCODE_ANY to allow serialization of any JSON value. Call 'lisp_to_json' instead of 'lisp_to_json_toplevel'. Remove obsolete comments (neither JSON_DECODE_ANY nor JSON_ALLOW_NUL are allowed here). Reword documentation strings. (Fjson_parse_string, Fjson_parse_buffer): Pass JSON_DECODE_ANY to allow deserialization of any JSON value. Reword documentation strings. (lisp_to_json_nonscalar, lisp_to_json_nonscalar_1): Rename from "toplevel" to avoid confusion. (lisp_to_json): Adapt caller. * test/src/json-tests.el (json-serialize/roundtrip-scalars): New unit test. * doc/lispref/text.texi (Parsing JSON): Update documentation.
* Update copyright year to 2021Paul Eggert2021-01-011-1/+1
| | | | Run "TZ=UTC0 admin/update-copyright".
* Use the full name of the null byte/character, not its abbreviationAndreas Schwab2020-10-051-9/+9
| | | | | | | | | | | | | | | | | | | | | * lisp/subr.el (inhibit-nul-byte-detection): Make it an obsolete alias. * src/coding.c (setup_coding_system): Use original name. (detect_coding): Rename nul_byte_found => null_byte_found. (detect_coding_system): Use original name. Rename nul_byte_found => null_byte_found. (Fdefine_coding_system_internal): Use original name. (syms_of_coding): Rename inhibit-nul-byte-detection to inhibit-null-byte-detection. * src/w16select.c (get_clipboard_data): Rename nul_char to null_char. * src/json.c (check_string_without_embedded_nulls): Rename from check_string_without_embedded_nuls. (Fjson_parse_string): Adjust accordingly. * src/coding.h (enum define_coding_undecided_arg_index) (enum coding_attr_index): Rename ...nul_byte... to ...null_byte.... * lisp/info.el (info-insert-file-contents, Info-insert-dir): * lisp/international/mule.el (define-coding-system): * lisp/vc/vc-git.el (vc-git--call): * doc/lispref/nonascii.texi (Lisp and Coding Systems): Use original name.
* * src/json.c (lisp_to_json): Simplify.Philipp Stephani2020-08-091-3/+1
|
* Merge from origin/emacs-27Glenn Morris2020-07-071-0/+2
|\ | | | | | | | | | | | | | | 59e768d64a Fix undefined behavior in json.c (Bug#42113) cce00bef03 Fix ACTION argument of 'display-buffer' call in gud.el 0121db2702 * src/keyboard.c (Fclear_this_command_keys): Doc fix. b9abf5ceb2 Improve do string of 'man' b87fc938a0 ; * src/xdisp.c (pos_visible_p): Yet another minor fix for...
| * Fix undefined behavior in json.c (Bug#42113)Philipp Stephani2020-06-291-0/+2
| | | | | | | | | | | | | | | | * src/json.c (lisp_to_json_toplevel_1, Fjson_parse_string): Check whether input strings are actually strings. * test/src/json-tests.el (json-parse-string/wrong-type) (json-serialize/wrong-hash-key-type): New regression tests.
* | Use decode_string_utf_8 in emacs-module.c.Philipp Stephani2020-01-131-1/+0
|/ | | | | | | | | | | Now that decode_string_utf_8 is available, we can use it to signal errors on invalid input. * src/coding.c (syms_of_coding): Move Qutf_8_string_p from json.c since it’s now used outside json.c. * src/emacs-module.c (module_decode_utf_8): New helper function. (module_make_function, module_copy_string_contents): Use it.
* Update copyright year to 2020Paul Eggert2020-01-011-1/+1
| | | | Run "TZ=UTC0 admin/update-copyright $(git ls-files)".
* Fix and speed up en/decoding of UTF-8 stringsEli Zaretskii2019-11-231-1/+1
| | | | | | | | | | | | * src/coding.c (get_char_bytes, encode_string_utf_8) (decode_string_utf_8): Fix commentary. (encode_string_utf_8): Return the original ASCII string only if NOCOPY is non-zero. (decode_string_utf_8): Accept 2 additional arguments STR and STR_LEN, which allow to pass the input text as a C string. (make_string_from_utf8): Delegate the job to decode_string_utf_8. * src/coding.h: Update the prototype of decode_string_utf_8. * src/json.c (json_encode): Call encode_string_utf_8.
* Adjust remaining uses of `NILP (HASH_HASH)`.Stefan Monnier2019-07-261-19/+22
| | | | | | | | * src/json.c (lisp_to_json_toplevel_1): * src/pdumper.c (dump_hash_table_stable_p, hash_table_contents): * src/print.c (print, print_vectorlike): * src/minibuf.c (Ftry_completion, Fall_completions, Ftest_completion): Use `EQ (HASH_KEY, Qunbound)` instead of `NILP (HASH_HASH)`.
* Simplify hashfn/cmpfn calling conventionPaul Eggert2019-07-201-2/+1
| | | | | | | | | | | | | | | | * src/fns.c (cmpfn_eql, cmpfn_equal, cmpfn_user_defined) (hashfn_eq, hashfn_equal, hashfn_eql, hashfn_user_defined): * src/profiler.c (cmpfn_profiler, hashfn_profiler): Use new calling convention where the return value is a fixnum instead of EMACS_UINT. While we’re at it, put the hash table at the end, since that’s a bit simpler and generates better code (at least on the x86-64). All callers changed. * src/fns.c (hash_lookup): Store fixnum rather than EMACS_UINT. All callers changed. (hash_put): Take a fixnum rather than an EMACS_UINT. All callers changed. Remove unnecessary eassert (XUFIXNUM does it). * src/lisp.h (struct hash_table_test): Adjust signatures of cmpfn and hashfn.
* * src/json.c (Fjson_insert): Don't temporarily insert invalid bytes in bufferStefan Monnier2019-07-021-9/+8
|
* * src/insdel.c (insert_from_gap_1): New fun, extracted from insert_from_gap.Stefan Monnier2019-07-021-11/+1
| | | | | | | (insert_from_gap): Use it. * src/lisp.h (insert_from_gap_1): Declare it. * src/json.c (Fjson_insert): * src/fileio.c (Finsert_file_contents): Use it.
* * src/coding.c (decode_coding_gap): Remove `chars` argument.Stefan Monnier2019-07-021-1/+1
| | | | | | * src/json.c (Fjson_insert): * src/fileio.c (Finsert_file_contents): * src/coding.h (decode_coding_gap): Adjust accordingly.
* Remove unnecessary tortoise checks.Pip Cet2019-06-271-1/+0
| | | | | | * src/fns.c (Fplist_get, Fplist_put, Flax_plist_get) (Flax_plist_put, Fplist_member): Remove unnecessary check. * src/json.c (lisp_to_json_toplevel_1): Remove unnecessary check.
* Avoid some strlen work, primarily via strnlenPaul Eggert2019-06-251-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * admin/merge-gnulib (GNULIB_MODULES): Add strnlen. * lib-src/etags.c (find_entries): * src/emacs.c (main): * src/nsmenu.m (parseKeyEquiv:): * src/nsterm.m (ns_xlfd_to_fontname): * src/term.c (vfatal): Prefer !*X to !strlen (X). * lib-src/etags.c (pfnote, add_regex): * lib-src/pop.c (pop_open): * lib-src/update-game-score.c (main): * lwlib/lwlib.c (lw_separator_p): * src/doprnt.c (doprnt): * src/emacs.c (main): * src/inotify.c (inotifyevent_to_event): * src/keyboard.c (menu_separator_name_p, parse_tool_bar_item): * src/sysdep.c (get_current_dir_name_or_unreachable): * src/xdisp.c (store_mode_line_string): Use strnlen to avoid unnecessary work with strlen. * lib-src/etags.c (Prolog_functions, prolog_pr) (Erlang_functions, erlang_func): Prefer ptrdiff_t to size_t when either will do. (prolog_pr, erlang_func): New arg LASTLEN, to avoid unnecessary strlen call. All callers changed. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * lib/strnlen.c, m4/strnlen.m4: New files, copied from Gnulib. * lwlib/lwlib.c (lw_separator_p): * src/json.c (json_has_prefix): Use strncmp to avoid unecessary work with strlen + memcmp. * src/process.c (set_socket_option): Use SBYTES instead of strlen.
* Fix names of functions in last commitEli Zaretskii2019-04-281-9/+12
| | | | | | | * src/coding.h (build_string_from_utf8): Rename from build_utf8_string. All callers changed. * src/coding.c (make_string_from_utf8): Rename from make_utf8_string. All callers changed.
* Refactoring: move UTF-8 decoding functions into coding.h.Philipp Stephani2019-04-281-44/+8
| | | | | | | | | | | | | | | | | json_make_string and json_build_string are generally useful and not JSON-specific. Move them to coding.[ch]. * src/coding.h (build_utf8_string): Move from json.c. * src/coding.c (make_utf8_string): Move from json.c. * src/json.c (json_make_string, json_build_string): Move to coding.[ch]. Split out JSON-specific comment. (json_parse_error, Fjson_serialize, json_to_lisp): Fix callers. * src/emacs-module.c (module_make_function, module_make_string): Use new functions. (module_decode, module_decode_copy): Remove.
* Use high-level integer conversion macro in a few cases.Philipp Stephani2019-04-231-2/+2
| | | | | | | | | INT_TO_INTEGER is more obviously correct and means we don’t have to worry about data type sizes and signedness. * src/json.c (json_parse_error): Use INT_TO_INTEGER. The tiny performance gain of make_fixed_natnum isn’t worth the trouble then signaling an error.
* * src/json.c (json_make_string): Add missing cast.Philipp Stephani2019-04-231-1/+1
|
* Speed up JSON parsingEli Zaretskii2019-04-231-3/+17
| | | | | | | | Thanks to Dmitry Gutov <dgutov@yandex.ru> for running many benchmarks and for useful discussions. * src/json.c (json_make_string): Speed up parsing of JSON strings by optimizing the normal case of a valid UTF-8 string being returned from libjansson. (Bug#31138)
* Go back to old way of checking json int rangePaul Eggert2019-04-221-1/+8
| | | | | | | | | | | | Although the lisp.h macros really need improvement, INTEGER_TO_INT is not the right way to go about it, as it causes conversion from intmax_t to uintmax_t and back again, which can cause a signal if the value is negative. * src/lisp.h (INTEGER_TO_INT, ranged_integer_to_int) (ranged_integer_to_uint): Remove, reverting recent changes to this file. * src/json.c (lisp_to_json): Revert to previous code, as the change messes up with uintmax_t<->intmax_t conversion.
* Introduce a helper macro to convert a Lisp integer to a C integer.Philipp Stephani2019-04-221-8/+1
| | | | | | | | | | | 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.
* Use eassume (false) for branch that's never taken.Philipp Stephani2019-04-191-1/+1
| | | | | * src/json.c (json_handle_nonlocal_exit): Use eassume (false) since this branch is never taken.
* Fix compilation warning due to a recent changeEli Zaretskii2019-04-191-0/+2
| | | | | * src/json.c (json_handle_nonlocal_exit): Always return a value.
* Refactoring: have CATCHER_ALL also catch signals.Philipp Stephani2019-04-191-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | In all cases where we use a CATCHER_ALL handler we also want to catch signals. Therefore have 'signal' respect CATCHER_ALL. Adapt internal interfaces so that handlers can distinguish among the two types of nonlocal exits in CATCHER_ALL handlers. * src/lisp.h (enum nonlocal_exit): New enum. (struct handler): Add member 'nonlocal_exit' to hold the type of nonlocal exit during stack unwinding. * src/eval.c (signal_or_quit): Also respect CATCHER_ALL handlers. (unwind_to_catch): Store nonlocal exit type in catch structure. (Fthrow, signal_or_quit): Adapt callers. (internal_catch_all): Install only one handler. Give handler a nonlocal exit type argument. (internal_catch_all_1): Remove, no longer needed. * src/emacs-module.c (MODULE_SETJMP): Install only one handler. (module_handle_nonlocal_exit): New function to handle all nonlocal exits. (MODULE_SETJMP_1): Pass nonlocal exit type to handler function. (module_handle_signal, module_handle_throw): Remove, no longer needed. * src/json.c (json_handle_nonlocal_exit): New helper function. (json_insert_callback): Adapt to change in 'internal_catch_all'.
* Mark _Noreturn error functions as coldPaul Eggert2019-04-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On my platform this made ‘make compile-always’ 1.3% faster. Suggested by Alex Gramiak in: https://lists.gnu.org/r/emacs-devel/2019-04/msg00684.html * configure.ac (nw): Don’t use -Wsuggest-attribute=cold. * lib-src/make-docfile.c (write_globals): Mark noreturn functions as cold. * src/callproc.c (exec_failed): * src/data.c (wrong_length_argument, wrong_type_argument): * src/emacs-module.c (module_abort): * src/emacs.c (terminate_due_to_signal): * src/eval.c (unwind_to_catch): * src/image.c (my_png_error, my_error_exit): * src/json.c (json_out_of_memory, json_parse_error): * src/keyboard.c (quit_throw_to_read_char, user_error): * src/lisp.h (die, wrong_type_argument, wrong_choice) (args_out_of_range, args_out_of_range_3, circular_list) (buffer_overflow, memory_full, buffer_memory_full) (string_overflow, xsignal, xsignal0, xsignal1, xsignal2) (xsignal3, signal_error, overflow_error, error, verror) (nsberror, report_file_errno, report_file_error) (report_file_notify_error, terminate_due_to_signal) (emacs_abort, fatal): * src/lread.c (load_error_old_style_backquotes) (end_of_file_error, invalid_syntax): * src/pdumper.c (error_unsupported_dump_object): * src/puresize.h (pure_write_error): * src/search.c (matcher_overflow): * src/sound.c (sound_perror, alsa_sound_perror): * src/sysdep.c (handle_arith_signal): * src/systime.h (time_overflow): * src/term.c (maybe_fatal, vfatal): * src/textprop.c (text_read_only): * src/timefns.c (invalid_time_zone_specification) (time_error, invalid_hz): * src/xterm.c (x_connection_closed): Use AVOID instead of _Noreturn void, so that it’s marked cold. * src/conf_post.h (__has_attribute_cold) [!__has_attribute]: New macro. (ATTRIBUTE_COLD): New macro. * src/frame.h (WINDOW_SYSTEM_RETURN): Add ATTRIBUTE_COLD. * src/lisp.h (AVOID): New macro. * src/xterm.c: Omit unnecessary static decls, so that we needn’t worry about which functions should be marked cold. (x_io_error_quitter): Mark as cold.
* Improve documentation changes of a recent commitEli Zaretskii2019-04-131-10/+32
| | | | | | | * doc/lispref/text.texi (Parsing JSON): Improve wording of the documentation of 'json-parse-string' and 'json-parse-buffer'. * src/json.c (Fjson_parse_string, Fjson_parse_buffer): Doc fix. (Bug#34763)
* Add :array-type option to json-parse-stringDmitry Gutov2019-04-131-13/+65
| | | | | | | | | | | | | * src/json.c (enum json_array_type): New type. (struct json_configuration): New field array_type. (json_parse_args): Rename the last argument. Handle the :array-type keyword argument (bug#32793). (Fjson_parse_string): Update the docstring accordingly. (json_to_lisp): Handle the case of :array-type being `list'. Add a call to 'rarely_quit' inside the loop. (syms_of_json): Define new symbols. (Fjson_serialize, Fjson_insert, Fjson_parse_string) (Fjson_parse_buffer): Update the config struct initializers.
* Fix misuses of NULL when talking about the NUL characterStefan Monnier2019-03-211-9/+9
| | | | | | | | | | | | | | | | | | | | | | * lisp/subr.el (inhibit-null-byte-detection): Make it an obsolete alias. * src/coding.c (setup_coding_system): Use new name. (detect_coding): Rename null_byte_found => nul_byte_found. (detect_coding_system): Use new name. Rename null_byte_found => nul_byte_found. (Fdefine_coding_system_internal): Use new name. (syms_of_coding): Rename inhibit-null-byte-detection to inhibit-nul-byte-detection. * src/w16select.c (get_clipboard_data): null_char => nul_char. * src/json.c (check_string_without_embedded_nuls): Rename from check_string_without_embedded_nulls. (Fjson_parse_string): Adjust accordingly. * src/coding.h (enum define_coding_undecided_arg_index) (enum coding_attr_index): ...null_byte... => ...nul_byte.... * lisp/info.el (info-insert-file-contents, Info-insert-dir): * lisp/international/mule.el (define-coding-system): * lisp/vc/vc-git.el (vc-git--call): * doc/lispref/nonascii.texi (Lisp and Coding Systems): Use the new name.
* Fix integer overflow check in json codePaul Eggert2018-12-311-1/+1
| | | | | * src/json.c (json_to_lisp): Check for ptrdiff_t overflow, not fixnum overflow.
* Update more copyright yearsPaul Eggert2018-12-311-1/+1
| | | | | | | | Update some other copyright years automatically, by running: Run 'UPDATE_COPYRIGHT_YEAR=2019 \ UPDATE_COPYRIGHT_USE_INTERVALS=1 \ UPDATE_COPYRIGHT_MAX_LINE_LENGTH=79 admin/update-copyright' followed by 'admin/merge-gnulib'.
* Add make_vector and make_nil_vectorPaul Eggert2018-12-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes the callers a bit easier to read, and doubtless improves efficiency very slightly. It also simplifies possible future changes to allow bignum indexes to buffers. * src/alloc.c (allocate_vectorlike): Prefer ptrdiff_t to size_t when either will do. (make_vector): New function. (Fmake_vector): Use it. * src/buffer.c (syms_of_buffer): * src/bytecode.c (syms_of_bytecode): * src/category.c (Fmake_category_table, init_category_once): * src/ccl.c (syms_of_ccl): * src/character.c (syms_of_character): * src/charset.c (Fdefine_charset_internal) (Ffind_charset_region, Ffind_charset_string): * src/chartab.c (copy_char_table): * src/coding.c (Fdefine_coding_system_internal, syms_of_coding): * src/composite.c (get_composition_id, Fcomposition_get_gstring): * src/composite.h (LGLYPH_NEW): * src/fns.c (concat, Flocale_info, make_hash_table): * src/font.c (font_otf_ValueRecord, font_otf_anchor) (build_style_table, syms_of_font): * src/fontset.c (RFONT_DEF_NEW, fontset_find_font) (dump_fontset, syms_of_fontset): * src/image.c (xpm_make_color_table_v): * src/keyboard.c (modify_event_symbol, menu_bar_items) (parse_menu_item, parse_tool_bar_item, init_tool_bar_items) (syms_of_keyboard): * src/keymap.c (Fdefine_key, describe_map, describe_vector): * src/lread.c (read_vector): * src/macfont.m (macfont_shape): * src/menu.c (init_menu_items): * src/nsfns.m (ns_make_monitor_attribute_list): * src/process.c (conv_sockaddr_to_lisp, network_interface_info): * src/profiler.c (make_log): * src/window.c (Fcurrent_window_configuration): * src/xdisp.c (with_echo_area_buffer_unwind_data) (format_mode_line_unwind_data): * src/xfaces.c (Finternal_make_lisp_face) (Fface_attributes_as_vector): * src/xfns.c (x_make_monitor_attribute_list) (Fx_display_monitor_attributes_list): * src/xfont.c (syms_of_xfont): * src/xselect.c (x_handle_dnd_message): * src/xwidget.c (save_script_callback): Prefer make_nil_vector (N) to Fmake_vector (make_fixnum (N), Qnil). * src/callint.c (Fcall_interactively): * src/charset.c (load_charset_map): * src/chartab.c (Fmake_char_table, uniprop_encode_value_numeric): * src/composite.c (get_composition_id) * src/dispnew.c (Fframe_or_buffer_changed_p) (syms_of_display): * src/fns.c (make_hash_table, maybe_resize_hash_table): * src/font.c (font_style_to_value): * src/fontset.c (FONTSET_ADD, fontset_add): * src/json.c (json_to_lisp): * src/keymap.c (syms_of_keymap): * src/lread.c (init_obarray): * src/profiler.c (make_log, Fprofiler_cpu_log): * src/term.c (term_get_fkeys_1): Prefer make_vector (N, V) to Fmake_vector (make_fixnum (N), V). * src/font.c (build_style_table): * src/macfont.m (macfont_shape): * src/process.c (conv_sockaddr_to_lisp, network_interface_info): Prefer make_uninit_vector if the vector will be initialized soon. * src/lisp.h (make_nil_vector): New function.
* Improve 'json-insert' so it doesn't cons a string from JSONEli Zaretskii2018-10-131-13/+89
| | | | | | | | | | | | | | | | | | | | * src/json.c (struct json_buffer_and_size): New member inserted_bytes. (json_insert): Instead of creating a string and inserting it into the current buffer, copy the unibyte text into the gap. (struct json_insert_data): New member inserted_bytes. (json_insert_callback): Update commentary. Pass the inserted_bytes value to json_insert and on its return copy the updated value back into DATA. (Fjson_insert): Decode the unibyte text inserted into the gap. Call before-change-functions and after-change-functions only once, before and after processing the insertion of the entire JSON representation. * test/src/json-tests.el (json-insert/throw): Adapt to the modified implementation of json-insert: it no longer calls the modification hooks once for each inserted chunk of JSON representation.
* Use new function overflow_error in a few placesPhilipp Stephani2018-09-211-2/+2
| | | | | | * src/emacs-module.c (module_make_global_ref, module_funcall) (module_make_string, Fmodule_load): * src/json.c (json_to_lisp): Use overflow_error.
* Support bignums when serializing JSONPhilipp Stephani2018-09-211-3/+7
| | | | | * src/json.c (lisp_to_json): Support bignums. * test/src/json-tests.el (json-serialize/bignum): New test.
* Improve bignum support for system typesPaul Eggert2018-08-271-8/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use bignums when Emacs converts to and from system types like off_t for file sizes whose values can exceed fixnum range. Formerly, Emacs sometimes generted floats and sometimes ad-hoc conses of integers. Emacs still accepts floats and conses for these system types, in case some stray Lisp code is generating them, though this usage is obsolescent. * doc/lispref/files.texi (File Attributes): * doc/lispref/hash.texi (Defining Hash): * doc/lispref/nonascii.texi (Character Sets): * doc/lispref/os.texi (User Identification): * doc/lispref/processes.texi (System Processes): * etc/NEWS: Document changes. * src/bignum.c (mpz_set_uintmax, make_biguint) (mpz_set_uintmax_slow, bignum_to_intmax, bignum_to_uintmax): New functions. (mpz_set_intmax_slow): Implement via mpz_limbs_write, to avoid the need for an extra pass through a negative number. * src/charset.c (Fencode_char): * src/composite.h (LGLYPH_SET_CODE): * src/dired.c (file_attributes): * src/dosfns.c, src/w32.c (list_system_processes) (system_process_attributes): * src/editfns.c (init_editfns, Fuser_uid, Fuser_real_uid) (Fgroup_gid, Fgroup_real_gid, Femacs_pid): * src/emacs-module.c (check_vec_index): * src/fns.c (Fsafe_length): * src/process.c (record_deleted_pid, Fprocess_id): * src/sysdep.c (list_system_processes, system_process_attributes): * src/xselect.c (x_own_selection, selection_data_to_lisp_data): * src/xterm.c (set_wm_state): * src/inotify.c (inotifyevent_to_event, add_watch) (inotify_callback): If an integer is out of fixnum range, use a bignum instead of converting it to a float or a cons of integers. * src/coding.c (Fdefine_coding_system_internal): * src/frame.c (frame_windows_min_size) (x_set_frame_parameters): * src/fringe.c (Fdefine_fringe_bitmap): * src/nsterm.m (mouseDown:): * src/syntax.c (find_defun_start): * src/w32fns.c (x_set_undecorated, w32_createwindow) (w32_wnd_proc, Fx_create_frame, Fx_show_tip) (w32_console_toggle_lock_key): * src/w32inevt.c (key_event): * src/w32proc.c (Fw32_get_locale_info): Do not mishandle floats by treating their addresses as their values. * src/data.c (store_symval_forwarding): * src/gnutls.c (Fgnutls_error_fatalp, Fgnutls_error_string): * src/keyboard.c (command_loop_1, make_lispy_event): * src/lread.c (read_filtered_event, read1) (substitute_object_recurse): * src/window.c (Fcoordinates_in_window_p, Fwindow_at) (window_resize_apply, Fset_window_vscroll): * src/xdisp.c (handle_single_display_spec, try_scrolling) (redisplay_window, calc_pixel_width_or_height) (calc_line_height_property, on_hot_spot_p): * src/xfaces.c (check_lface_attrs): * src/xselect.c (x_get_local_selection, cons_to_x_long) (lisp_data_to_selection_data, clean_local_selection_data) (x_check_property_data, x_fill_property_data): (x_send_client_event): Do not reject bignums. * src/data.c (INTBIG_TO_LISP, intbig_to_lisp) (uintbig_to_lisp): Remove. All uses removed. * src/data.c (cons_to_unsigned, cons_to_signed): * src/dbusbind.c (xd_signature, xd_extract_signed) (xd_extract_unsigned): * src/dispnew.c (sit_for): * src/dosfns.c, src/w32.c (system_process_attributes): * src/editfns.c (Fuser_full_name): * src/fileio.c (file_offset): * src/fileio.c (write_region): * src/font.c (font_unparse_xlfd, font_open_for_lface, Fopen_font): * src/frame.c (x_set_screen_gamma): * src/frame.h (NUMVAL, FRAME_PIXEL_X_FROM_CANON_X) (FRAME_PIXEL_Y_FROM_CANON_Y): * src/image.c (parse_image_spec, x_edge_detection) (compute_image_size): * src/json.c (json_to_lisp): * src/lcms.c (PARSE_LAB_LIST_FIELD, Flcms_cie_de2000) (PARSE_XYZ_LIST_FIELD, PARSE_JCH_LIST_FIELD) (PARSE_JAB_LIST_FIELD, PARSE_VIEW_CONDITION_FLOAT) (Flcms_temp_to_white_point): * src/nsimage.m (ns_load_image, setSizeFromSpec): * src/process.c (Fsignal_process, handle_child_signal): * src/sysdep.c (system_process_attributes): * src/xdisp.c (calc_line_height_property): Handle bignums. * src/data.c (Fnumber_to_string): Use proper predicate name in signal if the argument is not a number. * src/lisp.h (make_uint): New function. (INT_TO_INTEGER): New macro. (FIXED_OR_FLOATP, CHECK_FIXNUM_OR_FLOAT) (CHECK_FIXNUM_OR_FLOAT_COERCE_MARKER, INTEGER_TO_CONS) (make_fixnum_or_float): Remove; no longer used. * src/nsfns.m, src/w32fns.c, src/xfns.c (Fx_create_frame): Reject floating-point min-width or min-height. * src/process.c (handle_child_signal): Do not worry about floating-point pids, as they are no longer generated.