aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorPaul Eggert2011-09-21 10:41:20 -0700
committerPaul Eggert2011-09-21 10:41:20 -0700
commitd311d28c3f8a3c43e6ef33d68b852c5ea7f13239 (patch)
tree84b390c8bd472074294a31d51e790437f0a9a75d /src/buffer.c
parent4768be09c9866add356a0a9b47ecd42346442b9f (diff)
downloademacs-d311d28c3f8a3c43e6ef33d68b852c5ea7f13239.tar.gz
emacs-d311d28c3f8a3c43e6ef33d68b852c5ea7f13239.zip
* alloc.c (pure_bytes_used_lisp, pure_bytes_used_non_lisp):
(allocate_vectorlike, buffer_memory_full, struct sdata, SDATA_SIZE) (string_bytes, check_sblock, allocate_string_data): (compact_small_strings, Fmake_bool_vector, make_string) (make_unibyte_string, make_multibyte_string) (make_string_from_bytes, make_specified_string) (allocate_vectorlike, Fmake_vector, find_string_data_in_pure) (make_pure_string, make_pure_c_string, make_pure_vector, Fpurecopy) (mark_vectorlike): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (allocate_pseudovector): Use int, not EMACS_INT, where int is wide enough. (inhibit_garbage_collection, Fgarbage_collect): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * bidi.c (bidi_mirror_char): Use EMACS_INT, not int, where int might not be wide enough. (bidi_cache_search, bidi_cache_find, bidi_init_it) (bidi_count_bytes, bidi_char_at_pos, bidi_fetch_char) (bidi_at_paragraph_end, bidi_find_paragraph_start) (bidi_paragraph_init, bidi_resolve_explicit, bidi_resolve_weak) (bidi_level_of_next_char, bidi_move_to_visually_next): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * buffer.c (copy_overlays, Fgenerate_new_buffer_name) (Fkill_buffer, Fset_buffer_major_mode) (advance_to_char_boundary, Fbuffer_swap_text) (Fset_buffer_multibyte, overlays_at, overlays_in) (overlay_touches_p, struct sortvec, record_overlay_string) (overlay_strings, recenter_overlay_lists) (adjust_overlays_for_insert, adjust_overlays_for_delete) (fix_start_end_in_overlays, fix_overlays_before, modify_overlay) (Fmove_overlay, Fnext_overlay_change, Fprevious_overlay_change) (Foverlay_recenter, last_overlay_modification_hooks_used) (report_overlay_modification, evaporate_overlays, enlarge_buffer_text): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (validate_region): Omit unnecessary test for b <= e, since that's guaranteed by the previous test. (adjust_overlays_for_delete): Avoid pos + length overflow. (Fmove_overlay, Fdelete_overlay, add_overlay_mod_hooklist) (report_overlay_modification): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (Foverlays_at, Fnext_overlay_change, Fprevious_overlay_change): Omit pointer cast, which isn't needed anyway, and doesn't work after the EMACS_INT -> ptrdiff_t change. * buffer.h: Adjust decls to match defn changes elsewhere. (struct buffer_text, struct buffer): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. Use EMACS_INT, not int, where int might not be wide enough. * bytecode.c (exec_byte_code): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. Remove unnecessary memory-full test. Use EMACS_INT, not ptrdiff_t or int, where ptrdiff_t or int might not be wide enough. * callint.c (Fcall_interactively): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * callproc.c (call_process_kill, Fcall_process): Don't assume pid_t fits into an Emacs fixnum. (call_process_cleanup, Fcall_process, child_setup): Don't assume pid_t fits into int. (call_process_cleanup, Fcall_process, delete_temp_file) (Fcall_process_region): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (Fcall_process): Simplify handling of volatile integers. Use int, not EMACS_INT, where int will do. * casefiddle.c (casify_object, casify_region, operate_on_word) (Fupcase_word, Fdowncase_word, Fcapitalize_word): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (casify_object): Avoid integer overflow when overallocating buffer. * casetab.c (set_identity, shuffle): Prefer int to unsigned when either works. * category.c (Fchar_category_set): Don't assume fixnum fits in int. * category.h (CATEGORYP): Don't assume arg is nonnegative. * ccl.c (GET_CCL_INT): Remove; no longer needed, since the integers are now checked earlier. All uses replaced with XINT. (ccl_driver): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. For CCL_MapSingle, check that content and value are in int range. (resolve_symbol_ccl_program): Check that vector header is in range. Always copy the vector, so that we can check its contents reliably now rather than having to recheck each instruction as it's being executed. Check that vector words fit in 'int'. (ccl_get_compiled_code, Fregister_ccl_program) (Fregister_code_conversion_map): Use ptrdiff_t, not int, for program indexes, to avoid needless 32-bit limit on 64-bit hosts. (Fccl_execute, Fccl_execute_on_string): Check that initial reg contents are in range. (Fccl_execute_on_string): Check that status is in range. * ccl.h (struct ccl_program.idx): Now ptrdiff_t, not int. * character.c (char_resolve_modifier_mask, Fchar_resolve_modifiers): Accept and return EMACS_INT, not int, because callers can pass values out of 'int' range. (c_string_width, strwidth, lisp_string_width, chars_in_text) (multibyte_chars_in_text, parse_str_as_multibyte) (str_as_multibyte, count_size_as_multibyte, str_to_multibyte) (str_as_unibyte, str_to_unibyte, string_count_byte8) (string_escape_byte8, Fget_byte): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Funibyte_string): Use CHECK_CHARACTER, not CHECK_NATNUM, to avoid mishandling large integers. * character.h: Adjust decls to match defn changes elsewhere. * charset.c (load_charset_map_from_file, find_charsets_in_text) (Ffind_charset_region): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (load_charset_map_from_file): Redo idx calculation to avoid overflow. (load_charset_map_from_vector, Fdefine_charset_internal): Don't assume fixnum fits in int or unsigned int. (load_charset_map_from_vector, Fmap_charset_chars): Remove now-unnecessary CHECK_NATNUMs. (Fdefine_charset_internal): Check ranges here, more carefully. * chartab.c (Fmake_char_table, Fset_char_table_range) (uniprop_get_decoder, uniprop_get_encoder): Don't assume fixnum fits in int. * cmds.c (move_point): New function, that does the gist of Fforward_char and Fbackward_char, but does so while checking for integer overflow more accurately. (Fforward_char, Fbackward_char, internal_self_insert): Use it. (Fforward_line, Fend_of_line, internal_self_insert) (internal_self_insert): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. Fix a FIXME, by checking for integer overflow when calculating target_clm and actual_clm. * coding.c (detect_coding_XXX, encode_coding_XXX, CODING_DECODE_CHAR) (ASSURE_DESTINATION, coding_alloc_by_realloc) (coding_alloc_by_making_gap, alloc_destination) (detect_coding_utf_8, encode_coding_utf_8, decode_coding_utf_16) (encode_coding_utf_16, detect_coding_emacs_mule) (decode_coding_emacs_mule, encode_coding_emacs_mule) (detect_coding_iso_2022, decode_coding_iso_2022) (encode_invocation_designation, encode_designation_at_bol) (encode_coding_iso_2022, detect_coding_sjis, detect_coding_big5) (decode_coding_sjis, decode_coding_big5, encode_coding_sjis) (encode_coding_big5, detect_coding_ccl, decode_coding_ccl) (encode_coding_ccl, encode_coding_raw_text) (detect_coding_charset, decode_coding_charset) (encode_coding_charset, detect_eol, decode_eol, produce_chars) (produce_composition, produce_charset, produce_annotation) (decode_coding, handle_composition_annotation) (handle_charset_annotation, consume_chars, decode_coding_gap) (decode_coding_object, encode_coding_object, detect_coding_system) (Ffind_coding_systems_region_internal, Fcheck_coding_systems_region) (code_convert_region, code_convert_string) (Fdefine_coding_system_internal): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (setup_iso_safe_charsets, consume_chars, Funencodable_char_position) (Fdefine_coding_system_internal): Don't assume fixnums fit in int. (decode_coding_gap, decode_coding_object, encode_coding_object) (Fread_coding_system, Fdetect_coding_region, Funencodable_char_position) (Fcheck_coding_systems_region): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (Ffind_operation_coding_system): NATNUMP can eval its arg twice. (Fdefine_coding_system_internal): Check for charset-id overflow. * coding.h: Adjust decls to match defn changes elsewhere. (struct coding_system): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * composite.c (get_composition_id, find_composition) (run_composition_function, update_compositions) (compose_text, composition_gstring_put_cache) (composition_gstring_p, composition_gstring_width) (fill_gstring_header, fill_gstring_body, autocmp_chars) (composition_compute_stop_pos, composition_reseat_it) (composition_update_it, struct position_record) (find_automatic_composition, composition_adjust_point) (Fcomposition_get_gstring, Ffind_composition_internal): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (update_compositions): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * composite.h: Adjust decls to match defn changes elsewhere. (struct composition): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * data.c (let_shadows_buffer_binding_p, let_shadows_global_binding_p): Do not attempt to compute the address of the object just before a buffer; this is not portable. (Faref, Faset): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Faset): Use int, not EMACS_INT, where int is wide enough. (Fstring_to_number): Don't assume fixnums fit in int. (Frem): Don't assume arg is nonnegative. * dbusbind.c (xd_append_arg): Check for integers out of range. (Fdbus_call_method): Don't overflow the timeout int. * dired.c (directory_files_internal, file_name_completion, scmp) (file_name_completion_stat): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (file_name_completion): Don't overflow matchcount. (file_name_completion_stat): Use SAFE_ALLOCA, not alloca. * dispextern.h: Adjust decls to match defn changes elsewhere. (struct text_pos, struct glyph, struct bidi_saved_info) (struct bidi_string_data, struct bidi_it, struct composition_it) (struct it): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (struct display_pos, struct composition_it, struct it): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * dispnew.c (increment_matrix_positions) (increment_row_positions, mode_line_string) (marginal_area_string): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (change_frame_size_1, Fredisplay): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (duration_to_sec_usec): New function, to check for overflow better. (Fsleep_for, sit_for): Use it. * doc.c (get_doc_string, store_function_docstring): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (get_doc_string, Fsnarf_documentation): Use int, not EMACS_INT, where int is wide enough. (get_doc_string): Use SAFE_ALLOCA, not alloca. Check for overflow when converting EMACS_INT to off_t. * doprnt.c (doprnt): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * editfns.c (init_editfns, Fuser_uid, Fuser_real_uid): Don't assume uid_t fits into fixnum. (buildmark, Fgoto_char, overlays_around, find_field, Fdelete_field) (Ffield_string, Ffield_string_no_properties, Ffield_beginning) (Ffield_end, Fconstrain_to_field, Fline_beginning_position) (Fline_end_position, Fprevious_char, Fchar_after, Fchar_before) (general_insert_function) (Finsert_char, make_buffer_string, make_buffer_string_both) (update_buffer_properties, Fbuffer_substring) (Fbuffer_substring_no_properties, Fcompare_buffer_substrings) (Fsubst_char_in_region, check_translation) (Ftranslate_region_internal, save_restriction_restore, Fformat) (transpose_markers, Ftranspose_regions): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (clip_to_bounds): Move to lisp.h as an inline function). (Fconstrain_to_field): Don't assume integers are nonnegative. (Fline_beginning_position, Fsave_excursion, Fsave_current_buffer): (Fsubst_char_in_region, Fsave_restriction): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (Femacs_pid): Don't assume pid_t fits into fixnum. (lo_time): Use int, not EMACS_INT, when int suffices. (lisp_time_argument): Check for usec out of range. (Fencode_time): Don't assume fixnum fits in int. * emacs.c (gdb_valbits, gdb_gctypebits): Now int, not EMACS_INT. (gdb_data_seg_bits): Now uintptr_t, not EMACS_INT. (PVEC_FLAG, gdb_array_mark_flag): Now ptrdiff_t, not EMACS_INT. (init_cmdargs, Fdump_emacs): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (Fkill_emacs): Don't assume fixnum fits in int; instead, take just the bottom (typically) 32 bits of the fixnum. * eval.c (specpdl_size, call_debugger): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (when_entered_debugger, Fbacktrace_debug): Don't assume fixnum can fit in int. (Fdefvaralias, Fdefvar): Do not attempt to compute the address of the object just before a buffer; this is not portable. (FletX, Flet, Funwind_protect, do_autoload, Feval, funcall_lambda) (grow_specpdl, unbind_to): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (Fapply, apply_lambda): Don't assume ptrdiff_t can hold fixnum. (grow_specpdl): Simplify allocation by using xpalloc. * fileio.c (Ffind_file_name_handler, Fcopy_file, Frename_file) (Finsert_file_contents, Fwrite_region, Fdo_auto_save): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (Ffind_file_name_handler, non_regular_inserted, Finsert_file_contents) (a_write, e_write): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Fcopy_file, non_regular_nbytes, read_non_regular) (Finsert_file_contents): Use int, not EMACS_INT, where int is wide enough. (READ_BUF_SIZE): Verify that it fits in int. (Finsert_file_contents): Check that counts are in proper range, rather than assuming fixnums fit into ptrdiff_t etc. Don't assume fixnums fit into int. (Fdo_auto_save, Fset_buffer_auto_saved) (Fclear_buffer_auto_save_failure): Don't assume time_t is signed, or that it fits in int. * fns.c (Fcompare_strings, Fstring_lessp, struct textprop_rec) (concat, string_char_byte_cache_charpos, string_char_byte_cache_bytepos) (string_char_to_byte, string_byte_to_char) (string_make_multibyte, string_to_multibyte) (string_make_unibyte, Fstring_as_unibyte, Fstring_as_multibyte) (Fstring_to_unibyte, Fsubstring, Fsubstring_no_properties) (substring_both, Fdelete, internal_equal, Ffillarray) (Fclear_string, mapcar1) (Fbase64_encode_region, Fbase64_encode_string, base64_encode_1) (Fbase64_decode_region, Fbase64_decode_string, base64_decode_1) (larger_vector, make_hash_table, maybe_resize_hash_table) (hash_lookup, hash_remove_from_table, hash_clear, sweep_weak_table) (Fmaphash, secure_hash): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (concat): Check for string index and length overflow. (Fmapconcat): Don't assume fixnums fit into ptrdiff_t. (Frequire): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (larger_vector): New API (vec, incr_min, size_max) replaces old one (vec, new_size, init). This catches size overflow. INIT was removed because it was always Qnil. All callers changed. (INDEX_SIZE_BOUND): New macro, which calculates more precisely the upper bound on a hash table index size. (make_hash_table, maybe_resize_hash_table): Use it. (secure_hash): Computer start_byte and end_byte only after they're known to be in ptrdiff_t range. * font.c (font_intern_prop, font_at, font_range, Ffont_shape_gstring) (Ffont_get_glyphs, Ffont_at): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (font_style_to_value, font_prop_validate_style, font_expand_wildcards) (Flist_fonts, Fopen_font): Don't assume fixnum can fit in int. (check_gstring): Don't assume index can fit in int. (font_match_p): Check that fixnum is a character, not a nonnegative fixnum, since the later code needs to stuff it into an int. (font_find_for_lface): Use SAFE_ALLOCA_LISP, not alloca. (font_fill_lglyph_metrics): Use unsigned, not EMACS_INT, to avoid conversion overflow issues. (Fopen_font): Check for integer out of range. (Ffont_get_glyphs): Don't assume index can fit in int. * font.h: Adjust decls to match defn changes elsewhere. * fontset.c (reorder_font_vector): Redo score calculation to avoid integer overflow. (num_auto_fontsets, fontset_from_font): Use ptrdiff_t, not printmax_t, where ptrdiff_t is wide enough. (Finternal_char_font): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * frame.c (Fset_mouse_position, Fset_mouse_pixel_position) (Fset_frame_height, Fset_frame_width, Fset_frame_size) (Fset_frame_position, x_set_frame_parameters) (x_set_line_spacing, x_set_border_width) (x_set_internal_border_width, x_set_alpha, x_figure_window_size): Check that fixnums are in proper range for system types. (frame_name_fnn_p, Fframe_parameter, Fmodify_frame_parameters): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Fmodify_frame_parameters): Don't assume fixnum fits in int. Use SAFE_ALLOCA_LISP, not alloca. * frame.h (struct frame): Use intptr_t, not EMACS_INT, where intptr_t is wide enough. * fringe.c (lookup_fringe_bitmap, get_logical_fringe_bitmap) (Fdefine_fringe_bitmap): Don't assume fixnum fits in int. (Ffringe_bitmaps_at_pos): Don't assume index fits in int. Check for fixnum out of range. * ftfont.c (ftfont_list): Don't assume index fits in int. Check that fixnums are in proper range for system types. (ftfont_shape_by_flt): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. Remove no-longer-needed lint_assume. * gnutls.c (emacs_gnutls_write, emacs_gnutls_read): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Fgnutls_error_fatalp, Fgnutls_error_string, Fgnutls_boot): Check that fixnums are in proper range for system types. * gnutls.h: Adjust decls to match defn changes elsewhere. * gtkutil.c (xg_dialog_run): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (update_frame_tool_bar): Check that fixnums are in proper range for system types. * image.c (parse_image_spec): Redo count calculation to avoid overflow. (lookup_image): Check that fixnums are in proper range for system types. * indent.c (last_known_column, last_known_column_point): (current_column_bol_cache): (skip_invisible, current_column, check_display_width): (check_display_width, scan_for_column, current_column_1) (Findent_to, Fcurrent_indentation, position_indentation) (indented_beyond_p, Fmove_to_column, compute_motion): (Fcompute_motion, Fvertical_motion): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (last_known_column_modified): Use EMACS_INT, not int. (check_display_width): (Fcompute_motion): Check that fixnums and floats are in proper range for system types. (compute_motion): Don't assume index or fixnum fits in int. (compute_motion, Fcompute_motion): Use int, not EMACS_INT, when it is wide enough. (vmotion): Omit local var start_hpos that is always 0; that way we don't need to worry about overflow in expressions involving it. * indent.h: Adjust decls to match defn changes elsewhere. (struct position): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. Use int, not EMACS_INT, where int is wide enough. Remove unused members ovstring_chars_done and tab_offset; all uses removed. * insdel.c (move_gap, move_gap_both, gap_left, gap_right) (adjust_markers_for_delete, adjust_markers_for_insert, adjust_point) (adjust_markers_for_replace, make_gap_larger, make_gap_smaller) (make_gap, copy_text, insert, insert_and_inherit) (insert_before_markers, insert_before_markers_and_inherit) (insert_1, count_combining_before, count_combining_after) (insert_1_both, insert_from_string) (insert_from_string_before_markers, insert_from_string_1) (insert_from_gap, insert_from_buffer, insert_from_buffer_1) (adjust_after_replace, adjust_after_insert, replace_range) (replace_range_2, del_range, del_range_1, del_range_byte) (del_range_both, del_range_2, modify_region) (prepare_to_modify_buffer, signal_before_change) (signal_after_change, Fcombine_after_change_execute): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * intervals.c (traverse_intervals, rotate_right, rotate_left) (balance_an_interval, split_interval_right, split_interval_left) (find_interval, next_interval, update_interval) (adjust_intervals_for_insertion, delete_node, delete_interval) (interval_deletion_adjustment, adjust_intervals_for_deletion) (static_offset_intervals, offset_intervals) (merge_interval_right, merge_interval_left, make_new_interval) (graft_intervals_into_buffer, temp_set_point_both) (temp_set_point, set_point, adjust_for_invis_intang) (set_point_both, move_if_not_intangible, get_property_and_range) (get_local_map, copy_intervals, copy_intervals_to_string) (compare_string_intervals, set_intervals_multibyte_1): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * intervals.h: Adjust decls to match defn changes elsewhere. (struct interval): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * keyboard.c (this_command_key_count, this_single_command_key_start) (before_command_key_count, before_command_echo_length, echo_now) (echo_length, recursive_edit_1, Frecursive_edit, Ftrack_mouse) (command_loop_1, safe_run_hooks, read_char, timer_check_2) (menu_item_eval_property, read_key_sequence, Fread_key_sequence) (Fread_key_sequence_vector, Fexecute_extended_command, Fsuspend_emacs): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (last_non_minibuf_size, last_point_position, echo_truncate) (command_loop_1, adjust_point_for_property, read_char, gen_help_event) (make_lispy_position, make_lispy_event, parse_modifiers_uncached) (parse_modifiers, modify_event_symbol, Fexecute_extended_command) (stuff_buffered_input): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (last_auto_save, command_loop_1, read_char): Use EMACS_INT, not int, to avoid integer overflow. (record_char): Avoid overflow in total_keys computation. (parse_modifiers_uncached): Redo index calculation to avoid overflow. * keyboard.h: Adjust decls to match defn changes elsewhere. * keymap.c (Fdefine_key, Fcurrent_active_maps, accessible_keymaps_1) (Fkey_description, Fdescribe_vector, Flookup_key): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (click_position): New function, to check that positions are in range. (Fcurrent_active_maps): (describe_command): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Faccessible_keymaps, Fkey_description): (preferred_sequence_p): Don't assume fixnum can fit into int. (Fkey_description): Use SAFE_ALLOCA_LISP, not alloca. Check for integer overflow in size calculations. (Ftext_char_description): Use CHECK_CHARACTER, not CHECK_NUMBER, to avoid mishandling large integers. * lisp.h: Adjust decls to match defn changes elsewhere. (ARRAY_MARK_FLAG, PSEUDOVECTOR_FLAG, struct Lisp_String) (struct vectorlike_header, struct Lisp_Subr, struct Lisp_Hash_Table) (struct Lisp_Marker): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (clip_to_bounds): Now an inline function, moved here from editfns.c. (XSETSUBR): Use size of 0 since the actual size doesn't matter, and using 0 avoids overflow. (GLYPH_CODE_P): Check for overflow in system types, subsuming the need for GLYPH_CODE_CHAR_VALID_P and doing proper checking ourselves. All callers changed. (GLYPH_CODE_CHAR, GLYPH_CODE_FACE): Assume the arg has valid form, since it always does. (TYPE_RANGED_INTEGERP): Avoid bug when checking against a wide unsigned integer system type. (CHECK_RANGED_INTEGER, CHECK_TYPE_RANGED_INTEGER): New macros. (struct catchtag, specpdl_size, SPECPDL_INDEX, USE_SAFE_ALLOCA): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (struct catchtag): Use EMACS_INT, not int, since it may be a fixnum. (duration_to_sec_usec): New decl. * lread.c (read_from_string_index, read_from_string_index_byte) (read_from_string_limit, readchar, unreadchar, openp) (read_internal_start, read1, oblookup): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Fload, readevalloop, Feval_buffer, Feval_region): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (openp): Check for out-of-range argument to 'access'. (read1): Use int, not EMACS_INT, where int is wide enough. Don't assume fixnum fits into int. * macros.c (Fstart_kbd_macro): Use xpalloc to check for overflow in size calculation. (Fexecute_kbd_macro): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * marker.c (cached_charpos, cached_bytepos, CONSIDER) (byte_char_debug_check, buf_charpos_to_bytepos, verify_bytepos) (buf_bytepos_to_charpos, Fset_marker, set_marker_restricted) (set_marker_both, set_marker_restricted_both, marker_position) (marker_byte_position, Fbuffer_has_markers_at): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Fset_marker, set_marker_restricted): Don't assume fixnum fits in int. * menu.c (ensure_menu_items): Renamed from grow_menu_items. It now merely ensures that the menu is large enough, without necessarily growing it, as this avoids some integer overflow issues. All callers changed. (keymap_panes, parse_single_submenu, Fx_popup_menu): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (parse_single_submenu, Fx_popup_menu): Don't assume fixnum fits in int. Use SAFE_ALLOCA_LISP, not alloca. (find_and_return_menu_selection): Avoid unnecessary casts of pointers to EMACS_INT. Check that fixnums are in proper range for system types. * minibuf.c (minibuf_prompt_width, string_to_object) (Fminibuffer_contents, Fminibuffer_contents_no_properties) (Fminibuffer_completion_contents, Ftry_completion, Fall_completions): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (get_minibuffer, read_minibuf_unwind): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (read_minibuf): Omit unnecessary arg BACKUP_N, which is always nil; this simplifies overflow checking. All callers changed. (read_minibuf, Fread_buffer, Ftry_completion, Fall_completions) (Ftest_completion): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * nsfns.m (check_ns_display_info): Don't assume fixnum fits in long. (x_set_menu_bar_lines, x_set_tool_bar_lines, Fx_create_frame): Check that fixnums are in proper range for system types. (Fx_create_frame, Fx_show_tip): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * nsfont.m (ns_findfonts, nsfont_list_family): Don't assume fixnum fits in long. * nsmenu.m (ns_update_menubar, ns_menu_show, ns_popup_dialog): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (ns_update_menubar): Use intptr_t, not EMACS_INT, when intptr_t is wide enough. * nsselect.m (ns_get_local_selection): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * print.c (print_buffer_size, print_buffer_pos, print_buffer_pos_byte) (PRINTDECLARE, PRINTPREPARE): (strout, print_string): (print, print_preprocess, print_check_string_charset_prop) (print_object): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (PRINTDECLARE): (temp_output_buffer_setup, Fprin1_to_string, print_object): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (PRINTPREPARE): Use int, not ptrdiff_t, where int is wide enough. (PRINTFINISH): Use SAFE_ALLOCA, not alloca. (printchar, strout): Use xpalloc to catch size calculation overflow. (Fexternal_debugging_output): Use CHECK_CHARACTER, not CHECK_NUMBER, to avoid mishandling large integers. (print_error_message): Use SAFE_ALLOCA, not alloca. (print_object): Use int, not EMACS_INT, where int is wide enough. * process.c (Fdelete_process): Don't assume pid fits into EMACS_INT. (Fset_process_window_size, Fformat_network_address) (get_lisp_to_sockaddr_size, set_socket_option, Fmake_network_process) (Fsignal_process, sigchld_handler): Check that fixnums are in proper range for system types. (Fformat_network_address, read_process_output, send_process) (Fprocess_send_region, status_notify): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Fformat_network_address, Fmake_serial_process, Fmake_network_process) (wait_reading_process_output, read_process_output, exec_sentinel): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (conv_lisp_to_sockaddr): Don't assume fixnums fit into int. (Faccept_process_output): Use duration_to_sec_usec to do proper overflow checking on durations. * scroll.c (calculate_scrolling, calculate_direct_scrolling) (line_ins_del): Use int, not EMACS_INT, where int is wide enough. * search.c (looking_at_1, string_match_1): (fast_string_match, fast_c_string_match_ignore_case) (fast_string_match_ignore_case, fast_looking_at, scan_buffer) (scan_newline, find_before_next_newline, search_command) (trivial_regexp_p, search_buffer, simple_search, boyer_moore) (set_search_regs, wordify): (Freplace_match): (Fmatch_data): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (string_match_1, search_buffer, set_search_regs): (Fmatch_data): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (wordify): Check for overflow in size calculation. (Freplace_match): Avoid potential buffer overflow in search_regs.start. (Fset_match_data): Don't assume fixnum fits in ptrdiff_t. Check that fixnums are in proper range for system types. * sound.c (struct sound_device) (wav_play, au_play, vox_write, alsa_period_size, alsa_write): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Fplay_sound_internal): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * syntax.c (ST_COMMENT_STYLE, ST_STRING_STYLE): In definitions, make it clearer that these values must be out of range for the respective integer ranges. This fixes a bug with ST_STRING_STYLE and non-ASCII characters. (struct lisp_parse_state, find_start_modiff) (Finternal_describe_syntax_value, scan_lists, scan_sexps_forward): (Fparse_partial_sexp): Don't assume fixnums can fit in int. (struct lisp_parse_state, find_start_pos, find_start_value) (find_start_value_byte, find_start_begv) (update_syntax_table, char_quoted, dec_bytepos) (find_defun_start, prev_char_comend_first, back_comment): (scan_words, skip_chars, skip_syntaxes, forw_comment, Fforward_comment) (scan_lists, Fbackward_prefix_chars, scan_sexps_forward): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Finternal_describe_syntax_value): Check that match_lisp is a character, not an integer, since the code stuffs it into int. (scan_words, scan_sexps_forward): Check that fixnums are in proper range for system types. (Fforward_word): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (scan_sexps_forward): Use CHARACTERP, not INTEGERP, since the value must fit into int. (Fparse_partial_sexp): Fix doc; element 8 is not ignored. * syntax.h: Adjust decls to match defn changes elsewhere. (struct gl_state_s): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * sysdep.c (wait_for_termination_1, wait_for_termination) (interruptible_wait_for_termination, mkdir): Don't assume pid_t fits in int; on 64-bit AIX pid_t is 64-bit. (emacs_read, emacs_write): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (system_process_attributes): Don't assume uid_t, gid_t, and double all fit in int or even EMACS_INT. * term.c (set_tty_color_mode): Check that fixnums are in proper range for system types. * termhooks.h (struct input_event): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * textprop.c (validate_interval_range, interval_of) (Fadd_text_properties, set_text_properties_1) (Fremove_text_properties, Fremove_list_of_text_properties) (Ftext_property_any, Ftext_property_not_all) (copy_text_properties, text_property_list, extend_property_ranges) (verify_interval_modification): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Fnext_single_char_property_change) (Fprevious_single_char_property_change): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (copy_text_properties): Check for integer overflow in index calculation. * undo.c (last_boundary_position, record_point, record_insert) (record_delete, record_marker_adjustment, record_change) (record_property_change): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (truncate_undo_list, Fprimitive_undo): Don't assume fixnum fits in int. Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * w32fns.c (Fx_create_frame, x_create_tip_frame, Fx_show_tip) (Fx_hide_tip, Fx_file_dialog): * w32menu.c (set_frame_menubar): Use ptrdiff_t, not int, for consistency with rest of code. * window.c (window_scroll_preserve_hpos, window_scroll_preserve_vpos) (select_window, Fdelete_other_windows_internal) (window_scroll_pixel_based, window_scroll_line_based) (Frecenter, Fset_window_configuration): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (Fset_window_hscroll, run_window_configuration_change_hook) (set_window_buffer, temp_output_buffer_show, scroll_command) (Fscroll_other_window): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (Fwindow_line_height, window_scroll, Fscroll_left, Fscroll_right): Don't assume fixnum fits in int. (Fset_window_scroll_bars): Check that fixnums are in proper range for system types. * xdisp.c (help_echo_pos, pos_visible_p, string_pos_nchars_ahead) (string_pos, c_string_pos, number_of_chars, init_iterator) (in_ellipses_for_invisible_text_p, init_from_display_pos) (compute_stop_pos, next_overlay_change, compute_display_string_pos) (compute_display_string_end, handle_face_prop) (face_before_or_after_it_pos, handle_invisible_prop, handle_display_prop) (handle_display_spec, handle_single_display_spec) (display_prop_intangible_p, string_buffer_position_lim) (string_buffer_position, handle_composition_prop, load_overlay_strings) (get_overlay_strings_1, get_overlay_strings) (iterate_out_of_display_property, forward_to_next_line_start) (back_to_previous_visible_line_start, reseat, reseat_to_string) (get_next_display_element, set_iterator_to_next) (get_visually_first_element, compute_stop_pos_backwards) (handle_stop_backwards, next_element_from_buffer) (move_it_in_display_line_to, move_it_in_display_line) (move_it_to, move_it_vertically_backward, move_it_by_lines) (add_to_log, message_dolog, message_log_check_duplicate) (message2, message2_nolog, message3, message3_nolog (with_echo_area_buffer, display_echo_area_1, resize_mini_window_1) (current_message_1, truncate_echo_area, truncate_message_1) (set_message, set_message_1, store_mode_line_noprop) (hscroll_window_tree, debug_delta, debug_delta_bytes, debug_end_vpos) (text_outside_line_unchanged_p, check_point_in_composition) (reconsider_clip_changes) (redisplay_internal, set_cursor_from_row, try_scrolling) (try_cursor_movement, set_vertical_scroll_bar, redisplay_window) (redisplay_window, find_last_unchanged_at_beg_row) (find_first_unchanged_at_end_row, row_containing_pos, try_window_id) (trailing_whitespace_p, find_row_edges, display_line) (RECORD_MAX_MIN_POS, Fcurrent_bidi_paragraph_direction) (display_mode_element, store_mode_line_string) (pint2str, pint2hrstr, decode_mode_spec) (display_count_lines, display_string, draw_glyphs) (x_produce_glyphs, x_insert_glyphs) (rows_from_pos_range, mouse_face_from_buffer_pos) (fast_find_string_pos, mouse_face_from_string_pos) (note_mode_line_or_margin_highlight, note_mouse_highlight): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (safe_call, init_from_display_pos, handle_fontified_prop) (handle_single_display_spec, load_overlay_strings) (with_echo_area_buffer, setup_echo_area_for_printing) (display_echo_area, echo_area_display) (x_consider_frame_title, prepare_menu_bars, update_menu_bar) (update_tool_bar, hscroll_window_tree, redisplay_internal) (redisplay_window, dump_glyph_row, display_mode_line, Fformat_mode_line) (decode_mode_spec, on_hot_spot_p): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (handle_single_display_spec, build_desired_tool_bar_string) (redisplay_tool_bar, scroll_window_tree, Fdump_glyph_matrix) (get_specified_cursor_type): Check that fixnums are in proper range for system types. (struct overlay_entry, resize_mini_window, Fdump_glyph_row) (Flookup_image_map): Don't assume fixnums fit in int. (compare_overlay_entries): Avoid mishandling comparisons due to subtraction overflow. (load_overlay_strings): Use SAFE_NALLOCA, not alloca. (last_escape_glyph_face_id, last_glyphless_glyph_face_id): (handle_tool_bar_click): Use int, not unsigned, since we prefer signed and the signedness doesn't matter here. (get_next_display_element, next_element_from_display_vector): Use int, not EMACS_INT, when int is wide enough. (start_hourglass): Use duration_to_sec_usec to do proper overflow checking on durations. * xfaces.c (Fbitmap_spec_p): Check that fixnums are in proper range for system types. (compare_fonts_by_sort_order): Avoid mishandling comparisons due to subtraction overflow. (Fx_family_fonts, realize_basic_faces): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (Fx_family_fonts): Don't assume fixnum fits in int. Use SAFE_ALLOCA_LISP, not alloca. (merge_face_heights): Remove unnecessary cast to EMACS_INT. (Finternal_make_lisp_face): Don't allocate more than MAX_FACE_ID. (face_at_buffer_position, face_for_overlay_string) (face_at_string_position): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. (merge_faces): Use int, not EMACS_INT, where int is wide enough. * xfns.c (x_set_menu_bar_lines, x_set_tool_bar_lines, x_icon_verify) (Fx_show_tip): Check that fixnums are in proper range for system types. (Fx_create_frame, x_create_tip_frame, Fx_show_tip) (Fx_hide_tip, Fx_file_dialog, Fx_select_font): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (Fx_change_window_property): Don't assume fixnums fit in int. * xfont.c (xfont_chars_supported): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * xmenu.c (Fx_popup_dialog, set_frame_menubar) (create_and_show_popup_menu, create_and_show_dialog, xmenu_show): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * xml.c (parse_region): * xrdb.c (magic_file_p): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. * xselect.c (TRACE1): Don't assume pid_t promotes to int. (x_get_local_selection, x_reply_selection_request) (x_handle_selection_request, wait_for_property_change): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. (selection_data_to_lisp_data): Use short, not EMACS_INT, where short is wide enough. (x_send_client_event): Don't assume fixnum fits in int. * xterm.c (x_x_to_emacs_modifiers): Don't assume EMACS_INT overflows nicely into int. (x_emacs_to_x_modifiers): Use EMACS_INT, not int, because values may come from Lisp. (handle_one_xevent): NATNUMP can eval its arg twice. (x_connection_closed): Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts. * xterm.h: Adjust decls to match defn changes elsewhere. (struct scroll_bar): Use struct vectorlike_header rather than rolling our own approximation. (SCROLL_BAR_VEC_SIZE): Remove; not used.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c186
1 files changed, 95 insertions, 91 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 37d2975c8c7..564dab689cd 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -155,7 +155,7 @@ Lisp_Object Qinsert_behind_hooks;
155static void alloc_buffer_text (struct buffer *, ptrdiff_t); 155static void alloc_buffer_text (struct buffer *, ptrdiff_t);
156static void free_buffer_text (struct buffer *b); 156static void free_buffer_text (struct buffer *b);
157static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); 157static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *);
158static void modify_overlay (struct buffer *, EMACS_INT, EMACS_INT); 158static void modify_overlay (struct buffer *, ptrdiff_t, ptrdiff_t);
159static Lisp_Object buffer_lisp_local_variables (struct buffer *); 159static Lisp_Object buffer_lisp_local_variables (struct buffer *);
160 160
161/* For debugging; temporary. See set_buffer_internal. */ 161/* For debugging; temporary. See set_buffer_internal. */
@@ -423,7 +423,7 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
423 for (; list; list = list->next) 423 for (; list; list = list->next)
424 { 424 {
425 Lisp_Object overlay, start, end, old_overlay; 425 Lisp_Object overlay, start, end, old_overlay;
426 EMACS_INT charpos; 426 ptrdiff_t charpos;
427 427
428 XSETMISC (old_overlay, list); 428 XSETMISC (old_overlay, list);
429 charpos = marker_position (OVERLAY_START (old_overlay)); 429 charpos = marker_position (OVERLAY_START (old_overlay));
@@ -724,7 +724,7 @@ reset_buffer (register struct buffer *b)
724 b->prevent_redisplay_optimizations_p = 1; 724 b->prevent_redisplay_optimizations_p = 1;
725 BVAR (b, backed_up) = Qnil; 725 BVAR (b, backed_up) = Qnil;
726 BUF_AUTOSAVE_MODIFF (b) = 0; 726 BUF_AUTOSAVE_MODIFF (b) = 0;
727 b->auto_save_failure_time = -1; 727 b->auto_save_failure_time = 0;
728 BVAR (b, auto_save_file_name) = Qnil; 728 BVAR (b, auto_save_file_name) = Qnil;
729 BVAR (b, read_only) = Qnil; 729 BVAR (b, read_only) = Qnil;
730 b->overlays_before = NULL; 730 b->overlays_before = NULL;
@@ -858,8 +858,8 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
858 (register Lisp_Object name, Lisp_Object ignore) 858 (register Lisp_Object name, Lisp_Object ignore)
859{ 859{
860 register Lisp_Object gentemp, tem; 860 register Lisp_Object gentemp, tem;
861 EMACS_INT count; 861 ptrdiff_t count;
862 char number[INT_BUFSIZE_BOUND (EMACS_INT) + sizeof "<>"]; 862 char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
863 863
864 CHECK_STRING (name); 864 CHECK_STRING (name);
865 865
@@ -873,7 +873,7 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
873 count = 1; 873 count = 1;
874 while (1) 874 while (1)
875 { 875 {
876 sprintf (number, "<%"pI"d>", ++count); 876 sprintf (number, "<%"pD"d>", ++count);
877 gentemp = concat2 (name, build_string (number)); 877 gentemp = concat2 (name, build_string (number));
878 tem = Fstring_equal (gentemp, ignore); 878 tem = Fstring_equal (gentemp, ignore);
879 if (!NILP (tem)) 879 if (!NILP (tem))
@@ -1475,7 +1475,7 @@ with SIGHUP. */)
1475 1475
1476 /* Run hooks with the buffer to be killed the current buffer. */ 1476 /* Run hooks with the buffer to be killed the current buffer. */
1477 { 1477 {
1478 int count = SPECPDL_INDEX (); 1478 ptrdiff_t count = SPECPDL_INDEX ();
1479 Lisp_Object arglist[1]; 1479 Lisp_Object arglist[1];
1480 1480
1481 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 1481 record_unwind_protect (save_excursion_restore, save_excursion_save ());
@@ -1746,7 +1746,7 @@ Use this function before selecting the buffer, since it may need to inspect
1746the current buffer's major mode. */) 1746the current buffer's major mode. */)
1747 (Lisp_Object buffer) 1747 (Lisp_Object buffer)
1748{ 1748{
1749 int count; 1749 ptrdiff_t count;
1750 Lisp_Object function; 1750 Lisp_Object function;
1751 1751
1752 CHECK_BUFFER (buffer); 1752 CHECK_BUFFER (buffer);
@@ -1958,16 +1958,15 @@ validate_region (register Lisp_Object *b, register Lisp_Object *e)
1958 tem = *b; *b = *e; *e = tem; 1958 tem = *b; *b = *e; *e = tem;
1959 } 1959 }
1960 1960
1961 if (!(BEGV <= XINT (*b) && XINT (*b) <= XINT (*e) 1961 if (! (BEGV <= XINT (*b) && XINT (*e) <= ZV))
1962 && XINT (*e) <= ZV))
1963 args_out_of_range (*b, *e); 1962 args_out_of_range (*b, *e);
1964} 1963}
1965 1964
1966/* Advance BYTE_POS up to a character boundary 1965/* Advance BYTE_POS up to a character boundary
1967 and return the adjusted position. */ 1966 and return the adjusted position. */
1968 1967
1969static EMACS_INT 1968static ptrdiff_t
1970advance_to_char_boundary (EMACS_INT byte_pos) 1969advance_to_char_boundary (ptrdiff_t byte_pos)
1971{ 1970{
1972 int c; 1971 int c;
1973 1972
@@ -1980,7 +1979,7 @@ advance_to_char_boundary (EMACS_INT byte_pos)
1980 { 1979 {
1981 /* We should advance BYTE_POS only when C is a constituent of a 1980 /* We should advance BYTE_POS only when C is a constituent of a
1982 multibyte sequence. */ 1981 multibyte sequence. */
1983 EMACS_INT orig_byte_pos = byte_pos; 1982 ptrdiff_t orig_byte_pos = byte_pos;
1984 1983
1985 do 1984 do
1986 { 1985 {
@@ -2056,12 +2055,12 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2056 (POINTER_TYPE **) &current_buffer->own_text.beg); 2055 (POINTER_TYPE **) &current_buffer->own_text.beg);
2057#endif /* REL_ALLOC */ 2056#endif /* REL_ALLOC */
2058 2057
2059 swapfield (pt, EMACS_INT); 2058 swapfield (pt, ptrdiff_t);
2060 swapfield (pt_byte, EMACS_INT); 2059 swapfield (pt_byte, ptrdiff_t);
2061 swapfield (begv, EMACS_INT); 2060 swapfield (begv, ptrdiff_t);
2062 swapfield (begv_byte, EMACS_INT); 2061 swapfield (begv_byte, ptrdiff_t);
2063 swapfield (zv, EMACS_INT); 2062 swapfield (zv, ptrdiff_t);
2064 swapfield (zv_byte, EMACS_INT); 2063 swapfield (zv_byte, ptrdiff_t);
2065 eassert (!current_buffer->base_buffer); 2064 eassert (!current_buffer->base_buffer);
2066 eassert (!other_buffer->base_buffer); 2065 eassert (!other_buffer->base_buffer);
2067 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; 2066 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1;
@@ -2071,7 +2070,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2071 other_buffer->prevent_redisplay_optimizations_p = 1; 2070 other_buffer->prevent_redisplay_optimizations_p = 1;
2072 swapfield (overlays_before, struct Lisp_Overlay *); 2071 swapfield (overlays_before, struct Lisp_Overlay *);
2073 swapfield (overlays_after, struct Lisp_Overlay *); 2072 swapfield (overlays_after, struct Lisp_Overlay *);
2074 swapfield (overlay_center, EMACS_INT); 2073 swapfield (overlay_center, ptrdiff_t);
2075 swapfield_ (undo_list, Lisp_Object); 2074 swapfield_ (undo_list, Lisp_Object);
2076 swapfield_ (mark, Lisp_Object); 2075 swapfield_ (mark, Lisp_Object);
2077 swapfield_ (enable_multibyte_characters, Lisp_Object); 2076 swapfield_ (enable_multibyte_characters, Lisp_Object);
@@ -2154,7 +2153,7 @@ current buffer is cleared. */)
2154{ 2153{
2155 struct Lisp_Marker *tail, *markers; 2154 struct Lisp_Marker *tail, *markers;
2156 struct buffer *other; 2155 struct buffer *other;
2157 EMACS_INT begv, zv; 2156 ptrdiff_t begv, zv;
2158 int narrowed = (BEG != BEGV || Z != ZV); 2157 int narrowed = (BEG != BEGV || Z != ZV);
2159 int modified_p = !NILP (Fbuffer_modified_p (Qnil)); 2158 int modified_p = !NILP (Fbuffer_modified_p (Qnil));
2160 Lisp_Object old_undo = BVAR (current_buffer, undo_list); 2159 Lisp_Object old_undo = BVAR (current_buffer, undo_list);
@@ -2186,7 +2185,7 @@ current buffer is cleared. */)
2186 2185
2187 if (NILP (flag)) 2186 if (NILP (flag))
2188 { 2187 {
2189 EMACS_INT pos, stop; 2188 ptrdiff_t pos, stop;
2190 unsigned char *p; 2189 unsigned char *p;
2191 2190
2192 /* Do this first, so it can use CHAR_TO_BYTE 2191 /* Do this first, so it can use CHAR_TO_BYTE
@@ -2250,8 +2249,8 @@ current buffer is cleared. */)
2250 } 2249 }
2251 else 2250 else
2252 { 2251 {
2253 EMACS_INT pt = PT; 2252 ptrdiff_t pt = PT;
2254 EMACS_INT pos, stop; 2253 ptrdiff_t pos, stop;
2255 unsigned char *p, *pend; 2254 unsigned char *p, *pend;
2256 2255
2257 /* Be sure not to have a multibyte sequence striding over the GAP. 2256 /* Be sure not to have a multibyte sequence striding over the GAP.
@@ -2267,7 +2266,7 @@ current buffer is cleared. */)
2267 while (! CHAR_HEAD_P (*q) && q > BEG_ADDR) q--; 2266 while (! CHAR_HEAD_P (*q) && q > BEG_ADDR) q--;
2268 if (LEADING_CODE_P (*q)) 2267 if (LEADING_CODE_P (*q))
2269 { 2268 {
2270 EMACS_INT new_gpt = GPT_BYTE - (GPT_ADDR - q); 2269 ptrdiff_t new_gpt = GPT_BYTE - (GPT_ADDR - q);
2271 2270
2272 move_gap_both (new_gpt, new_gpt); 2271 move_gap_both (new_gpt, new_gpt);
2273 } 2272 }
@@ -2351,8 +2350,8 @@ current buffer is cleared. */)
2351 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG; 2350 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG;
2352 2351
2353 { 2352 {
2354 EMACS_INT byte = advance_to_char_boundary (PT_BYTE); 2353 ptrdiff_t byte = advance_to_char_boundary (PT_BYTE);
2355 EMACS_INT position; 2354 ptrdiff_t position;
2356 2355
2357 if (byte > GPT_BYTE) 2356 if (byte > GPT_BYTE)
2358 position = chars_in_text (GAP_END_ADDR, byte - GPT_BYTE) + GPT; 2357 position = chars_in_text (GAP_END_ADDR, byte - GPT_BYTE) + GPT;
@@ -2516,20 +2515,20 @@ swap_out_buffer_local_variables (struct buffer *b)
2516ptrdiff_t 2515ptrdiff_t
2517overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, 2516overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2518 ptrdiff_t *len_ptr, 2517 ptrdiff_t *len_ptr,
2519 EMACS_INT *next_ptr, EMACS_INT *prev_ptr, int change_req) 2518 ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr, int change_req)
2520{ 2519{
2521 Lisp_Object overlay, start, end; 2520 Lisp_Object overlay, start, end;
2522 struct Lisp_Overlay *tail; 2521 struct Lisp_Overlay *tail;
2523 ptrdiff_t idx = 0; 2522 ptrdiff_t idx = 0;
2524 ptrdiff_t len = *len_ptr; 2523 ptrdiff_t len = *len_ptr;
2525 Lisp_Object *vec = *vec_ptr; 2524 Lisp_Object *vec = *vec_ptr;
2526 EMACS_INT next = ZV; 2525 ptrdiff_t next = ZV;
2527 EMACS_INT prev = BEGV; 2526 ptrdiff_t prev = BEGV;
2528 int inhibit_storing = 0; 2527 int inhibit_storing = 0;
2529 2528
2530 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2529 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2531 { 2530 {
2532 EMACS_INT startpos, endpos; 2531 ptrdiff_t startpos, endpos;
2533 2532
2534 XSETMISC (overlay, tail); 2533 XSETMISC (overlay, tail);
2535 2534
@@ -2577,7 +2576,7 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2577 2576
2578 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2577 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2579 { 2578 {
2580 EMACS_INT startpos, endpos; 2579 ptrdiff_t startpos, endpos;
2581 2580
2582 XSETMISC (overlay, tail); 2581 XSETMISC (overlay, tail);
2583 2582
@@ -2650,21 +2649,21 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2650static ptrdiff_t 2649static ptrdiff_t
2651overlays_in (EMACS_INT beg, EMACS_INT end, int extend, 2650overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2652 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr, 2651 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr,
2653 EMACS_INT *next_ptr, EMACS_INT *prev_ptr) 2652 ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr)
2654{ 2653{
2655 Lisp_Object overlay, ostart, oend; 2654 Lisp_Object overlay, ostart, oend;
2656 struct Lisp_Overlay *tail; 2655 struct Lisp_Overlay *tail;
2657 ptrdiff_t idx = 0; 2656 ptrdiff_t idx = 0;
2658 ptrdiff_t len = *len_ptr; 2657 ptrdiff_t len = *len_ptr;
2659 Lisp_Object *vec = *vec_ptr; 2658 Lisp_Object *vec = *vec_ptr;
2660 EMACS_INT next = ZV; 2659 ptrdiff_t next = ZV;
2661 EMACS_INT prev = BEGV; 2660 ptrdiff_t prev = BEGV;
2662 int inhibit_storing = 0; 2661 int inhibit_storing = 0;
2663 int end_is_Z = end == Z; 2662 int end_is_Z = end == Z;
2664 2663
2665 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2664 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2666 { 2665 {
2667 EMACS_INT startpos, endpos; 2666 ptrdiff_t startpos, endpos;
2668 2667
2669 XSETMISC (overlay, tail); 2668 XSETMISC (overlay, tail);
2670 2669
@@ -2711,7 +2710,7 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2711 2710
2712 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2711 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2713 { 2712 {
2714 EMACS_INT startpos, endpos; 2713 ptrdiff_t startpos, endpos;
2715 2714
2716 XSETMISC (overlay, tail); 2715 XSETMISC (overlay, tail);
2717 2716
@@ -2767,8 +2766,8 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2767int 2766int
2768mouse_face_overlay_overlaps (Lisp_Object overlay) 2767mouse_face_overlay_overlaps (Lisp_Object overlay)
2769{ 2768{
2770 EMACS_INT start = OVERLAY_POSITION (OVERLAY_START (overlay)); 2769 ptrdiff_t start = OVERLAY_POSITION (OVERLAY_START (overlay));
2771 EMACS_INT end = OVERLAY_POSITION (OVERLAY_END (overlay)); 2770 ptrdiff_t end = OVERLAY_POSITION (OVERLAY_END (overlay));
2772 ptrdiff_t n, i, size; 2771 ptrdiff_t n, i, size;
2773 Lisp_Object *v, tem; 2772 Lisp_Object *v, tem;
2774 2773
@@ -2794,14 +2793,14 @@ mouse_face_overlay_overlaps (Lisp_Object overlay)
2794 2793
2795/* Fast function to just test if we're at an overlay boundary. */ 2794/* Fast function to just test if we're at an overlay boundary. */
2796int 2795int
2797overlay_touches_p (EMACS_INT pos) 2796overlay_touches_p (ptrdiff_t pos)
2798{ 2797{
2799 Lisp_Object overlay; 2798 Lisp_Object overlay;
2800 struct Lisp_Overlay *tail; 2799 struct Lisp_Overlay *tail;
2801 2800
2802 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2801 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2803 { 2802 {
2804 EMACS_INT endpos; 2803 ptrdiff_t endpos;
2805 2804
2806 XSETMISC (overlay ,tail); 2805 XSETMISC (overlay ,tail);
2807 if (!OVERLAYP (overlay)) 2806 if (!OVERLAYP (overlay))
@@ -2816,7 +2815,7 @@ overlay_touches_p (EMACS_INT pos)
2816 2815
2817 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2816 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2818 { 2817 {
2819 EMACS_INT startpos; 2818 ptrdiff_t startpos;
2820 2819
2821 XSETMISC (overlay, tail); 2820 XSETMISC (overlay, tail);
2822 if (!OVERLAYP (overlay)) 2821 if (!OVERLAYP (overlay))
@@ -2834,7 +2833,7 @@ overlay_touches_p (EMACS_INT pos)
2834struct sortvec 2833struct sortvec
2835{ 2834{
2836 Lisp_Object overlay; 2835 Lisp_Object overlay;
2837 EMACS_INT beg, end; 2836 ptrdiff_t beg, end;
2838 EMACS_INT priority; 2837 EMACS_INT priority;
2839}; 2838};
2840 2839
@@ -2951,7 +2950,7 @@ static void
2951record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, 2950record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
2952 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size) 2951 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size)
2953{ 2952{
2954 EMACS_INT nbytes; 2953 ptrdiff_t nbytes;
2955 2954
2956 if (ssl->used == ssl->size) 2955 if (ssl->used == ssl->size)
2957 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf); 2956 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf);
@@ -3001,12 +3000,12 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
3001 PSTR, if that variable is non-null. The string may be overwritten by 3000 PSTR, if that variable is non-null. The string may be overwritten by
3002 subsequent calls. */ 3001 subsequent calls. */
3003 3002
3004EMACS_INT 3003ptrdiff_t
3005overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr) 3004overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr)
3006{ 3005{
3007 Lisp_Object overlay, window, str; 3006 Lisp_Object overlay, window, str;
3008 struct Lisp_Overlay *ov; 3007 struct Lisp_Overlay *ov;
3009 EMACS_INT startpos, endpos; 3008 ptrdiff_t startpos, endpos;
3010 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 3009 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
3011 3010
3012 overlay_heads.used = overlay_heads.bytes = 0; 3011 overlay_heads.used = overlay_heads.bytes = 0;
@@ -3076,7 +3075,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3076 if (overlay_heads.bytes || overlay_tails.bytes) 3075 if (overlay_heads.bytes || overlay_tails.bytes)
3077 { 3076 {
3078 Lisp_Object tem; 3077 Lisp_Object tem;
3079 EMACS_INT i; 3078 ptrdiff_t i;
3080 unsigned char *p; 3079 unsigned char *p;
3081 ptrdiff_t total; 3080 ptrdiff_t total;
3082 3081
@@ -3090,7 +3089,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3090 p = overlay_str_buf; 3089 p = overlay_str_buf;
3091 for (i = overlay_tails.used; --i >= 0;) 3090 for (i = overlay_tails.used; --i >= 0;)
3092 { 3091 {
3093 EMACS_INT nbytes; 3092 ptrdiff_t nbytes;
3094 tem = overlay_tails.buf[i].string; 3093 tem = overlay_tails.buf[i].string;
3095 nbytes = copy_text (SDATA (tem), p, 3094 nbytes = copy_text (SDATA (tem), p,
3096 SBYTES (tem), 3095 SBYTES (tem),
@@ -3099,7 +3098,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3099 } 3098 }
3100 for (i = 0; i < overlay_heads.used; ++i) 3099 for (i = 0; i < overlay_heads.used; ++i)
3101 { 3100 {
3102 EMACS_INT nbytes; 3101 ptrdiff_t nbytes;
3103 tem = overlay_heads.buf[i].string; 3102 tem = overlay_heads.buf[i].string;
3104 nbytes = copy_text (SDATA (tem), p, 3103 nbytes = copy_text (SDATA (tem), p,
3105 SBYTES (tem), 3104 SBYTES (tem),
@@ -3126,7 +3125,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3126/* Shift overlays in BUF's overlay lists, to center the lists at POS. */ 3125/* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3127 3126
3128void 3127void
3129recenter_overlay_lists (struct buffer *buf, EMACS_INT pos) 3128recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos)
3130{ 3129{
3131 Lisp_Object overlay, beg, end; 3130 Lisp_Object overlay, beg, end;
3132 struct Lisp_Overlay *prev, *tail, *next; 3131 struct Lisp_Overlay *prev, *tail, *next;
@@ -3164,7 +3163,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3164 if (OVERLAY_POSITION (end) > pos) 3163 if (OVERLAY_POSITION (end) > pos)
3165 { 3164 {
3166 /* OVERLAY needs to be moved. */ 3165 /* OVERLAY needs to be moved. */
3167 EMACS_INT where = OVERLAY_POSITION (beg); 3166 ptrdiff_t where = OVERLAY_POSITION (beg);
3168 struct Lisp_Overlay *other, *other_prev; 3167 struct Lisp_Overlay *other, *other_prev;
3169 3168
3170 /* Splice the cons cell TAIL out of overlays_before. */ 3169 /* Splice the cons cell TAIL out of overlays_before. */
@@ -3237,7 +3236,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3237 if (OVERLAY_POSITION (end) <= pos) 3236 if (OVERLAY_POSITION (end) <= pos)
3238 { 3237 {
3239 /* OVERLAY needs to be moved. */ 3238 /* OVERLAY needs to be moved. */
3240 EMACS_INT where = OVERLAY_POSITION (end); 3239 ptrdiff_t where = OVERLAY_POSITION (end);
3241 struct Lisp_Overlay *other, *other_prev; 3240 struct Lisp_Overlay *other, *other_prev;
3242 3241
3243 /* Splice the cons cell TAIL out of overlays_after. */ 3242 /* Splice the cons cell TAIL out of overlays_after. */
@@ -3275,7 +3274,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3275} 3274}
3276 3275
3277void 3276void
3278adjust_overlays_for_insert (EMACS_INT pos, EMACS_INT length) 3277adjust_overlays_for_insert (ptrdiff_t pos, ptrdiff_t length)
3279{ 3278{
3280 /* After an insertion, the lists are still sorted properly, 3279 /* After an insertion, the lists are still sorted properly,
3281 but we may need to update the value of the overlay center. */ 3280 but we may need to update the value of the overlay center. */
@@ -3284,13 +3283,13 @@ adjust_overlays_for_insert (EMACS_INT pos, EMACS_INT length)
3284} 3283}
3285 3284
3286void 3285void
3287adjust_overlays_for_delete (EMACS_INT pos, EMACS_INT length) 3286adjust_overlays_for_delete (ptrdiff_t pos, ptrdiff_t length)
3288{ 3287{
3289 if (current_buffer->overlay_center < pos) 3288 if (current_buffer->overlay_center < pos)
3290 /* The deletion was to our right. No change needed; the before- and 3289 /* The deletion was to our right. No change needed; the before- and
3291 after-lists are still consistent. */ 3290 after-lists are still consistent. */
3292 ; 3291 ;
3293 else if (current_buffer->overlay_center > pos + length) 3292 else if (current_buffer->overlay_center - pos > length)
3294 /* The deletion was to our left. We need to adjust the center value 3293 /* The deletion was to our left. We need to adjust the center value
3295 to account for the change in position, but the lists are consistent 3294 to account for the change in position, but the lists are consistent
3296 given the new value. */ 3295 given the new value. */
@@ -3309,7 +3308,7 @@ adjust_overlays_for_delete (EMACS_INT pos, EMACS_INT length)
3309 Such an overlay might even have negative size at this point. 3308 Such an overlay might even have negative size at this point.
3310 If so, we'll make the overlay empty. */ 3309 If so, we'll make the overlay empty. */
3311void 3310void
3312fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end) 3311fix_start_end_in_overlays (register ptrdiff_t start, register ptrdiff_t end)
3313{ 3312{
3314 Lisp_Object overlay; 3313 Lisp_Object overlay;
3315 struct Lisp_Overlay *before_list IF_LINT (= NULL); 3314 struct Lisp_Overlay *before_list IF_LINT (= NULL);
@@ -3322,7 +3321,7 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3322 current_buffer->overlays_before or overlays_after, depending 3321 current_buffer->overlays_before or overlays_after, depending
3323 which loop we're in. */ 3322 which loop we're in. */
3324 struct Lisp_Overlay *tail, *parent; 3323 struct Lisp_Overlay *tail, *parent;
3325 EMACS_INT startpos, endpos; 3324 ptrdiff_t startpos, endpos;
3326 3325
3327 /* This algorithm shifts links around instead of consing and GCing. 3326 /* This algorithm shifts links around instead of consing and GCing.
3328 The loop invariant is that before_list (resp. after_list) is a 3327 The loop invariant is that before_list (resp. after_list) is a
@@ -3456,12 +3455,12 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3456 was at PREV, and now is at POS. */ 3455 was at PREV, and now is at POS. */
3457 3456
3458void 3457void
3459fix_overlays_before (struct buffer *bp, EMACS_INT prev, EMACS_INT pos) 3458fix_overlays_before (struct buffer *bp, ptrdiff_t prev, ptrdiff_t pos)
3460{ 3459{
3461 /* If parent is nil, replace overlays_before; otherwise, parent->next. */ 3460 /* If parent is nil, replace overlays_before; otherwise, parent->next. */
3462 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair; 3461 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair;
3463 Lisp_Object tem; 3462 Lisp_Object tem;
3464 EMACS_INT end IF_LINT (= 0); 3463 ptrdiff_t end IF_LINT (= 0);
3465 3464
3466 /* After the insertion, the several overlays may be in incorrect 3465 /* After the insertion, the several overlays may be in incorrect
3467 order. The possibility is that, in the list `overlays_before', 3466 order. The possibility is that, in the list `overlays_before',
@@ -3619,11 +3618,11 @@ for the rear of the overlay advance when text is inserted there
3619/* Mark a section of BUF as needing redisplay because of overlays changes. */ 3618/* Mark a section of BUF as needing redisplay because of overlays changes. */
3620 3619
3621static void 3620static void
3622modify_overlay (struct buffer *buf, EMACS_INT start, EMACS_INT end) 3621modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
3623{ 3622{
3624 if (start > end) 3623 if (start > end)
3625 { 3624 {
3626 EMACS_INT temp = start; 3625 ptrdiff_t temp = start;
3627 start = end; 3626 start = end;
3628 end = temp; 3627 end = temp;
3629 } 3628 }
@@ -3672,7 +3671,7 @@ buffer. */)
3672{ 3671{
3673 struct buffer *b, *ob; 3672 struct buffer *b, *ob;
3674 Lisp_Object obuffer; 3673 Lisp_Object obuffer;
3675 int count = SPECPDL_INDEX (); 3674 ptrdiff_t count = SPECPDL_INDEX ();
3676 3675
3677 CHECK_OVERLAY (overlay); 3676 CHECK_OVERLAY (overlay);
3678 if (NILP (buffer)) 3677 if (NILP (buffer))
@@ -3691,19 +3690,22 @@ buffer. */)
3691 CHECK_NUMBER_COERCE_MARKER (beg); 3690 CHECK_NUMBER_COERCE_MARKER (beg);
3692 CHECK_NUMBER_COERCE_MARKER (end); 3691 CHECK_NUMBER_COERCE_MARKER (end);
3693 3692
3694 if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate)))
3695 return Fdelete_overlay (overlay);
3696
3697 if (XINT (beg) > XINT (end)) 3693 if (XINT (beg) > XINT (end))
3698 { 3694 {
3699 Lisp_Object temp; 3695 Lisp_Object temp;
3700 temp = beg; beg = end; end = temp; 3696 temp = beg; beg = end; end = temp;
3701 } 3697 }
3702 3698
3699 b = XBUFFER (buffer);
3700 if (! (BUF_BEGV (b) <= XINT (beg) && XINT (end) <= BUF_ZV (b)))
3701 args_out_of_range (beg, end);
3702
3703 if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate)))
3704 return Fdelete_overlay (overlay);
3705
3703 specbind (Qinhibit_quit, Qt); 3706 specbind (Qinhibit_quit, Qt);
3704 3707
3705 obuffer = Fmarker_buffer (OVERLAY_START (overlay)); 3708 obuffer = Fmarker_buffer (OVERLAY_START (overlay));
3706 b = XBUFFER (buffer);
3707 ob = BUFFERP (obuffer) ? XBUFFER (obuffer) : (struct buffer *) 0; 3709 ob = BUFFERP (obuffer) ? XBUFFER (obuffer) : (struct buffer *) 0;
3708 3710
3709 /* If the overlay has changed buffers, do a thorough redisplay. */ 3711 /* If the overlay has changed buffers, do a thorough redisplay. */
@@ -3712,8 +3714,8 @@ buffer. */)
3712 /* Redisplay where the overlay was. */ 3714 /* Redisplay where the overlay was. */
3713 if (!NILP (obuffer)) 3715 if (!NILP (obuffer))
3714 { 3716 {
3715 EMACS_INT o_beg; 3717 ptrdiff_t o_beg;
3716 EMACS_INT o_end; 3718 ptrdiff_t o_end;
3717 3719
3718 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay)); 3720 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
3719 o_end = OVERLAY_POSITION (OVERLAY_END (overlay)); 3721 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
@@ -3727,7 +3729,7 @@ buffer. */)
3727 else 3729 else
3728 /* Redisplay the area the overlay has just left, or just enclosed. */ 3730 /* Redisplay the area the overlay has just left, or just enclosed. */
3729 { 3731 {
3730 EMACS_INT o_beg, o_end; 3732 ptrdiff_t o_beg, o_end;
3731 3733
3732 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay)); 3734 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
3733 o_end = OVERLAY_POSITION (OVERLAY_END (overlay)); 3735 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
@@ -3781,7 +3783,7 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3781{ 3783{
3782 Lisp_Object buffer; 3784 Lisp_Object buffer;
3783 struct buffer *b; 3785 struct buffer *b;
3784 int count = SPECPDL_INDEX (); 3786 ptrdiff_t count = SPECPDL_INDEX ();
3785 3787
3786 CHECK_OVERLAY (overlay); 3788 CHECK_OVERLAY (overlay);
3787 3789
@@ -3872,7 +3874,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
3872 /* Put all the overlays we want in a vector in overlay_vec. 3874 /* Put all the overlays we want in a vector in overlay_vec.
3873 Store the length in len. */ 3875 Store the length in len. */
3874 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 3876 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3875 (EMACS_INT *) 0, (EMACS_INT *) 0, 0); 3877 0, 0, 0);
3876 3878
3877 /* Make a list of them all. */ 3879 /* Make a list of them all. */
3878 result = Flist (noverlays, overlay_vec); 3880 result = Flist (noverlays, overlay_vec);
@@ -3920,7 +3922,7 @@ the value is (point-max). */)
3920 (Lisp_Object pos) 3922 (Lisp_Object pos)
3921{ 3923{
3922 ptrdiff_t i, len, noverlays; 3924 ptrdiff_t i, len, noverlays;
3923 EMACS_INT endpos; 3925 ptrdiff_t endpos;
3924 Lisp_Object *overlay_vec; 3926 Lisp_Object *overlay_vec;
3925 3927
3926 CHECK_NUMBER_COERCE_MARKER (pos); 3928 CHECK_NUMBER_COERCE_MARKER (pos);
@@ -3932,14 +3934,14 @@ the value is (point-max). */)
3932 Store the length in len. 3934 Store the length in len.
3933 endpos gets the position where the next overlay starts. */ 3935 endpos gets the position where the next overlay starts. */
3934 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 3936 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3935 &endpos, (EMACS_INT *) 0, 1); 3937 &endpos, 0, 1);
3936 3938
3937 /* If any of these overlays ends before endpos, 3939 /* If any of these overlays ends before endpos,
3938 use its ending point instead. */ 3940 use its ending point instead. */
3939 for (i = 0; i < noverlays; i++) 3941 for (i = 0; i < noverlays; i++)
3940 { 3942 {
3941 Lisp_Object oend; 3943 Lisp_Object oend;
3942 EMACS_INT oendpos; 3944 ptrdiff_t oendpos;
3943 3945
3944 oend = OVERLAY_END (overlay_vec[i]); 3946 oend = OVERLAY_END (overlay_vec[i]);
3945 oendpos = OVERLAY_POSITION (oend); 3947 oendpos = OVERLAY_POSITION (oend);
@@ -3958,7 +3960,7 @@ If there are no overlay boundaries from (point-min) to POS,
3958the value is (point-min). */) 3960the value is (point-min). */)
3959 (Lisp_Object pos) 3961 (Lisp_Object pos)
3960{ 3962{
3961 EMACS_INT prevpos; 3963 ptrdiff_t prevpos;
3962 Lisp_Object *overlay_vec; 3964 Lisp_Object *overlay_vec;
3963 ptrdiff_t len; 3965 ptrdiff_t len;
3964 3966
@@ -3976,7 +3978,7 @@ the value is (point-min). */)
3976 Store the length in len. 3978 Store the length in len.
3977 prevpos gets the position of the previous change. */ 3979 prevpos gets the position of the previous change. */
3978 overlays_at (XINT (pos), 1, &overlay_vec, &len, 3980 overlays_at (XINT (pos), 1, &overlay_vec, &len,
3979 (EMACS_INT *) 0, &prevpos, 1); 3981 0, &prevpos, 1);
3980 3982
3981 xfree (overlay_vec); 3983 xfree (overlay_vec);
3982 return make_number (prevpos); 3984 return make_number (prevpos);
@@ -4014,9 +4016,11 @@ That makes overlay lookup faster for positions near POS (but perhaps slower
4014for positions far away from POS). */) 4016for positions far away from POS). */)
4015 (Lisp_Object pos) 4017 (Lisp_Object pos)
4016{ 4018{
4019 ptrdiff_t p;
4017 CHECK_NUMBER_COERCE_MARKER (pos); 4020 CHECK_NUMBER_COERCE_MARKER (pos);
4018 4021
4019 recenter_overlay_lists (current_buffer, XINT (pos)); 4022 p = clip_to_bounds (PTRDIFF_MIN, XINT (pos), PTRDIFF_MAX);
4023 recenter_overlay_lists (current_buffer, p);
4020 return Qnil; 4024 return Qnil;
4021} 4025}
4022 4026
@@ -4083,7 +4087,7 @@ VALUE will be returned.*/)
4083static Lisp_Object last_overlay_modification_hooks; 4087static Lisp_Object last_overlay_modification_hooks;
4084 4088
4085/* Number of elements actually used in last_overlay_modification_hooks. */ 4089/* Number of elements actually used in last_overlay_modification_hooks. */
4086static int last_overlay_modification_hooks_used; 4090static ptrdiff_t last_overlay_modification_hooks_used;
4087 4091
4088/* Add one functionlist/overlay pair 4092/* Add one functionlist/overlay pair
4089 to the end of last_overlay_modification_hooks. */ 4093 to the end of last_overlay_modification_hooks. */
@@ -4091,11 +4095,11 @@ static int last_overlay_modification_hooks_used;
4091static void 4095static void
4092add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay) 4096add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay)
4093{ 4097{
4094 int oldsize = ASIZE (last_overlay_modification_hooks); 4098 ptrdiff_t oldsize = ASIZE (last_overlay_modification_hooks);
4095 4099
4096 if (last_overlay_modification_hooks_used == oldsize) 4100 if (oldsize - 1 <= last_overlay_modification_hooks_used)
4097 last_overlay_modification_hooks = larger_vector 4101 last_overlay_modification_hooks =
4098 (last_overlay_modification_hooks, oldsize * 2, Qnil); 4102 larger_vector (last_overlay_modification_hooks, 2, -1);
4099 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used, 4103 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used,
4100 functionlist); last_overlay_modification_hooks_used++; 4104 functionlist); last_overlay_modification_hooks_used++;
4101 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used, 4105 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used,
@@ -4144,7 +4148,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4144 last_overlay_modification_hooks_used = 0; 4148 last_overlay_modification_hooks_used = 0;
4145 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 4149 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4146 { 4150 {
4147 EMACS_INT startpos, endpos; 4151 ptrdiff_t startpos, endpos;
4148 Lisp_Object ostart, oend; 4152 Lisp_Object ostart, oend;
4149 4153
4150 XSETMISC (overlay, tail); 4154 XSETMISC (overlay, tail);
@@ -4181,7 +4185,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4181 4185
4182 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 4186 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4183 { 4187 {
4184 EMACS_INT startpos, endpos; 4188 ptrdiff_t startpos, endpos;
4185 Lisp_Object ostart, oend; 4189 Lisp_Object ostart, oend;
4186 4190
4187 XSETMISC (overlay, tail); 4191 XSETMISC (overlay, tail);
@@ -4222,9 +4226,9 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4222 /* Call the functions recorded in last_overlay_modification_hooks. 4226 /* Call the functions recorded in last_overlay_modification_hooks.
4223 First copy the vector contents, in case some of these hooks 4227 First copy the vector contents, in case some of these hooks
4224 do subsequent modification of the buffer. */ 4228 do subsequent modification of the buffer. */
4225 int size = last_overlay_modification_hooks_used; 4229 ptrdiff_t size = last_overlay_modification_hooks_used;
4226 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); 4230 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object));
4227 int i; 4231 ptrdiff_t i;
4228 4232
4229 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, 4233 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
4230 size * sizeof (Lisp_Object)); 4234 size * sizeof (Lisp_Object));
@@ -4264,7 +4268,7 @@ call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, int after,
4264/* Delete any zero-sized overlays at position POS, if the `evaporate' 4268/* Delete any zero-sized overlays at position POS, if the `evaporate'
4265 property is set. */ 4269 property is set. */
4266void 4270void
4267evaporate_overlays (EMACS_INT pos) 4271evaporate_overlays (ptrdiff_t pos)
4268{ 4272{
4269 Lisp_Object overlay, hit_list; 4273 Lisp_Object overlay, hit_list;
4270 struct Lisp_Overlay *tail; 4274 struct Lisp_Overlay *tail;
@@ -4273,7 +4277,7 @@ evaporate_overlays (EMACS_INT pos)
4273 if (pos <= current_buffer->overlay_center) 4277 if (pos <= current_buffer->overlay_center)
4274 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 4278 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4275 { 4279 {
4276 EMACS_INT endpos; 4280 ptrdiff_t endpos;
4277 XSETMISC (overlay, tail); 4281 XSETMISC (overlay, tail);
4278 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 4282 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
4279 if (endpos < pos) 4283 if (endpos < pos)
@@ -4285,7 +4289,7 @@ evaporate_overlays (EMACS_INT pos)
4285 else 4289 else
4286 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 4290 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4287 { 4291 {
4288 EMACS_INT startpos; 4292 ptrdiff_t startpos;
4289 XSETMISC (overlay, tail); 4293 XSETMISC (overlay, tail);
4290 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 4294 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
4291 if (startpos > pos) 4295 if (startpos > pos)
@@ -4795,7 +4799,7 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
4795 shrink it. */ 4799 shrink it. */
4796 4800
4797void 4801void
4798enlarge_buffer_text (struct buffer *b, EMACS_INT delta) 4802enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
4799{ 4803{
4800 POINTER_TYPE *p; 4804 POINTER_TYPE *p;
4801 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 4805 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1