Mercurial > hg > xemacs-beta
annotate src/rangetab.c @ 2720:6fa9919a9a0b
[xemacs-hg @ 2005-04-08 23:10:01 by crestani]
ChangeLog addition:
2005-04-01 Marcus Crestani <crestani@xemacs.org>
The new allocator.
New configure flag: `MC_ALLOC':
* configure.ac (XE_COMPLEX_ARG_ENABLE): Add `--enable-mc-alloc' as
a new configure flag.
* configure.in (AC_INIT_PARSE_ARGS): Add `--mc-alloc' as a new
configure flag.
* configure.usage: Add description for `mc-alloc'.
DUMP_IN_EXEC:
* Makefile.in.in: Condition the installation of a separate dump
file on !DUMP_ON_EXEC.
* configure.ac (XE_COMPLEX_ARG_ENABLE): Add
`--enable-dump-in-exec' as a new configure flag.
* configure.ac: DUMP_IN_EXEC is define as default for PDUMP but
not default for MC_ALLOC.
* configure.in (AC_INIT_PARSE_ARGS): Add `--dump-in-exec' as a
new configure flag.
* configure.in: DUMP_IN_EXEC is define as default for PDUMP but
not default for MC_ALLOC.
* configure.usage: Add description for `dump-in-exec'.
lib-src/ChangeLog addition:
2005-04-01 Marcus Crestani <crestani@xemacs.org>
The new allocator.
DUMP_IN_EXEC:
* Makefile.in.in: Only compile insert-data-in-exec if
DUMP_IN_EXEC is defined.
lisp/ChangeLog addition:
2005-04-01 Marcus Crestani <crestani@xemacs.org>
The new allocator.
MEMORY_USAGE_STATS
* diagnose.el: Add new lisp function to pretty print statistics
about the new allocator.
* diagnose.el (show-mc-alloc-memory-usage): New.
modules/ChangeLog addition:
2005-04-01 Marcus Crestani <crestani@xemacs.org>
The new allocator.
Remove Lcrecords:
* postgresql/postgresql.c (allocate_pgconn): Allocate with new
allocator.
* postgresql/postgresql.c (allocate_pgresult): Allocate PGresult
with new allocator.
* postgresql/postgresql.h (struct Lisp_PGconn): Add
lrecord_header.
* postgresql/postgresql.h (struct Lisp_PGresult): Add
lrecord_header.
* ldap/eldap.c (allocate_ldap): Allocate with new allocator.
* ldap/eldap.h (struct Lisp_LDAP): Add lrecord_header.
nt/ChangeLog addition:
2005-04-01 Marcus Crestani <crestani@xemacs.org>
The new allocator.
New configure flag: `MC_ALLOC':
* config.inc.samp: Add new flag `MC_ALLOC'.
* xemacs.mak: Add flag and configuration output for `MC_ALLOC'.
New files:
* xemacs.dsp: Add source files mc-alloc.c and mc-alloc.h.
* xemacs.mak: Add new object file mc-alloc.obj to dependencies.
src/ChangeLog addition:
2005-04-01 Marcus Crestani <crestani@xemacs.org>
The new allocator.
New configure flag: `MC_ALLOC':
* config.h.in: Add new flag `MC_ALLOC'.
New files:
* Makefile.in.in: Add new object file mc-alloc.o.
* depend: Add new files to dependencies.
* mc-alloc.c: New.
* mc-alloc.h: New.
Running the new allocator from XEmacs:
* alloc.c (deadbeef_memory): Moved to mc-alloc.c.
* emacs.c (main_1): Initialize the new allocator and add
syms_of_mc_alloc.
* symsinit.h: Add syms_of_mc_alloc.
New lrecord allocation and free functions:
* alloc.c (alloc_lrecord): New. Allocates an lrecord, includes
type checking and initializing of the lrecord_header.
* alloc.c (noseeum_alloc_lrecord): Same as above, but increments
the NOSEEUM cons counter.
* alloc.c (free_lrecord): New. Calls the finalizer and frees the
lrecord.
* lrecord.h: Add lrecord allocation prototypes and comments.
Remove old lrecord FROB block allocation:
* alloc.c (allocate_lisp_storage): Former function to expand
heap. Not needed anymore, remove.
* alloc.c: Completely remove `Fixed-size type macros'
* alloc.c (release_breathing_space): Remove.
* alloc.c (memory_full): Remove release_breathing_space.
* alloc.c (refill_memory_reserve): Remove.
* alloc.c (TYPE_ALLOC_SIZE): Remove.
* alloc.c (DECLARE_FIXED_TYPE_ALLOC): Remove.
* alloc.c (ALLOCATE_FIXED_TYPE_FROM_BLOCK): Remove.
* alloc.c (ALLOCATE_FIXED_TYPE_1): Remove.
* alloc.c (ALLOCATE_FIXED_TYPE): Remove.
* alloc.c (NOSEEUM_ALLOCATE_FIXED_TYPE): Remove.
* alloc.c (struct Lisp_Free): Remove.
* alloc.c (LRECORD_FREE_P): Remove.
* alloc.c (MARK_LRECORD_AS_FREE): Remove.
* alloc.c (MARK_LRECORD_AS_NOT_FREE): Remove.
* alloc.c (PUT_FIXED_TYPE_ON_FREE_LIST): Remove.
* alloc.c (FREE_FIXED_TYPE): Remove.
* alloc.c (FREE_FIXED_TYPE_WHEN_NOT_IN_GC): Remove.
Allocate old lrecords with new allocator:
* alloc.c: DECLARE_FIXED_TYPE_ALLOC removed for all lrecords
defined in alloc.c.
* alloc.c (Fcons): Allocate with new allocator.
* alloc.c (noseeum_cons): Allocate with new allocator.
* alloc.c (make_float): Allocate with new allocator.
* alloc.c (make_bignum): Allocate with new allocator.
* alloc.c (make_bignum_bg): Allocate with new allocator.
* alloc.c (make_ratio): Allocate with new allocator.
* alloc.c (make_ratio_bg): Allocate with new allocator.
* alloc.c (make_ratio_rt): Allocate with new allocator.
* alloc.c (make_bigfloat): Allocate with new allocator.
* alloc.c (make_bigfloat_bf): Allocate with new allocator.
* alloc.c (make_compiled_function): Allocate with new allocator.
* alloc.c (Fmake_symbol): Allocate with new allocator.
* alloc.c (allocate_extent): Allocate with new allocator.
* alloc.c (allocate_event): Allocate with new allocator.
* alloc.c (make_key_data): Allocate with new allocator.
* alloc.c (make_button_data): Allocate with new allocator.
* alloc.c (make_motion_data): Allocate with new allocator.
* alloc.c (make_process_data): Allocate with new allocator.
* alloc.c (make_timeout_data): Allocate with new allocator.
* alloc.c (make_magic_data): Allocate with new allocator.
* alloc.c (make_magic_eval_data): Allocate with new allocator.
* alloc.c (make_eval_data): Allocate with new allocator.
* alloc.c (make_misc_user_data): Allocate with new allocator.
* alloc.c (Fmake_marker): Allocate with new allocator.
* alloc.c (noseeum_make_marker): Allocate with new allocator.
* alloc.c (make_uninit_string): Allocate with new allocator.
* alloc.c (resize_string): Allocate with new allocator.
* alloc.c (make_string_nocopy): Allocate with new allocator.
Garbage Collection:
* alloc.c (GC_CHECK_NOT_FREE): Remove obsolete assertions.
* alloc.c (SWEEP_FIXED_TYPE_BLOCK): Remove.
* alloc.c (SWEEP_FIXED_TYPE_BLOCK_1): Remove.
* alloc.c (sweep_conses): Remove.
* alloc.c (free_cons): Use new allocator to free.
* alloc.c (sweep_compiled_functions): Remove.
* alloc.c (sweep_floats): Remove.
* alloc.c (sweep_bignums): Remove.
* alloc.c (sweep_ratios): Remove.
* alloc.c (sweep_bigfloats): Remove.
* alloc.c (sweep_symbols): Remove.
* alloc.c (sweep_extents): Remove.
* alloc.c (sweep_events): Remove.
* alloc.c (sweep_key_data): Remove.
* alloc.c (free_key_data): Use new allocator to free.
* alloc.c (sweep_button_data): Remove.
* alloc.c (free_button_data): Use new allocator to free.
* alloc.c (sweep_motion_data): Remove.
* alloc.c (free_motion_data): Use new allocator to free.
* alloc.c (sweep_process_data): Remove.
* alloc.c (free_process_data): Use new allocator to free.
* alloc.c (sweep_timeout_data): Remove.
* alloc.c (free_timeout_data): Use new allocator to free.
* alloc.c (sweep_magic_data): Remove.
* alloc.c (free_magic_data): Use new allocator to free.
* alloc.c (sweep_magic_eval_data): Remove.
* alloc.c (free_magic_eval_data): Use new allocator to free.
* alloc.c (sweep_eval_data): Remove.
* alloc.c (free_eval_data): Use new allocator to free.
* alloc.c (sweep_misc_user_data): Remove.
* alloc.c (free_misc_user_data): Use new allocator to free.
* alloc.c (sweep_markers): Remove.
* alloc.c (free_marker): Use new allocator to free.
* alloc.c (garbage_collect_1): Remove release_breathing_space.
* alloc.c (gc_sweep): Remove all the old lcrecord and lrecord
related stuff. Sweeping now works like this: compact string
chars, finalize, sweep.
* alloc.c (common_init_alloc_early): Remove old lrecord
initializations, remove breathing_space.
* emacs.c (Fdump_emacs): Remove release_breathing_space.
* lisp.h: Remove prototype for release_breathing_space.
* lisp.h: Adjust the special cons mark makros.
Lrecord Finalizer:
* alloc.c: Add finalizer to lrecord definition.
* alloc.c (finalize_string): Add finalizer for string.
* bytecode.c: Add finalizer to lrecord definition.
* bytecode.c (finalize_compiled_function): Add finalizer for
compiled function.
* marker.c: Add finalizer to lrecord definition.
* marker.c (finalize_marker): Add finalizer for marker.
These changes build the interface to mc-alloc:
* lrecord.h (MC_ALLOC_CALL_FINALIZER): Tell mc-alloc how to
finalize lrecords.
* lrecord.h (MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE): Tell
mc-alloc how to finalize for disksave.
Unify lrecords and lcrecords:
* lisp.h (struct Lisp_String): Adjust string union hack to
new lrecord header.
* lrecord.h: Adjust comments.
* lrecord.h (struct lrecord_header): The new lrecord header
includes type, lisp-readonly, free, and uid.
* lrecord.h (set_lheader_implementation): Adjust to new
lrecord_header.
* lrecord.h (struct lrecord_implementation): The field basic_p
for indication of an old lrecord is not needed anymore, remove.
* lrecord.h (MAKE_LRECORD_IMPLEMENTATION): Remove basic_p.
* lrecord.h (MAKE_EXTERNAL_LRECORD_IMPLEMENTATION): Remove
basic_p.
* lrecord.h (copy_sized_lrecord): Remove distinction between
old lrecords and lcrecords.
* lrecord.h (copy_lrecord): Remove distinction between old
lrecords and lcrecords.
* lrecord.h (zero_sized_lrecord): Remove distinction between
old lrecords and lcrecords.
* lrecord.h (zero_lrecord): Remove distinction between old
lrecords and lcrecords.
Remove lcrecords and lcrecord lists:
* alloc.c (basic_alloc_lcrecord): Not needed anymore, remove.
* alloc.c (very_old_free_lcrecord): Not needed anymore, remove.
* alloc.c (copy_lisp_object): No more distinction between
lrecords and lcrecords.
* alloc.c (all_lcrecords): Not needed anymore, remove.
* alloc.c (make_vector_internal): Allocate as lrecord.
* alloc.c (make_bit_vector_internal): Allocate as lrecord.
* alloc.c: Completely remove `lcrecord lists'.
* alloc.c (free_description): Remove.
* alloc.c (lcrecord_list_description): Remove.
* alloc.c (mark_lcrecord_list): Remove.
* alloc.c (make_lcrecord_list): Remove.
* alloc.c (alloc_managed_lcrecord): Remove.
* alloc.c (free_managed_lcrecord): Remove.
* alloc.c (alloc_automanaged_lcrecord): Remove.
* alloc.c (free_lcrecord): Remove.
* alloc.c (lcrecord_stats): Remove.
* alloc.c (tick_lcrecord_stats): Remove.
* alloc.c (disksave_object_finalization_1): Add call to
mc_finalize_for_disksave. Remove the lcrecord way to visit all
objects.
* alloc.c (kkcc_marking): Remove XD_FLAG_FREE_LISP_OBJECT
* alloc.c (sweep_lcrecords_1): Remove.
* alloc.c (common_init_alloc_early): Remove everything related
to lcrecords, remove old lrecord initializations,
* alloc.c (init_lcrecord_lists): Not needed anymore, remove.
* alloc.c (reinit_alloc_early): Remove everything related to
lcrecords.
* alloc.c (init_alloc_once_early): Remove everything related to
lcrecords.
* buffer.c (allocate_buffer): Allocate as lrecord.
* buffer.c (nuke_all_buffer_slots): Use lrecord functions.
* buffer.c (common_init_complex_vars_of_buffer): Allocate as
lrecord.
* buffer.h (struct buffer): Add lrecord_header.
* casetab.c (allocate_case_table): Allocate as lrecord.
* casetab.h (struct Lisp_Case_Table): Add lrecord_header.
* charset.h (struct Lisp_Charset): Add lrecord_header.
* chartab.c (fill_char_table): Use lrecord functions.
* chartab.c (Fmake_char_table): Allocate as lrecord.
* chartab.c (make_char_table_entry): Allocate as lrecord.
* chartab.c (copy_char_table_entry): Allocate as lrecord.
* chartab.c (Fcopy_char_table): Allocate as lrecord.
* chartab.c (put_char_table): Use lrecord functions.
* chartab.h (struct Lisp_Char_Table_Entry): Add lrecord_header.
* chartab.h (struct Lisp_Char_Table): Add lrecord_header.
* console-impl.h (struct console): Add lrecord_header.
* console-msw-impl.h (struct Lisp_Devmode): Add lrecord_header.
* console-msw-impl.h (struct mswindows_dialog_id): Add
lrecord_header.
* console.c (allocate_console): Allocate as lrecord.
* console.c (nuke_all_console_slots): Use lrecord functions.
* console.c (common_init_complex_vars_of_console): Allocate as
lrecord.
* data.c (make_weak_list): Allocate as lrecord.
* data.c (make_weak_box): Allocate as lrecord.
* data.c (make_ephemeron): Allocate as lrecord.
* database.c (struct Lisp_Database): Add lrecord_header.
* database.c (allocate_database): Allocate as lrecord.
* device-impl.h (struct device): Add lrecord_header.
* device-msw.c (allocate_devmode): Allocate as lrecord.
* device.c (nuke_all_device_slots): Use lrecord functions.
* device.c (allocate_device): Allocate as lrecord.
* dialog-msw.c (handle_question_dialog_box): Allocate as lrecord.
* elhash.c (struct Lisp_Hash_Table): Add lrecord_header.
* elhash.c (make_general_lisp_hash_table): Allocate as lrecord.
* elhash.c (Fcopy_hash_table): Allocate as lrecord.
* event-stream.c: Lcrecord lists Vcommand_builder_free_list and
Vtimeout_free_list are no longer needed. Remove.
* event-stream.c (allocate_command_builder): Allocate as lrecord.
* event-stream.c (free_command_builder): Use lrecord functions.
* event-stream.c (event_stream_generate_wakeup): Allocate as
lrecord.
* event-stream.c (event_stream_resignal_wakeup): Use lrecord
functions.
* event-stream.c (event_stream_disable_wakeup): Use lrecord
functions.
* event-stream.c (reinit_vars_of_event_stream): Lcrecord lists
remove.
* events.h (struct Lisp_Timeout): Add lrecord_header.
* events.h (struct command_builder): Add lrecord_header.
* extents-impl.h (struct extent_auxiliary): Add lrecord_header.
* extents-impl.h (struct extent_info): Add lrecord_header.
* extents.c (allocate_extent_auxiliary): Allocate as lrecord.
* extents.c (allocate_extent_info): Allocate as lrecord.
* extents.c (copy_extent): Allocate as lrecord.
* faces.c (allocate_face): Allocate as lrecord.
* faces.h (struct Lisp_Face): Add lrecord_header.
* file-coding.c (allocate_coding_system): Allocate as lrecord.
* file-coding.c (Fcopy_coding_system): Allocate as lrecord.
* file-coding.h (struct Lisp_Coding_System): Add lrecord_header.
* fns.c (Ffillarray): Allocate as lrecord.
* frame-impl.h (struct frame): Add lrecord_header.
* frame.c (nuke_all_frame_slots): Use lrecord functions.
* frame.c (allocate_frame_core): Allocate as lrecord.
* glyphs.c (allocate_image_instance): Allocate as lrecord.
* glyphs.c (Fcolorize_image_instance): Allocate as lrecord.
* glyphs.c (allocate_glyph): Allocate as lrecord.
* glyphs.h (struct Lisp_Image_Instance): Add lrecord_header.
* glyphs.h (struct Lisp_Glyph): Add lrecord_header.
* gui.c (allocate_gui_item): Allocate as lrecord.
* gui.h (struct Lisp_Gui_Item): Add lrecord_header.
* keymap.c (struct Lisp_Keymap): Add lrecord_header.
* keymap.c (make_keymap): Allocate as lrecord.
* lisp.h (struct Lisp_Vector): Add lrecord_header.
* lisp.h (struct Lisp_Bit_Vector): Add lrecord_header.
* lisp.h (struct weak_box): Add lrecord_header.
* lisp.h (struct ephemeron): Add lrecord_header.
* lisp.h (struct weak_list): Add lrecord_header.
* lrecord.h (struct lcrecord_header): Not used, remove.
* lrecord.h (struct free_lcrecord_header): Not used, remove.
* lrecord.h (struct lcrecord_list): Not needed anymore, remove.
* lrecord.h (lcrecord_list): Not needed anymore, remove.
* lrecord.h: (enum data_description_entry_flags): Remove
XD_FLAG_FREE_LISP_OBJECT.
* lstream.c: Lrecord list Vlstream_free_list remove.
* lstream.c (Lstream_new): Allocate as lrecord.
* lstream.c (Lstream_delete): Use lrecod functions.
* lstream.c (reinit_vars_of_lstream): Vlstream_free_list
initialization remove.
* lstream.h (struct lstream): Add lrecord_header.
* emacs.c (main_1): Remove lstream initialization.
* mule-charset.c (make_charset): Allocate as lrecord.
* objects-impl.h (struct Lisp_Color_Instance): Add
lrecord_header.
* objects-impl.h (struct Lisp_Font_Instance): Add lrecord_header.
* objects.c (Fmake_color_instance): Allocate as lrecord.
* objects.c (Fmake_font_instance): Allocate as lrecord.
* objects.c (reinit_vars_of_objects): Allocate as lrecord.
* opaque.c: Lcreord list Vopaque_ptr_list remove.
* opaque.c (make_opaque): Allocate as lrecord.
* opaque.c (make_opaque_ptr): Allocate as lrecord.
* opaque.c (free_opaque_ptr): Use lrecord functions.
* opaque.c (reinit_opaque_early):
* opaque.c (init_opaque_once_early): Vopaque_ptr_list
initialization remove.
* opaque.h (Lisp_Opaque): Add lrecord_header.
* opaque.h (Lisp_Opaque_Ptr): Add lrecord_header.
* emacs.c (main_1): Remove opaque variable initialization.
* print.c (default_object_printer): Use new lrecord_header.
* print.c (print_internal): Use new lrecord_header.
* print.c (debug_p4): Use new lrecord_header.
* process.c (make_process_internal): Allocate as lrecord.
* procimpl.h (struct Lisp_Process): Add lrecord_header.
* rangetab.c (Fmake_range_table): Allocate as lrecord.
* rangetab.c (Fcopy_range_table): Allocate as lrecord.
* rangetab.h (struct Lisp_Range_Table): Add lrecord_header.
* scrollbar.c (create_scrollbar_instance): Allocate as lrecord.
* scrollbar.h (struct scrollbar_instance): Add lrecord_header.
* specifier.c (make_specifier_internal): Allocate as lrecord.
* specifier.h (struct Lisp_Specifier): Add lrecord_header.
* symbols.c:
* symbols.c (Fmake_variable_buffer_local): Allocate as lrecord.
* symbols.c (Fdontusethis_set_symbol_value_handler): Allocate
as lrecord.
* symbols.c (Fdefvaralias): Allocate as lrecord.
* symeval.h (struct symbol_value_magic): Add lrecord_header.
* toolbar.c (update_toolbar_button): Allocate as lrecord.
* toolbar.h (struct toolbar_button): Add lrecord_header.
* tooltalk.c (struct Lisp_Tooltalk_Message): Add lrecord_header.
* tooltalk.c (make_tooltalk_message): Allocate as lrecord.
* tooltalk.c (struct Lisp_Tooltalk_Pattern): Add lrecord_header.
* tooltalk.c (make_tooltalk_pattern): Allocate as lrecord.
* ui-gtk.c (allocate_ffi_data): Allocate as lrecord.
* ui-gtk.c (allocate_emacs_gtk_object_data): Allocate as lrecord.
* ui-gtk.c (allocate_emacs_gtk_boxed_data): Allocate as lrecord.
* ui-gtk.h (structs): Add lrecord_header.
* window-impl.h (struct window): Add lrecord_header.
* window-impl.h (struct window_mirror): Add lrecord_header.
* window.c (allocate_window): Allocate as lrecord.
* window.c (new_window_mirror): Allocate as lrecord.
* window.c (make_dummy_parent): Allocate as lrecord.
MEMORY_USAGE_STATS
* alloc.c (fixed_type_block_overhead): Not used anymore, remove.
* buffer.c (compute_buffer_usage): Get storage size from new
allocator.
* marker.c (compute_buffer_marker_usage): Get storage size from
new allocator.
* mule-charset.c (compute_charset_usage): Get storage size from
new allocator.
* scrollbar-gtk.c (gtk_compute_scrollbar_instance_usage): Get
storage size from new allocator.
* scrollbar-msw.c (mswindows_compute_scrollbar_instance_usage):
Get storage size from new allocator.
* scrollbar-x.c (x_compute_scrollbar_instance_usage): Get
storage size from new allocator.
* scrollbar.c (compute_scrollbar_instance_usage): Get storage
size from new allocator.
* unicode.c (compute_from_unicode_table_size_1): Get storage
size from new allocator.
* unicode.c (compute_to_unicode_table_size_1): Get storage size
from new allocator.
* window.c (compute_window_mirror_usage): Get storage size from
new allocator.
* window.c (compute_window_usage): Get storage size from new
allocator.
MC_ALLOC_TYPE_STATS:
* alloc.c (alloc_lrecord): Bump lrecord count.
* alloc.c (noseeum_alloc_lrecord): Bump lrecord count.
* alloc.c (struct lrecord_stats): Storage for counts.
* alloc.c (init_lrecord_stats): Zero statistics.
* alloc.c (inc_lrecord_stats): Increase the statistic.
* alloc.c (dec_lrecord_stats): Decrease the statistic.
* alloc.c (gc_plist_hack): Used to print the information.
* alloc.c (Fgarbage_collect): Return the collected information.
* mc-alloc.c (remove_cell): Decrease lrecord count.
* mc-alloc.h: Set flag MC_ALLOC_TYPE_STATS.
* emacs.c (main_1): Init lrecord statistics.
* lrecord.h: Add prototypes for *_lrecord_stats.
Strings:
* alloc.c (Fmake_string): Initialize ascii_begin to zero.
* alloc.c (gc_count_num_short_string_in_use): Remove.
* alloc.c (gc_count_string_total_size): Remove.
* alloc.c (gc_count_short_string_total_size): Remove.
* alloc.c (debug_string_purity): Remove.
* alloc.c (debug_string_purity_print): Remove.
* alloc.c (sweep_strings): Remove.
Remove static C-readonly Lisp objects:
* alloc.c (c_readonly): Not needed anymore, remove.
* alloc.c (GC_CHECK_LHEADER_INVARIANTS): Remove some obsolete
lheader invariants assertions.
* buffer.c (DEFVAR_BUFFER_LOCAL_1): Allocate dynamically.
* console.c (DEFVAR_CONSOLE_LOCAL_1): Allocate dynamically.
* gpmevent.c: Indirection via MC_ALLOC_Freceive_gpm_event.
* gpmevent.c (Fgpm_enable): Allocate dynamically.
* gpmevent.c (syms_of_gpmevent): Allocate dynamically.
* lisp.h (C_READONLY): Not needed anymore, remove.
* lisp.h (DEFUN): Allocate dynamically.
* lrecord.h (C_READONLY_RECORD_HEADER_P): Not needed anymore,
remove.
* lrecord.h (SET_C_READONLY_RECORD_HEADER): Not needed anymore,
remove.
* symbols.c (guts_of_unbound_marker):
* symeval.h (defsubr): Allocate dynamically.
* symeval.h (DEFSUBR_MACRO): Allocate dynamically.
* symeval.h (DEFVAR_ SYMVAL_FWD): Allocate dynamically.
* tests.c (TESTS_DEFSUBR): Allocate dynamically.
Definition of mcpro:
* lisp.h: Add mcpro prototypes.
* alloc.c (common_init_alloc_early): Add initialization for
mcpros.
* alloc.c (mcpro_description_1): New.
* alloc.c (mcpro_description): New.
* alloc.c (mcpros_description_1): New.
* alloc.c (mcpros_description): New.
* alloc.c (mcpro_one_name_description_1): New.
* alloc.c (mcpro_one_name_description): New.
* alloc.c (mcpro_names_description_1): New.
* alloc.c (mcpro_names_description): New.
* alloc.c (mcpros): New.
* alloc.c (mcpro_names): New.
* alloc.c (mcpro_1): New.
* alloc.c (mc_pro): New.
* alloc.c (garbage_collect_1): Add mcpros to root set.
Usage of mcpro:
* alloc.c (make_string_nocopy): Add string to root set.
* symbols.c (init_symbols_once_early): Add Qunbound to root set.
Changes to the Portable Dumper:
* alloc.c (FREE_OR_REALLOC_BEGIN): Since dumped objects can be
freed with the new allocator, remove assertion for !DUMPEDP.
* dumper.c: Adjust comments, increase PDUMP_HASHSIZE.
* dumper.c (pdump_make_hash): Shift address only 2 bytes, to
avoid collisions.
* dumper.c (pdump_objects_unmark): No more mark bits within
the object, remove.
* dumper.c (mc_addr_elt): New. Element data structure for mc
hash table.
* dumper.c (pdump_mc_hash): New hash table: `lookup table'.
* dumper.c (pdump_get_mc_addr): New. Lookup for hash table.
* dumper.c (pdump_get_indirect_mc_addr): New. Lookup for
convertibles.
* dumper.c (pdump_put_mc_addr): New. Putter for hash table.
* dumper.c (pdump_dump_mc_data): New. Writes the table for
relocation at load time to the dump file.
* dumper.c (pdump_scan_lisp_objects_by_alignment): New.
Visits all dumped Lisp objects.
* dumper.c (pdump_scan_non_lisp_objects_by_alignment): New.
Visits all other dumped objects.
* dumper.c (pdump_reloc_one_mc): New. Updates all pointers
of an object by using the hash table pdump_mc_hash.
* dumper.c (pdump_reloc_one): Replaced by pdump_reloc_one_mc.
* dumper.c (pdump): Change the structure of the dump file, add
the mc post dump relocation table to dump file.
* dumper.c (pdump_load_finish): Hand all dumped objects to the
new allocator and use the mc post dump relocation table for
relocating the dumped objects at dump file load time, free not
longer used data structures.
* dumper.c (pdump_load): Free the dump file.
* dumper.h: Remove pdump_objects_unmark.
* lrecord.h (DUMPEDP): Dumped objects can be freed, remove.
DUMP_IN_EXEC:
* Makefile.in.in: Linking for and with dump in executable only if
DUMP_IN_EXEC is defined.
* config.h.in: Add new flag `DUMP_IN_EXEC'
* emacs.c: Condition dump-data.h on DUMP_IN_EXEC.
* emacs.c (main_1): Flag `-si' only works if dump image is
written into executable.
Miscellanious
* lrecord.h (enum lrecord_type): Added numbers to all types,
very handy for debugging.
* xemacs.def.in.in: Add mc-alloc functions to make them visible
to the modules.
author | crestani |
---|---|
date | Fri, 08 Apr 2005 23:11:35 +0000 |
parents | 9f70af3ac939 |
children | 861a7995b9fe |
rev | line source |
---|---|
428 | 1 /* XEmacs routines to deal with range tables. |
2 Copyright (C) 1995 Sun Microsystems, Inc. | |
2421 | 3 Copyright (C) 1995, 2002, 2004 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: Not in FSF. */ | |
23 | |
24 /* Written by Ben Wing, August 1995. */ | |
25 | |
26 #include <config.h> | |
27 #include "lisp.h" | |
28 #include "rangetab.h" | |
29 | |
30 Lisp_Object Qrange_tablep; | |
31 Lisp_Object Qrange_table; | |
32 | |
2421 | 33 Lisp_Object Qstart_closed_end_open; |
34 Lisp_Object Qstart_open_end_open; | |
35 Lisp_Object Qstart_closed_end_closed; | |
36 Lisp_Object Qstart_open_end_closed; | |
37 | |
428 | 38 |
39 /************************************************************************/ | |
40 /* Range table object */ | |
41 /************************************************************************/ | |
42 | |
2421 | 43 static enum range_table_type |
44 range_table_symbol_to_type (Lisp_Object symbol) | |
45 { | |
46 if (NILP (symbol)) | |
47 return RANGE_START_CLOSED_END_OPEN; | |
48 | |
49 CHECK_SYMBOL (symbol); | |
50 if (EQ (symbol, Qstart_closed_end_open)) | |
51 return RANGE_START_CLOSED_END_OPEN; | |
52 if (EQ (symbol, Qstart_closed_end_closed)) | |
53 return RANGE_START_CLOSED_END_CLOSED; | |
54 if (EQ (symbol, Qstart_open_end_open)) | |
55 return RANGE_START_OPEN_END_OPEN; | |
56 if (EQ (symbol, Qstart_open_end_closed)) | |
57 return RANGE_START_OPEN_END_CLOSED; | |
58 | |
59 invalid_constant ("Unknown range table type", symbol); | |
60 RETURN_NOT_REACHED (RANGE_START_CLOSED_END_OPEN); | |
61 } | |
62 | |
63 static Lisp_Object | |
64 range_table_type_to_symbol (enum range_table_type type) | |
65 { | |
66 switch (type) | |
67 { | |
68 case RANGE_START_CLOSED_END_OPEN: | |
69 return Qstart_closed_end_open; | |
70 case RANGE_START_CLOSED_END_CLOSED: | |
71 return Qstart_closed_end_closed; | |
72 case RANGE_START_OPEN_END_OPEN: | |
73 return Qstart_open_end_open; | |
74 case RANGE_START_OPEN_END_CLOSED: | |
75 return Qstart_open_end_closed; | |
76 } | |
77 | |
2500 | 78 ABORT (); |
2421 | 79 return Qnil; |
80 } | |
81 | |
428 | 82 /* We use a sorted array of ranges. |
83 | |
84 #### We should be using the gap array stuff from extents.c. This | |
85 is not hard but just requires moving that stuff out of that file. */ | |
86 | |
87 static Lisp_Object | |
88 mark_range_table (Lisp_Object obj) | |
89 { | |
440 | 90 Lisp_Range_Table *rt = XRANGE_TABLE (obj); |
428 | 91 int i; |
92 | |
93 for (i = 0; i < Dynarr_length (rt->entries); i++) | |
94 mark_object (Dynarr_at (rt->entries, i).val); | |
95 return Qnil; | |
96 } | |
97 | |
98 static void | |
2286 | 99 print_range_table (Lisp_Object obj, Lisp_Object printcharfun, |
100 int UNUSED (escapeflag)) | |
428 | 101 { |
440 | 102 Lisp_Range_Table *rt = XRANGE_TABLE (obj); |
428 | 103 int i; |
104 | |
2421 | 105 if (print_readably) |
106 write_fmt_string_lisp (printcharfun, "#s(range-table type %s data (", | |
107 1, range_table_type_to_symbol (rt->type)); | |
108 else | |
109 write_c_string (printcharfun, "#<range-table "); | |
428 | 110 for (i = 0; i < Dynarr_length (rt->entries); i++) |
111 { | |
112 struct range_table_entry *rte = Dynarr_atp (rt->entries, i); | |
2421 | 113 int so, ec; |
428 | 114 if (i > 0) |
826 | 115 write_c_string (printcharfun, " "); |
2421 | 116 switch (rt->type) |
117 { | |
118 case RANGE_START_CLOSED_END_OPEN: so = 0, ec = 0; break; | |
119 case RANGE_START_CLOSED_END_CLOSED: so = 0, ec = 1; break; | |
120 case RANGE_START_OPEN_END_OPEN: so = 1, ec = 0; break; | |
121 case RANGE_START_OPEN_END_CLOSED: so = 1; ec = 1; break; | |
2500 | 122 default: ABORT (); so = 0, ec = 0; break; |
2421 | 123 } |
124 write_fmt_string (printcharfun, "%c%ld %ld%c ", | |
125 print_readably ? '(' : so ? '(' : '[', | |
126 (long) (rte->first - so), | |
127 (long) (rte->last - ec), | |
128 print_readably ? ')' : ec ? ']' : ')' | |
129 ); | |
428 | 130 print_internal (rte->val, printcharfun, 1); |
131 } | |
2421 | 132 if (print_readably) |
133 write_c_string (printcharfun, "))"); | |
134 else | |
135 write_fmt_string (printcharfun, " 0x%x>", rt->header.uid); | |
428 | 136 } |
137 | |
138 static int | |
139 range_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
140 { | |
440 | 141 Lisp_Range_Table *rt1 = XRANGE_TABLE (obj1); |
142 Lisp_Range_Table *rt2 = XRANGE_TABLE (obj2); | |
428 | 143 int i; |
144 | |
145 if (Dynarr_length (rt1->entries) != Dynarr_length (rt2->entries)) | |
146 return 0; | |
147 | |
148 for (i = 0; i < Dynarr_length (rt1->entries); i++) | |
149 { | |
150 struct range_table_entry *rte1 = Dynarr_atp (rt1->entries, i); | |
151 struct range_table_entry *rte2 = Dynarr_atp (rt2->entries, i); | |
152 | |
153 if (rte1->first != rte2->first | |
154 || rte1->last != rte2->last | |
155 || !internal_equal (rte1->val, rte2->val, depth + 1)) | |
156 return 0; | |
157 } | |
158 | |
159 return 1; | |
160 } | |
161 | |
2515 | 162 static Hashcode |
428 | 163 range_table_entry_hash (struct range_table_entry *rte, int depth) |
164 { | |
165 return HASH3 (rte->first, rte->last, internal_hash (rte->val, depth + 1)); | |
166 } | |
167 | |
2515 | 168 static Hashcode |
428 | 169 range_table_hash (Lisp_Object obj, int depth) |
170 { | |
440 | 171 Lisp_Range_Table *rt = XRANGE_TABLE (obj); |
428 | 172 int i; |
173 int size = Dynarr_length (rt->entries); | |
2515 | 174 Hashcode hash = size; |
428 | 175 |
176 /* approach based on internal_array_hash(). */ | |
177 if (size <= 5) | |
178 { | |
179 for (i = 0; i < size; i++) | |
180 hash = HASH2 (hash, | |
181 range_table_entry_hash (Dynarr_atp (rt->entries, i), | |
182 depth)); | |
183 return hash; | |
184 } | |
185 | |
186 /* just pick five elements scattered throughout the array. | |
187 A slightly better approach would be to offset by some | |
188 noise factor from the points chosen below. */ | |
189 for (i = 0; i < 5; i++) | |
190 hash = HASH2 (hash, range_table_entry_hash (Dynarr_atp (rt->entries, | |
191 i*size/5), | |
192 depth)); | |
193 return hash; | |
194 } | |
195 | |
1204 | 196 static const struct memory_description rte_description_1[] = { |
440 | 197 { XD_LISP_OBJECT, offsetof (range_table_entry, val) }, |
428 | 198 { XD_END } |
199 }; | |
200 | |
1204 | 201 static const struct sized_memory_description rte_description = { |
440 | 202 sizeof (range_table_entry), |
428 | 203 rte_description_1 |
204 }; | |
205 | |
1204 | 206 static const struct memory_description rted_description_1[] = { |
440 | 207 XD_DYNARR_DESC (range_table_entry_dynarr, &rte_description), |
428 | 208 { XD_END } |
209 }; | |
210 | |
1204 | 211 static const struct sized_memory_description rted_description = { |
440 | 212 sizeof (range_table_entry_dynarr), |
428 | 213 rted_description_1 |
214 }; | |
215 | |
1204 | 216 static const struct memory_description range_table_description[] = { |
2551 | 217 { XD_BLOCK_PTR, offsetof (Lisp_Range_Table, entries), 1, |
218 { &rted_description } }, | |
428 | 219 { XD_END } |
220 }; | |
221 | |
934 | 222 DEFINE_LRECORD_IMPLEMENTATION ("range-table", range_table, |
223 1, /*dumpable-flag*/ | |
224 mark_range_table, print_range_table, 0, | |
225 range_table_equal, range_table_hash, | |
226 range_table_description, | |
227 Lisp_Range_Table); | |
428 | 228 |
229 /************************************************************************/ | |
230 /* Range table operations */ | |
231 /************************************************************************/ | |
232 | |
800 | 233 #ifdef ERROR_CHECK_STRUCTURES |
428 | 234 |
235 static void | |
440 | 236 verify_range_table (Lisp_Range_Table *rt) |
428 | 237 { |
238 int i; | |
239 | |
240 for (i = 0; i < Dynarr_length (rt->entries); i++) | |
241 { | |
242 struct range_table_entry *rte = Dynarr_atp (rt->entries, i); | |
243 assert (rte->last >= rte->first); | |
244 if (i > 0) | |
2421 | 245 assert (Dynarr_at (rt->entries, i - 1).last <= rte->first); |
428 | 246 } |
247 } | |
248 | |
249 #else | |
250 | |
251 #define verify_range_table(rt) | |
252 | |
253 #endif | |
254 | |
255 /* Look up in a range table without the Dynarr wrapper. | |
256 Used also by the unified range table format. */ | |
257 | |
258 static Lisp_Object | |
259 get_range_table (EMACS_INT pos, int nentries, struct range_table_entry *tab, | |
260 Lisp_Object default_) | |
261 { | |
262 int left = 0, right = nentries; | |
263 | |
264 /* binary search for the entry. Based on similar code in | |
265 extent_list_locate(). */ | |
266 while (left != right) | |
267 { | |
268 /* RIGHT might not point to a valid entry (i.e. it's at the end | |
269 of the list), so NEWPOS must round down. */ | |
647 | 270 int newpos = (left + right) >> 1; |
428 | 271 struct range_table_entry *entry = tab + newpos; |
2421 | 272 if (pos >= entry->last) |
273 left = newpos + 1; | |
428 | 274 else if (pos < entry->first) |
275 right = newpos; | |
276 else | |
277 return entry->val; | |
278 } | |
279 | |
280 return default_; | |
281 } | |
282 | |
283 DEFUN ("range-table-p", Frange_table_p, 1, 1, 0, /* | |
284 Return non-nil if OBJECT is a range table. | |
285 */ | |
286 (object)) | |
287 { | |
288 return RANGE_TABLEP (object) ? Qt : Qnil; | |
289 } | |
290 | |
2421 | 291 DEFUN ("range-table-type", Frange_table_type, 1, 1, 0, /* |
292 Return non-nil if OBJECT is a range table. | |
293 */ | |
294 (range_table)) | |
295 { | |
296 CHECK_RANGE_TABLE (range_table); | |
297 return range_table_type_to_symbol (XRANGE_TABLE (range_table)->type); | |
298 } | |
299 | |
300 DEFUN ("make-range-table", Fmake_range_table, 0, 1, 0, /* | |
428 | 301 Return a new, empty range table. |
302 You can manipulate it using `put-range-table', `get-range-table', | |
303 `remove-range-table', and `clear-range-table'. | |
2421 | 304 Range tables allow you to efficiently set values for ranges of integers. |
305 | |
306 TYPE is a symbol indicating how ranges are assumed to function at their | |
307 ends. It can be one of | |
308 | |
309 SYMBOL RANGE-START RANGE-END | |
310 ------ ----------- --------- | |
311 `start-closed-end-open' (the default) closed open | |
312 `start-closed-end-closed' closed closed | |
313 `start-open-end-open' open open | |
314 `start-open-end-closed' open closed | |
315 | |
316 A `closed' endpoint of a range means that the number at that end is included | |
317 in the range. For an `open' endpoint, the number would not be included. | |
318 | |
319 For example, a closed-open range from 5 to 20 would be indicated as [5, | |
320 20) where a bracket indicates a closed end and a parenthesis an open end, | |
321 and would mean `all the numbers between 5 and 20', including 5 but not 20. | |
322 This seems a little strange at first but is in fact extremely common in | |
323 the outside world as well as in computers and makes things work sensibly. | |
324 For example, if I say "there are seven days between today and next week | |
325 today", I'm including today but not next week today; if I included both, | |
326 there would be eight days. Similarly, there are 15 (= 20 - 5) elements in | |
327 the range [5, 20), but 16 in the range [5, 20]. | |
428 | 328 */ |
2421 | 329 (type)) |
428 | 330 { |
2720 | 331 #ifdef MC_ALLOC |
332 Lisp_Range_Table *rt = alloc_lrecord_type (Lisp_Range_Table, | |
333 &lrecord_range_table); | |
334 #else /* not MC_ALLOC */ | |
440 | 335 Lisp_Range_Table *rt = alloc_lcrecord_type (Lisp_Range_Table, |
336 &lrecord_range_table); | |
2720 | 337 #endif /* not MC_ALLOC */ |
428 | 338 rt->entries = Dynarr_new (range_table_entry); |
2421 | 339 rt->type = range_table_symbol_to_type (type); |
793 | 340 return wrap_range_table (rt); |
428 | 341 } |
342 | |
343 DEFUN ("copy-range-table", Fcopy_range_table, 1, 1, 0, /* | |
444 | 344 Return a new range table which is a copy of RANGE-TABLE. |
345 It will contain the same values for the same ranges as RANGE-TABLE. | |
346 The values will not themselves be copied. | |
428 | 347 */ |
444 | 348 (range_table)) |
428 | 349 { |
440 | 350 Lisp_Range_Table *rt, *rtnew; |
428 | 351 |
444 | 352 CHECK_RANGE_TABLE (range_table); |
353 rt = XRANGE_TABLE (range_table); | |
428 | 354 |
2720 | 355 #ifdef MC_ALLOC |
356 rtnew = alloc_lrecord_type (Lisp_Range_Table, &lrecord_range_table); | |
357 #else /* not MC_ALLOC */ | |
440 | 358 rtnew = alloc_lcrecord_type (Lisp_Range_Table, &lrecord_range_table); |
2720 | 359 #endif /* not MC_ALLOC */ |
428 | 360 rtnew->entries = Dynarr_new (range_table_entry); |
2421 | 361 rtnew->type = rt->type; |
428 | 362 |
363 Dynarr_add_many (rtnew->entries, Dynarr_atp (rt->entries, 0), | |
364 Dynarr_length (rt->entries)); | |
793 | 365 return wrap_range_table (rtnew); |
428 | 366 } |
367 | |
368 DEFUN ("get-range-table", Fget_range_table, 2, 3, 0, /* | |
444 | 369 Find value for position POS in RANGE-TABLE. |
428 | 370 If there is no corresponding value, return DEFAULT (defaults to nil). |
371 */ | |
444 | 372 (pos, range_table, default_)) |
428 | 373 { |
440 | 374 Lisp_Range_Table *rt; |
428 | 375 |
444 | 376 CHECK_RANGE_TABLE (range_table); |
377 rt = XRANGE_TABLE (range_table); | |
428 | 378 |
379 CHECK_INT_COERCE_CHAR (pos); | |
380 | |
381 return get_range_table (XINT (pos), Dynarr_length (rt->entries), | |
382 Dynarr_atp (rt->entries, 0), default_); | |
383 } | |
384 | |
385 void | |
386 put_range_table (Lisp_Object table, EMACS_INT first, | |
387 EMACS_INT last, Lisp_Object val) | |
388 { | |
389 int i; | |
390 int insert_me_here = -1; | |
440 | 391 Lisp_Range_Table *rt = XRANGE_TABLE (table); |
428 | 392 |
2421 | 393 /* Fix up the numbers in accordance with the open/closedness to make |
394 them behave like default open/closed. */ | |
395 | |
396 switch (rt->type) | |
397 { | |
398 case RANGE_START_CLOSED_END_OPEN: break; | |
399 case RANGE_START_CLOSED_END_CLOSED: last++; break; | |
400 case RANGE_START_OPEN_END_OPEN: first++; break; | |
401 case RANGE_START_OPEN_END_CLOSED: first++, last++; break; | |
402 } | |
403 | |
404 if (first == last) | |
405 return; | |
406 if (first > last) | |
407 /* This will happen if originally first == last and both ends are | |
408 open. #### Should we signal an error? */ | |
409 return; | |
410 | |
428 | 411 /* Now insert in the proper place. This gets tricky because |
412 we may be overlapping one or more existing ranges and need | |
413 to fix them up. */ | |
414 | |
415 /* First delete all sections of any existing ranges that overlap | |
416 the new range. */ | |
417 for (i = 0; i < Dynarr_length (rt->entries); i++) | |
418 { | |
419 struct range_table_entry *entry = Dynarr_atp (rt->entries, i); | |
420 /* We insert before the first range that begins at or after the | |
421 new range. */ | |
422 if (entry->first >= first && insert_me_here < 0) | |
423 insert_me_here = i; | |
424 if (entry->last < first) | |
425 /* completely before the new range. */ | |
426 continue; | |
427 if (entry->first > last) | |
428 /* completely after the new range. No more possibilities of | |
429 finding overlapping ranges. */ | |
430 break; | |
2421 | 431 /* At this point the existing ENTRY overlaps or touches the new one. */ |
428 | 432 if (entry->first < first && entry->last <= last) |
433 { | |
434 /* looks like: | |
435 | |
2421 | 436 [ NEW ) |
437 [ EXISTING ) | |
438 | |
439 or | |
440 | |
441 [ NEW ) | |
442 [ EXISTING ) | |
428 | 443 |
444 */ | |
445 /* truncate the end off of it. */ | |
2421 | 446 entry->last = first; |
428 | 447 } |
448 else if (entry->first < first && entry->last > last) | |
449 /* looks like: | |
450 | |
2421 | 451 [ NEW ) |
452 [ EXISTING ) | |
428 | 453 |
454 */ | |
455 /* need to split this one in two. */ | |
456 { | |
457 struct range_table_entry insert_me_too; | |
458 | |
2421 | 459 insert_me_too.first = last; |
428 | 460 insert_me_too.last = entry->last; |
461 insert_me_too.val = entry->val; | |
2421 | 462 entry->last = first; |
428 | 463 Dynarr_insert_many (rt->entries, &insert_me_too, 1, i + 1); |
464 } | |
2421 | 465 else if (entry->last >= last) |
428 | 466 { |
467 /* looks like: | |
468 | |
2421 | 469 [ NEW ) |
470 [ EXISTING ) | |
471 | |
472 or | |
473 | |
474 [ NEW ) | |
475 [ EXISTING ) | |
428 | 476 |
477 */ | |
478 /* truncate the start off of it. */ | |
2421 | 479 entry->first = last; |
428 | 480 } |
481 else | |
482 { | |
483 /* existing is entirely within new. */ | |
484 Dynarr_delete_many (rt->entries, i, 1); | |
485 i--; /* back up since everything shifted one to the left. */ | |
486 } | |
487 } | |
488 | |
489 /* Someone asked us to delete the range, not insert it. */ | |
490 if (UNBOUNDP (val)) | |
491 return; | |
492 | |
493 /* Now insert the new entry, maybe at the end. */ | |
494 | |
495 if (insert_me_here < 0) | |
496 insert_me_here = i; | |
497 | |
498 { | |
499 struct range_table_entry insert_me; | |
500 | |
501 insert_me.first = first; | |
502 insert_me.last = last; | |
503 insert_me.val = val; | |
504 | |
505 Dynarr_insert_many (rt->entries, &insert_me, 1, insert_me_here); | |
506 } | |
507 | |
508 /* Now see if we can combine this entry with adjacent ones just | |
509 before or after. */ | |
510 | |
511 if (insert_me_here > 0) | |
512 { | |
513 struct range_table_entry *entry = Dynarr_atp (rt->entries, | |
514 insert_me_here - 1); | |
2421 | 515 if (EQ (val, entry->val) && entry->last == first) |
428 | 516 { |
517 entry->last = last; | |
518 Dynarr_delete_many (rt->entries, insert_me_here, 1); | |
519 insert_me_here--; | |
520 /* We have morphed into a larger range. Update our records | |
521 in case we also combine with the one after. */ | |
522 first = entry->first; | |
523 } | |
524 } | |
525 | |
526 if (insert_me_here < Dynarr_length (rt->entries) - 1) | |
527 { | |
528 struct range_table_entry *entry = Dynarr_atp (rt->entries, | |
529 insert_me_here + 1); | |
2421 | 530 if (EQ (val, entry->val) && entry->first == last) |
428 | 531 { |
532 entry->first = first; | |
533 Dynarr_delete_many (rt->entries, insert_me_here, 1); | |
534 } | |
535 } | |
536 } | |
537 | |
538 DEFUN ("put-range-table", Fput_range_table, 4, 4, 0, /* | |
2421 | 539 Set the value for range START .. END to be VALUE in RANGE-TABLE. |
428 | 540 */ |
444 | 541 (start, end, value, range_table)) |
428 | 542 { |
543 EMACS_INT first, last; | |
544 | |
444 | 545 CHECK_RANGE_TABLE (range_table); |
428 | 546 CHECK_INT_COERCE_CHAR (start); |
547 first = XINT (start); | |
548 CHECK_INT_COERCE_CHAR (end); | |
549 last = XINT (end); | |
550 if (first > last) | |
563 | 551 invalid_argument_2 ("start must be <= end", start, end); |
428 | 552 |
444 | 553 put_range_table (range_table, first, last, value); |
554 verify_range_table (XRANGE_TABLE (range_table)); | |
428 | 555 return Qnil; |
556 } | |
557 | |
558 DEFUN ("remove-range-table", Fremove_range_table, 3, 3, 0, /* | |
2421 | 559 Remove the value for range START .. END in RANGE-TABLE. |
428 | 560 */ |
444 | 561 (start, end, range_table)) |
428 | 562 { |
444 | 563 return Fput_range_table (start, end, Qunbound, range_table); |
428 | 564 } |
565 | |
566 DEFUN ("clear-range-table", Fclear_range_table, 1, 1, 0, /* | |
444 | 567 Flush RANGE-TABLE. |
428 | 568 */ |
444 | 569 (range_table)) |
428 | 570 { |
444 | 571 CHECK_RANGE_TABLE (range_table); |
572 Dynarr_reset (XRANGE_TABLE (range_table)->entries); | |
428 | 573 return Qnil; |
574 } | |
575 | |
576 DEFUN ("map-range-table", Fmap_range_table, 2, 2, 0, /* | |
444 | 577 Map FUNCTION over entries in RANGE-TABLE, calling it with three args, |
428 | 578 the beginning and end of the range and the corresponding value. |
442 | 579 |
580 Results are guaranteed to be correct (i.e. each entry processed | |
581 exactly once) if FUNCTION modifies or deletes the current entry | |
444 | 582 \(i.e. passes the current range to `put-range-table' or |
442 | 583 `remove-range-table'), but not otherwise. |
428 | 584 */ |
444 | 585 (function, range_table)) |
428 | 586 { |
442 | 587 Lisp_Range_Table *rt; |
588 int i; | |
589 | |
444 | 590 CHECK_RANGE_TABLE (range_table); |
442 | 591 CHECK_FUNCTION (function); |
592 | |
444 | 593 rt = XRANGE_TABLE (range_table); |
442 | 594 |
595 /* Do not "optimize" by pulling out the length computation below! | |
596 FUNCTION may have changed the table. */ | |
597 for (i = 0; i < Dynarr_length (rt->entries); i++) | |
598 { | |
599 struct range_table_entry *entry = Dynarr_atp (rt->entries, i); | |
600 EMACS_INT first, last; | |
601 Lisp_Object args[4]; | |
602 int oldlen; | |
603 | |
604 again: | |
605 first = entry->first; | |
606 last = entry->last; | |
607 oldlen = Dynarr_length (rt->entries); | |
608 args[0] = function; | |
609 args[1] = make_int (first); | |
610 args[2] = make_int (last); | |
611 args[3] = entry->val; | |
612 Ffuncall (countof (args), args); | |
613 /* Has FUNCTION removed the entry? */ | |
614 if (oldlen > Dynarr_length (rt->entries) | |
615 && i < Dynarr_length (rt->entries) | |
616 && (first != entry->first || last != entry->last)) | |
617 goto again; | |
618 } | |
619 | |
428 | 620 return Qnil; |
621 } | |
622 | |
623 | |
624 /************************************************************************/ | |
625 /* Range table read syntax */ | |
626 /************************************************************************/ | |
627 | |
628 static int | |
2421 | 629 rangetab_type_validate (Lisp_Object UNUSED (keyword), Lisp_Object value, |
630 Error_Behavior UNUSED (errb)) | |
631 { | |
632 /* #### should deal with ERRB */ | |
633 range_table_symbol_to_type (value); | |
634 return 1; | |
635 } | |
636 | |
637 static int | |
2286 | 638 rangetab_data_validate (Lisp_Object UNUSED (keyword), Lisp_Object value, |
639 Error_Behavior UNUSED (errb)) | |
428 | 640 { |
2367 | 641 /* #### should deal with ERRB */ |
642 EXTERNAL_PROPERTY_LIST_LOOP_3 (range, data, value) | |
428 | 643 { |
644 if (!INTP (range) && !CHARP (range) | |
645 && !(CONSP (range) && CONSP (XCDR (range)) | |
646 && NILP (XCDR (XCDR (range))) | |
647 && (INTP (XCAR (range)) || CHARP (XCAR (range))) | |
648 && (INTP (XCAR (XCDR (range))) || CHARP (XCAR (XCDR (range)))))) | |
563 | 649 sferror ("Invalid range format", range); |
428 | 650 } |
651 | |
652 return 1; | |
653 } | |
654 | |
655 static Lisp_Object | |
2421 | 656 rangetab_instantiate (Lisp_Object plist) |
428 | 657 { |
2425 | 658 Lisp_Object data = Qnil, type = Qnil, rangetab; |
428 | 659 |
2421 | 660 PROPERTY_LIST_LOOP_3 (key, value, plist) |
428 | 661 { |
2421 | 662 if (EQ (key, Qtype)) type = value; |
663 else if (EQ (key, Qdata)) data = value; | |
664 else | |
2500 | 665 ABORT (); |
2421 | 666 } |
667 | |
2425 | 668 rangetab = Fmake_range_table (type); |
428 | 669 |
2421 | 670 { |
671 PROPERTY_LIST_LOOP_3 (range, val, data) | |
672 { | |
673 if (CONSP (range)) | |
674 Fput_range_table (Fcar (range), Fcar (Fcdr (range)), val, | |
675 rangetab); | |
676 else | |
677 Fput_range_table (range, range, val, rangetab); | |
678 } | |
679 } | |
428 | 680 |
681 return rangetab; | |
682 } | |
683 | |
684 | |
685 /************************************************************************/ | |
686 /* Unified range tables */ | |
687 /************************************************************************/ | |
688 | |
689 /* A "unified range table" is a format for storing range tables | |
690 as contiguous blocks of memory. This is used by the regexp | |
691 code, which needs to use range tables to properly handle [] | |
692 constructs in the presence of extended characters but wants to | |
693 store an entire compiled pattern as a contiguous block of memory. | |
694 | |
695 Unified range tables are designed so that they can be placed | |
696 at an arbitrary (possibly mis-aligned) place in memory. | |
697 (Dealing with alignment is a pain in the ass.) | |
698 | |
699 WARNING: No provisions for garbage collection are currently made. | |
700 This means that there must not be any Lisp objects in a unified | |
701 range table that need to be marked for garbage collection. | |
702 Good candidates for objects that can go into a range table are | |
703 | |
704 -- numbers and characters (do not need to be marked) | |
705 -- nil, t (marked elsewhere) | |
706 -- charsets and coding systems (automatically marked because | |
707 they are in a marked list, | |
708 and can't be removed) | |
709 | |
710 Good but slightly less so: | |
711 | |
712 -- symbols (could be uninterned, but that is not likely) | |
713 | |
714 Somewhat less good: | |
715 | |
716 -- buffers, frames, devices (could get deleted) | |
717 | |
718 | |
719 It is expected that you work with range tables in the normal | |
720 format and then convert to unified format when you are done | |
721 making modifications. As such, no functions are provided | |
722 for modifying a unified range table. The only operations | |
723 you can do to unified range tables are | |
724 | |
725 -- look up a value | |
726 -- retrieve all the ranges in an iterative fashion | |
727 | |
728 */ | |
729 | |
730 /* The format of a unified range table is as follows: | |
731 | |
732 -- The first byte contains the number of bytes to skip to find the | |
733 actual start of the table. This deals with alignment constraints, | |
734 since the table might want to go at any arbitrary place in memory. | |
735 -- The next three bytes contain the number of bytes to skip (from the | |
736 *first* byte) to find the stuff after the table. It's stored in | |
737 little-endian format because that's how God intended things. We don't | |
738 necessarily start the stuff at the very end of the table because | |
739 we want to have at least ALIGNOF (EMACS_INT) extra space in case | |
740 we have to move the range table around. (It appears that some | |
741 architectures don't maintain alignment when reallocing.) | |
742 -- At the prescribed offset is a struct unified_range_table, containing | |
743 some number of `struct range_table_entry' entries. */ | |
744 | |
745 struct unified_range_table | |
746 { | |
747 int nentries; | |
748 struct range_table_entry first; | |
749 }; | |
750 | |
751 /* Return size in bytes needed to store the data in a range table. */ | |
752 | |
753 int | |
754 unified_range_table_bytes_needed (Lisp_Object rangetab) | |
755 { | |
756 return (sizeof (struct range_table_entry) * | |
757 (Dynarr_length (XRANGE_TABLE (rangetab)->entries) - 1) + | |
758 sizeof (struct unified_range_table) + | |
759 /* ALIGNOF a struct may be too big. */ | |
760 /* We have four bytes for the size numbers, and an extra | |
761 four or eight bytes for making sure we get the alignment | |
762 OK. */ | |
763 ALIGNOF (EMACS_INT) + 4); | |
764 } | |
765 | |
766 /* Convert a range table into unified format and store in DEST, | |
767 which must be able to hold the number of bytes returned by | |
768 range_table_bytes_needed(). */ | |
769 | |
770 void | |
771 unified_range_table_copy_data (Lisp_Object rangetab, void *dest) | |
772 { | |
773 /* We cast to the above structure rather than just casting to | |
774 char * and adding sizeof(int), because that will lead to | |
775 mis-aligned data on the Alpha machines. */ | |
776 struct unified_range_table *un; | |
777 range_table_entry_dynarr *rted = XRANGE_TABLE (rangetab)->entries; | |
778 int total_needed = unified_range_table_bytes_needed (rangetab); | |
826 | 779 void *new_dest = ALIGN_PTR ((char *) dest + 4, EMACS_INT); |
428 | 780 |
781 * (char *) dest = (char) ((char *) new_dest - (char *) dest); | |
782 * ((unsigned char *) dest + 1) = total_needed & 0xFF; | |
783 total_needed >>= 8; | |
784 * ((unsigned char *) dest + 2) = total_needed & 0xFF; | |
785 total_needed >>= 8; | |
786 * ((unsigned char *) dest + 3) = total_needed & 0xFF; | |
787 un = (struct unified_range_table *) new_dest; | |
788 un->nentries = Dynarr_length (rted); | |
789 memcpy (&un->first, Dynarr_atp (rted, 0), | |
790 sizeof (struct range_table_entry) * Dynarr_length (rted)); | |
791 } | |
792 | |
793 /* Return number of bytes actually used by a unified range table. */ | |
794 | |
795 int | |
796 unified_range_table_bytes_used (void *unrangetab) | |
797 { | |
798 return ((* ((unsigned char *) unrangetab + 1)) | |
799 + ((* ((unsigned char *) unrangetab + 2)) << 8) | |
800 + ((* ((unsigned char *) unrangetab + 3)) << 16)); | |
801 } | |
802 | |
803 /* Make sure the table is aligned, and move it around if it's not. */ | |
804 static void | |
805 align_the_damn_table (void *unrangetab) | |
806 { | |
807 void *cur_dest = (char *) unrangetab + * (char *) unrangetab; | |
826 | 808 if (cur_dest != ALIGN_PTR (cur_dest, EMACS_INT)) |
428 | 809 { |
810 int count = (unified_range_table_bytes_used (unrangetab) - 4 | |
811 - ALIGNOF (EMACS_INT)); | |
812 /* Find the proper location, just like above. */ | |
826 | 813 void *new_dest = ALIGN_PTR ((char *) unrangetab + 4, EMACS_INT); |
428 | 814 /* memmove() works in the presence of overlapping data. */ |
815 memmove (new_dest, cur_dest, count); | |
816 * (char *) unrangetab = (char) ((char *) new_dest - (char *) unrangetab); | |
817 } | |
818 } | |
819 | |
820 /* Look up a value in a unified range table. */ | |
821 | |
822 Lisp_Object | |
823 unified_range_table_lookup (void *unrangetab, EMACS_INT pos, | |
824 Lisp_Object default_) | |
825 { | |
826 void *new_dest; | |
827 struct unified_range_table *un; | |
828 | |
829 align_the_damn_table (unrangetab); | |
830 new_dest = (char *) unrangetab + * (char *) unrangetab; | |
831 un = (struct unified_range_table *) new_dest; | |
832 | |
833 return get_range_table (pos, un->nentries, &un->first, default_); | |
834 } | |
835 | |
836 /* Return number of entries in a unified range table. */ | |
837 | |
838 int | |
839 unified_range_table_nentries (void *unrangetab) | |
840 { | |
841 void *new_dest; | |
842 struct unified_range_table *un; | |
843 | |
844 align_the_damn_table (unrangetab); | |
845 new_dest = (char *) unrangetab + * (char *) unrangetab; | |
846 un = (struct unified_range_table *) new_dest; | |
847 return un->nentries; | |
848 } | |
849 | |
850 /* Return the OFFSETth range (counting from 0) in UNRANGETAB. */ | |
851 void | |
852 unified_range_table_get_range (void *unrangetab, int offset, | |
853 EMACS_INT *min, EMACS_INT *max, | |
854 Lisp_Object *val) | |
855 { | |
856 void *new_dest; | |
857 struct unified_range_table *un; | |
858 struct range_table_entry *tab; | |
859 | |
860 align_the_damn_table (unrangetab); | |
861 new_dest = (char *) unrangetab + * (char *) unrangetab; | |
862 un = (struct unified_range_table *) new_dest; | |
863 | |
864 assert (offset >= 0 && offset < un->nentries); | |
865 tab = (&un->first) + offset; | |
866 *min = tab->first; | |
867 *max = tab->last; | |
868 *val = tab->val; | |
869 } | |
870 | |
871 | |
872 /************************************************************************/ | |
873 /* Initialization */ | |
874 /************************************************************************/ | |
875 | |
876 void | |
877 syms_of_rangetab (void) | |
878 { | |
442 | 879 INIT_LRECORD_IMPLEMENTATION (range_table); |
880 | |
563 | 881 DEFSYMBOL_MULTIWORD_PREDICATE (Qrange_tablep); |
882 DEFSYMBOL (Qrange_table); | |
428 | 883 |
2421 | 884 DEFSYMBOL (Qstart_closed_end_open); |
885 DEFSYMBOL (Qstart_open_end_open); | |
886 DEFSYMBOL (Qstart_closed_end_closed); | |
887 DEFSYMBOL (Qstart_open_end_closed); | |
888 | |
428 | 889 DEFSUBR (Frange_table_p); |
2421 | 890 DEFSUBR (Frange_table_type); |
428 | 891 DEFSUBR (Fmake_range_table); |
892 DEFSUBR (Fcopy_range_table); | |
893 DEFSUBR (Fget_range_table); | |
894 DEFSUBR (Fput_range_table); | |
895 DEFSUBR (Fremove_range_table); | |
896 DEFSUBR (Fclear_range_table); | |
897 DEFSUBR (Fmap_range_table); | |
898 } | |
899 | |
900 void | |
901 structure_type_create_rangetab (void) | |
902 { | |
903 struct structure_type *st; | |
904 | |
905 st = define_structure_type (Qrange_table, 0, rangetab_instantiate); | |
906 | |
907 define_structure_type_keyword (st, Qdata, rangetab_data_validate); | |
2421 | 908 define_structure_type_keyword (st, Qtype, rangetab_type_validate); |
428 | 909 } |