1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-04-05 13:51:09 -07:00
Commit graph

188162 commits

Author SHA1 Message Date
Helmut Eller
3fbf4dc9ac Don't call record_unwind_protect_ptr with a GCed pointer
* src/xmenu.c (create_and_show_popup_menu): Use record_unwind_protect
instead of record_unwind_protect_ptr.
(leave_toolkit_menu): Use a Lisp_Object instead of a untagged pointer.
2025-11-10 12:35:21 +01:00
Helmut Eller
f536751c7a Fix indentation of recent commits
* src/fns.c (strong_copy_hash_table):
* src/xterm.c (x_cache_xi_devices, xi_disable_devices): clang-format's
output does not comform to Emacs coding conventions.
2025-11-10 12:33:18 +01:00
Gerd Möllmann
87b7b29718 Revert "Alternative implementation of constants in .eln files"
This reverts commit a93ee02873
because it is missing some important other changes.
2025-11-10 12:16:04 +01:00
Gerd Möllmann
a93ee02873 Alternative implementation of constants in .eln files
* src/comp.h (USE_POINTER_TO_CONSTANT_VECTOR): If defined, don't
use vectors.
(Lisp_Native_Comp_Unit): Make data_relocs and data_eph_relocs
pointers to Lisp_Object pointers.

* src/comp.c (ABI_VERSION): Increase to 13.
(check_comp_unit_relocs): Don't check if pointers are used.
* src/comp.c (load_comp_unit, Fcomp__register_lambda): Handle
case that constant vectors are pointers.
* src/comp.c (emit_static_object): Add some FIXME comments.
(declare_imported_data_relocs): Handle case of pointers to
constants vectors differently.
* src/comp.c (declare_imported_data_relocs): Make array elemen
type volatile.
* src/comp.c (comp_t): Add n_data_relocs and
n_data_relocs_ephemeral.
(obj_to_reloc): Set array length correctly.
(declare_imported_data_relocs): Return # of constants.
(declare_imported_data): Set comp's number of constants.

* src/igc.c (root_create_exact_ptr, igc_root_create_exact_ptr):
Return root list node.
* src/igc.h (igc_root_create_exact_ptr): Change return type.

* src/pdumper.c (dump_do_dump_relocation): Don't do fixup if
using pointers to constants vectors.

* src/comp.h (struct Lisp_Native_Comp_Unit): Add member
data_eph_vec.
* src/comp.c (load_comp_unit): Use data_eph_vec to protect the
eph constants.
2025-11-10 11:21:50 +01:00
Eli Zaretskii
df20ffeb78 ; Avoid compilation warnings in emacs-module-tests
* test/src/emacs-module-resources/mod-test.c
(Fmod_test_address_to_userptr, Fmod_test_userptr_to_address):
Avoid compilation warnings when 'intmax_t' is a 64-bit type, while
pointers are 32-bit wide.
2025-11-08 13:39:10 +02:00
Pip Cet
67fabb7488 Assert that misc and user pointers don't point to MPS memory
* src/alloc.c (make_misc_ptr, make_user_ptr): Call
'igc_assert_not_an_mps_object'.
* src/igc.c (gc_assert_untraced_object): New wrapper function.
* src/lisp.h (make_mint_ptr): Use it.
2025-11-08 07:15:28 +00:00
Helmut Eller
f8a34d449c Add some more root labels
* src/xterm.c (x_cache_xi_devices, xi_disable_devices): Use
igc_xzalloc_ambig_with_label.
2025-11-07 09:21:29 +01:00
Helmut Eller
0a0ba349c0 Add labels to some roots
* src/atimer.c (start_atimer):
* src/fns.c (strong_copy_hash_table):
* src/pgtkfns.c (Fx_create_frame):
* src/pgtkterm.c (pgtk_enumerate_devices, pgtk_term_init): Use
igc_xzalloc_ambig_with_label instead of igc_xzalloc_ambig.
2025-11-07 08:56:43 +01:00
Helmut Eller
cde26088bf Fix assertion failures in valid_lisp_object_p
The cold_user_data area is no longer pinned; this caused the assertion
failures.

* src/pdumper.c (pdumper_load): Make dump_public emtpy.
2025-11-06 09:24:28 +01:00
Pip Cet
f9d90179c9 Don't call record_unwind_protect_ptr with a Lisp pointer
* src/fns.c (restore_mutability):
(hash_table_user_defined_call): Use 'record_unwind_protect', not
'record_unwind_protect_ptr', and adjust accordingly.
2025-11-03 19:44:27 +00:00
Pip Cet
80a39e7394 Don't call record_unwind_protect_ptr with a Lisp pointer
This should ensure the value is properly marked by GC.

* src/regex-emacs.c (unwind_re_match):
(re_match_2_internal): Use a Lisp_Object for the callback argument.
2025-11-03 19:44:27 +00:00
Pip Cet
2cca44d8f5 Produce a warning when MPS pointers are passed as callback cookies
* src/igc.c (igc_assert_not_an_mps_object): New function.
* src/eval.c (record_unwind_protect_ptr):
(record_unwind_protect_ptr_mark):
(record_unwind_protect_module): Use it.
2025-11-03 19:44:27 +00:00
Helmut Eller
d21464f269 Don't trace the pointer in Lisp_User_Ptr objects
* src/igc.c (fix_user_ptr): Ignore the p field.
* test/src/test/src/emacs-module-tests.el (mod-test-unaligned-userptr):
New test.
* test/src/emacs-module-resources/mod-test.c
(Fmod_test_address_to_userptr, Fmod_test_userptr_to_address): New
helpers.
2025-11-03 20:26:21 +01:00
Helmut Eller
6680461f02 Don't trace the pointer in Lisp_Misc_Ptr objects
We used to trace the pointer in Lisp_Misc_Ptr objects just in case it
points to an object on the GC heap without knowing much of the intended
use.  However, make_misc_ptr is primarily used by make_mint_ptr for
unaligned pointers.  MPS ignores unaligned references and, if enabled,
unaligned references cause an igc_assertion to fail.  So tracing the
pointer is either useless or counterproductive.

* src/igc.c (fix_misc_ptr): Ignore the pointer field.
2025-11-03 20:14:46 +01:00
Helmut Eller
e4ef42fb9c Fix GTK scrollbars
* src/xterm.c (xg_scroll_callback, xg_end_scroll_callback): Adapt to
gc_handles.
2025-11-02 17:13:10 +01:00
Helmut Eller
e4f2d89487 Fix PGTK scrollbars
* src/gtkutil.c (free_gc_handle_callback): New.
(xg_finish_scroll_bar_creation): Use it instead of free_glib_gc_handle.
* src/pgtkterm.c (xg_scroll_callback, xg_end_scroll_callback): Adapt to
gc_handles.
2025-11-02 17:00:30 +01:00
Helmut Eller
45d0c389ec Remove the charset_table_init array
Determining the best size for a static array seems difficult; so
allocate it dynamically.

* src/charset.c (CHARSET_TABLE_INIT_SIZE): New constant.
(syms_of_charset): Malloc charset_table here.
(charset_table_init): Removed.
(shrink_charset_table): New function.
(Fclear_charset_maps): Call it.
* src/charset.h (charset_table_init): Removed.
(charset_attributes_getter): Add an assertion.
* src/pdumper (dump_charset_table, dump_do_dump_relocation): Assert that
charset_table_size == charset_table_used.
2025-11-02 15:19:50 +01:00
Helmut Eller
0588ad9cbe Copy the charset_table to malloced memory
The charset_table_init array can't be used because it may be too small.

* src/pdumper.c (RELOC_CHARSET_TABLE): New reloc type.
(dump_charset_table): Emit RELOC_CHARSET_TABLE.
(dump_do_dump_relocation): Implement the RELOC_CHARSET_TABLE case.
2025-11-01 18:44:00 +01:00
Gerd Möllmann
9b9c187a6a * src/igc.c (fix_hash_table): Don't fix empty_hash_index_vector 2025-11-01 13:53:24 +00:00
Pip Cet
1a2da25031 Avoid (rarely) turning INVALID_LISP_OBJECT into Qnil when fixing
* src/igc.c (fix_lisp_obj): If 'addr' is NULL but 'tag' isn't, leave
the word alone; it's an INVALID_LISP_OBJECT.
2025-11-01 07:14:31 +00:00
Pip Cet
95fd3ca980 * src/igc.c: Adjust pdumper hashes. 2025-10-31 14:12:05 +00:00
Pip Cet
dfe07bfded Fix thinko in alloc_multi
* src/igc.c (igc_hash): Round up sizes destructively.
2025-10-31 14:10:08 +00:00
Pip Cet
267b2a1cd9 Use a strong Lisp hash table as a weak hash table's strong part
* src/fns.c (weak_hash_from_key, set_weak_hash_next_slot):
(set_weak_hash_hash_slot, set_weak_hash_index_slot):
(WEAK_HASH_NEXT, WEAK_HASH_INDEX, allocate_weak_hash_table):
(strong_copy_hash_table): Adjust member access.
(strengthen_hash_table_for_dump): Also, fix comment.
(make_weak_hash_table, weak_hash_index_index):
(maybe_resize_weak_hash_table, weak_hash_lookup):
(weak_hash_put, weak_hash_remove_from_table):
(weak_hash_clear, Fhash_table_size, Fhash_table_test):
(Fhash_table_weakness, Fputhash, Fremhash):
* src/igc.c (fix_hash_table, fix_weak_hash_table):
(fix_weak_hash_table_strong_part):
(fix_weak_hash_table_weak_part): Adjust member access.
* src/lisp.h (struct Lisp_Weak_Hash_Table_Strong_Part): Redefine to
include a 'struct Lisp_Hash_Table'.
(WEAK_HASH_KEY, make_lisp_weak_hash_table, WEAK_HASH_VALUE):
(WEAK_HASH_HASH, WEAK_HASH_TABLE_SIZE, DOHASH_WEAK):
(set_hash_value_slot, set_weak_hash_key_slot):
(set_weak_hash_value_slot):
* src/print.c (print_object): Adjust member access.
2025-10-30 22:54:13 +00:00
Pip Cet
d535d85975 Make weak hash tables look like strong hash tables again
A weak hash table is now once again a pointer to a structure that
looks like a strong hash table.

* src/fns.c (weak_hash_from_key, set_weak_hash_next_slot):
(set_weak_hash_hash_slot, set_weak_hash_index_slot):
(WEAK_HASH_NEXT, WEAK_HASH_INDEX): Use Lisp_Objects or integers, not
the old 'struct Lisp_Weak_Hash_Table_Entry' type.
(allocate_weak_hash_table): Rewrite to use ...
(allocate_weak_hash_table_parts): ... this new function.
(make_weak_hash_table, weak_hash_index_index): Adjust entry types.
(maybe_resize_weak_hash_table): Reuse
'allocate_weak_hash_table_parts'.
(weak_hash_lookup_with_hash, weak_hash_put):
(weak_hash_remove_from_table, weak_hash_clear):
(Fhash_table_size, Fputhash): Adjust entry types.
* src/igc.c (fix_weak, IGC_FIX12_WEAK): Function and macro removed.
(fix_weak_hash_table_strong_part):
(fix_weak_hash_table_weak_part): Rewritten to use interior pointers
rather than making assumptions about the memory layout.
(weak_hash_table_entry, make_weak_hash_table_entry): Functions
removed.
(igc_alloc_weak_hash_table_strong_part):
(igc_alloc_weak_hash_table_weak_part): Rewritten to use 'alloc_multi'.
* src/igc.h:
* src/lisp.h (struct Lisp_Weak_Hash_Table_Entry): Type removed.
(struct Lisp_Weak_Hash_Table_Strong_Part)
(struct Lisp_Weak_Hash_Table_Weak_Part): Remove flexible 'entries' array.
(WEAK_HASH_KEY, WEAK_HASH_VALUE, WEAK_HASH_HASH)
(WEAK_HASH_TABLE_SIZE, weak_hash_table_index_size):
(DOHASH_WEAK, set_weak_hash_key_slot):
(set_weak_hash_value_slot): Adjust types of hash table entries.
2025-10-30 22:54:13 +00:00
Pip Cet
5a784bfd5d Use AWL0 pool for weak hash tables
* src/igc.c (make_pool_awl): Function removed.
(make_igc): Use 'make_pool_awl0' instead.
2025-10-30 22:54:13 +00:00
Pip Cet
813fd88c02 Introduce a function to allocate several Emacs objects in one go
Hash table weak and strong parts cannot be described as C structures,
since they consist of a sequence of variably-sized objects.

* src/igc.c (alloc_multi): New function.
2025-10-30 22:54:13 +00:00
Helmut Eller
7cc4f7a657 Abort if charset_table_init is too small
* src/pdumper.c (dump_charset_table): As requested by Pip.
2025-10-30 21:28:56 +01:00
Helmut Eller
494311785f charset_table_init no longer needs protection
* src/igc.c (root_create_charset_table): Deleted.
2025-10-30 18:45:50 +01:00
Helmut Eller
b6575fa647 Removed dump-pins
These objects are no longer used.

* src/igc.c (pinned_objects_in_dump): Deleted
(igc_on_pdump_loaded): Skip creating pins.
(fix_charset_table): This should no longer be needed.
2025-10-30 18:42:04 +01:00
Helmut Eller
2b251af993 Copy the charset_table out from the dump
This is a preparation step to remove the pinned charset objects from the
GC heap.

* src/pdumper.c (dump_charset_table): Copy the charset_table back to
charset_table_init.
(dump_fixup_type.DUMP_FIXUP_CHARSET_CODE_SPACE_MASK): New fixup type.
(dump_reloc_type.RELOC_CHARSET_CODE_SPACE_MASK): New reloc type.
(dump_cold_charset): Emit fixup to relocate the code space mask.
(dump_do_fixup): Implemented DUMP_FIXUP_CHARSET_CODE_SPACE_MASK.
(dump_do_dump_relocation): Implemented RELOC_CHARSET_CODE_SPACE_MASK.
* src/charset.c (charset_table): Initialize charset_table here, not ...
(syms_of_charset): ... here.
* src/igc.c (igc_on_pdump_loaded): Remove assertion.  charset_table no
longer points to the beginning of the dump.
2025-10-30 18:28:56 +01:00
Helmut Eller
699db8d2b3 Allow unaligned addresses in the weak pool
When compiled with igc_debug, fix_weak_hash_table_strong_part can
trigger assertion failures because it calls fix_raw with unaligned
addresses.  I assume that the AWL pool will filter out unaligned
addresses and the assertion is not needed.

* src/igc.c (fix_weak, IGC_FIX12_WEAK): New.
(fix_weak_hash_table_strong_part, fix_weak_hash_table_weak_part): Use
it.
* test/src/fns-tests.el (ft-weak-fixnums): New test.
(ft--test-weak-fixnums): New helper.
2025-10-30 17:20:10 +01:00
Gerd Möllmann
fa17b233a6 * src/igc.c (igc_alloc_handler): Alloc handlers from MPS on macOS/arm64. 2025-10-30 11:10:04 +01:00
Eli Zaretskii
6ed0916e85 Make w32 threads' stack-bottom alignment be like in thread.c
* src/igc.h (w32_aligned_stack_pos): New union.
* src/w32proc.c (timer_loop):
* src/w32fns.c (w32_msg_worker): Use it to ensure proper alignment
of stack bottom.  Evidently, MPS requires it to be aligned as the
'Word' type used by MPS, see
https://lists.gnu.org/archive/html/emacs-devel/2025-10/msg00767.html
for the details.
2025-10-30 10:16:03 +02:00
Helmut Eller
e33ceabe6d * src/gc-handles.c: Explain advantages of GC handles 2025-10-29 15:10:54 +01:00
Helmut Eller
2f17f9a372 Move the attribute field of charsets to a separate vector
This simplifies the GC code, as this was the only field in the charset
struct that referenced the GC heap.  Without it, we no longer need to
trace the charset_table.

* src/charset.h (struct charset.attributes): Removed.
(charset_attributes_getter): New helper.
(CHARSET_ATTRIBUTES): Use it.
* src/charset.c (charset_attributes_table): New.
(Fdefine_charset_internal): Place attrs in charset_attributes_table.
(syms_of_charset): Initialize charset_attributes_table.
(mark_charset): Deleted.
* src/pdumper.c (dump_charset): Skip attributes field.
* src/lisp.h (mark_charset): Deleted.
* src/igc.c (fix_charset_table): Nothing to do anymore.
* src/alloc.c (garbage_collect): mark_charset no longer needed.
2025-10-28 09:21:23 +01:00
Helmut Eller
988b4b6c5d * src/gc-handles.c (Fgc_handles_info): Include per-object refcounts 2025-10-27 14:39:25 +01:00
Helmut Eller
7e189d1504 Try to avoid alignment problems with 64 bit builds
* src/w32proc.c (timer_loop): Make stk_bot a pointer; that is more
likely word aligned than a DWORD.
* src/w32fns.c (w32_msg_worker): Idem.
2025-10-26 21:34:18 +01:00
Pip Cet
9395f76710 Remove 'glib_user_data'
* src/gtkutil.c (free_glib_user_data):
* src/gtkutil.h (glib_user_data, get_glib_user_data): Functions
removed.
2025-10-26 14:44:42 +00:00
Pip Cet
e1713417ab Remove glib_user_data in PGTK code
* src/pgtkmenu.c (menu_highlight_callback, menubar_selection_callback)
(popup_selection_callback):
* src/pgtkterm.c (size_allocate, pgtk_set_event_handler): Use
'gc_handle' or raw pointer, not 'glib_user_data'.
2025-10-26 14:42:27 +00:00
Pip Cet
9d0b537589 New function to count number of allocated gc handles
* src/gc-handles.c (Fgc_handles__refs): New function.
(syms_of_gc_handles): Define it.
2025-10-26 14:27:55 +00:00
Pip Cet
109306480e Don't leak objects through gc_handles
* src/gtkutil.c (xg_free_frame_widgets):
(unref_cl_data):
(xg_mark_data):
(xg_update_menu_item):
(find_icon_from_name):
(update_frame_tool_bar): Use 'free_gc_handle'.
(menuitem_highlight_callback): Use 'gc_handle_value'.
2025-10-26 13:57:29 +00:00
Pip Cet
cf53356c8b Use GC handles to store GTK callback data
* src/gtkutil.c (struct xg_frame_tb_info): Use 'gc_handle', not
'Lisp_Object'.
(free_glib_gc_handle): New function.
(hierarchy_ch_cb, qttip_cb): Use 'gc_handle', not 'glib_user_data'.
(style_changed_cb): Use pointer directly, not through
'glib_user_data'.
(xg_create_frame_widgets,xg_create_frame_outer_widgets): Use
'gc_handle' or pointer.
(xg_free_frame_widgets) [MPS]: Use 'xfree'
(create_dialog, xg_dialog_response_cb, xg_dialog_run):
(xg_toggle_notify_cb, xg_get_file_with_chooser): Use pointers
directly.
(make_cl_data, update_cl_data, unref_cl_data): Use 'gc_handle' values.
(xg_mark_data): Simplify, since 'gc_handle' values are marked elsewhere.
(menuitem_destroy_callback, menu_destroy_callback): Use pointers
directly.
(xg_create_one_menuitem): Use 'gc_handle' values for callback data.
(menu_bar_button_pressed_cb, create_menus):
(xg_update_menu_item): Use 'gc_handle' values.
(menubar_map_cb): Use pointer to stack variable.
(xg_update_frame_menubar, find_scrollbar_cb): Use 'gc_handle' value.
(xg_get_widget_from_map): Use pointer to stack variable.
(xg_gtk_scroll_free_scroll_bar_cell): Funtion removed.
(xg_finish_scroll_bar_creation): Use 'gc_handle' value. The object we
create a handle for is unprintable and must not be leaked to Lisp.
(draw_page):
(xg_print_frames_dialog): Use 'gc_handle' values.
(xg_tool_bar_callback, xg_tool_bar_help_callback): Use integers cast
to pointers.
(tb_size_cb): Use 'gc_handle' value.
(xg_create_tool_bar) [MPS]: Use 'xmalloc'.
(xg_make_tool_item): Use integers cast to pointers.
(update_frame_tool_bar): Use 'gc_handle' values.
(free_frame_tool_bar) [MPS]: Use 'xfree'.
(xg_im_context_commit, xg_widget_style_updated):
* src/gtkutil.h (xg_menu_cb_data, xg_menu_item_cb_data):
* src/xmenu.c (menu_highlight_callback, menubar_selection_callback):
Use 'gc_handle' values, not Lisp_Object values.
2025-10-26 13:57:29 +00:00
Eli Zaretskii
31dd90d222 Register with MPS non-Lisp w32 threads that need to access Lisp data
* src/igc.c (w32_add_non_lisp_thread)
(w32_remove_non_lisp_thread) [HAVE_NTGUI]: New functions to
register w32 threads with MPS.
* src/igc.h: Define their prototypes.
* src/w32proc.c (timer_loop):
* src/w32fns.c (w32_msg_worker) [HAVE_MPS]: Call
'w32_add_non_lisp_thread' when the thread starts and
'w32_remove_non_lisp_thread' when it is about to exit.
2025-10-26 12:28:16 +02:00
Helmut Eller
6595ee3a0a Fix Motif scrollbars using GC handles as for Athena
* src/xterm.c (xt_free_gc_handle): Renamed from xaw_free_gc_handle.
(x_create_toolkit_scroll_bar)
(x_create_horizontal_toolkit_scroll_bar) [MOTIF]: Create a GC handle.
(xm_scroll_callback): Adapt to GC handle.
2025-10-25 20:51:02 +02:00
Eli Zaretskii
a45ca7eeba * src/fns.c (strengthen_hash_table_for_dump): Fix a thinko (bug#79695). 2025-10-25 20:54:52 +03:00
Helmut Eller
33d9346348 Fix horizontal Athena scrollbars
Must use GC handles there too.

* src/xterm.c (xaw_jump_callback, xaw_scroll_callback)
(x_create_toolkit_scroll_bar): Some reformatting.
(xaw_free_gc_handle): Renamed from xaw_destroy_scrollbar_callback.
(x_create_horizontal_toolkit_scroll_bar): Create a GC handle.
2025-10-25 18:39:39 +02:00
Helmut Eller
b33d0c5982 * src/gc-handles.{h,c}: Add license headers 2025-10-25 17:27:58 +02:00
Pip Cet
eac2799565 Introduce a GC handle type
* src/gc-handles.h: New file.
* src/gc-handles.c: New file.
* src/Makefile.in (base_obj): Add gc-handles.o.
* src/emacs.c (main): Call syms_of_gc_handles.
* src/xterm.c (xaw_jump_callback, xaw_scroll_callback)
x_create_toolkit_scroll_bar): Use GC handles.
(xaw_destroy_scrollbar_callback): New helper.

Co-authored-by: Helmut Eller <eller.helmut@gmail.com>
2025-10-25 17:10:38 +02:00
Gerd Möllmann
8e3cfab962 Fix duplicate root creation
* src/comp.c (load_comp_unit): Create the root for the
compilation unit once only.
2025-10-23 08:55:46 +02:00
Gerd Möllmann
2a2c46346d Check for overlapping roots if checking is enabled
* src/igc.c (check_root): New function.
(register_root): Call it.
2025-10-23 08:55:33 +02:00