summaryrefslogtreecommitdiff
path: root/src/alloc.c
AgeCommit message (Collapse)Author
2026-05-26ARRAYELTS → countofPaul Eggert
C2y will standardize countof as the macro that Emacs uses the name ARRAYELTS for. Switch to the standard name, which is supported by GCC 16+, by Clang 21, and by the Gnulib stdcountof-h module already in use for compilers that do not support countof. Also, use countof in a few places where we missed using ARRAYELTS. * admin/coccinelle/arrayelts.cocci: Suggest countof, not ARRAYELTS. * admin/merge-gnulib (GNULIB_MODULES): Add stdcountof-h, as it is now a direct rather than an indirect dependency. * exec/trace.c, src/lisp.h, src/sfnt.c: Include <stdcountof.h>. (ARRAYELTS): Remove. All uses replaced by countof. * lib-src/ebrowse.c, lib-src/etags.c, lib-src/make-docfile.c: * lib-src/seccomp-filter.c, lwlib/lwlib-Xaw.c: Prefer <stdcountof.h> and countof to doing things by hand.
2026-05-26Omit useless casts found by GCC 16Paul Eggert
GCC 16’s -Wuseless-cast warning can be useful. Fix the useless casts it identifies, and also fix false positives by using compound literals, which are safer anyway than casts. * src/composite.c (composition_adjust_point) (Ffind_composition_internal): * lwlib/xlwmenu.c (xlwMenuResources, xlwMenuClassRec) (resource_widget_value, XlwMenuDestroy, Select): * src/alloc.c (process_mark_stack): * src/data.c (Faref): * src/emacs-module.c (module_extract_big_integer): * src/fileio.c (Finsert_file_contents): * src/frame.h (FRAME_MESSAGE_BUF_SIZE): * src/gtkutil.c (xg_tool_item_stale_p, update_frame_tool_bar): * src/image.c (pbm_load, png_load_body, jpeg_load_body) (tiff_load, gif_load): * src/pdumper.c (ptrdiff_t_to_dump_off, dump_queue_dequeue) (field_relpos, dump_field_emacs_ptr) (dump_object_start_pseudovector, pdumper_remember_scalar_impl) (pdumper_load, syms_of_pdumper): * src/regex-emacs.c (BUF_PUSH, BUF_PUSH_2, POINTER_TO_OFFSET): * src/xdisp.c (remember_mouse_glyph, pint2str): * src/xterm.c (cvt_string_to_pixel, handle_one_xevent): Omit useless casts. Perhaps they were formerly needed, but they should not be needed now. * src/alloc.c (Fmemory_info): * src/category.c (Fdefine_category, Fmodify_category_entry): * src/data.c (Fash): * src/dispextern.h (GLYPH_CODE_P): * src/emacs.c (load_seccomp): * src/fns.c (Flocale_info, maybe_resize_hash_table): * src/indent.c (check_display_width): * src/json.c (symset_size): * src/lisp.h (XUNTAG, BOOL_VECTOR_LENGTH_MAX, obarray_size) (hash_table_index_size): * src/lread.c (make_obarray, grow_obarray, Fobarray_clear): * src/menu.c (digest_single_submenu, x_popup_menu_1): * src/term.c (init_tty): * src/widget.c (update_wm_hints): * src/xdisp.c (truncate_echo_area): * src/xfns.c (x_set_border_pixel): * src/xfont.c (xfont_match, xfont_open): * src/xmenu.c (set_frame_menubar): * test/src/emacs-module-resources/mod-test.c (emacs_module_init): Use compound literal instead of a cast that is useless in some platforms but not others. * src/dispextern.h, src/haikugui.h, src/w32gui.h: (WINDOW_HANDLE_UINTPTR): New macro. * src/frame.c (gui_report_frame_params): * src/xterm.c (x_try_cr_xlib_drawable): Use it. * src/lisp.h (XUNTAG): And tag with UINTPTR_MAX to pacify gcc warning about a constant out of range. (hash_idx_t): Make it int_least32_t, as it need not be exactly 32 bits. (PRIdHASH_IDX): New macro. * src/pdumper.c (dump_queue_dequeue): Use it. * src/profiler.c (setup_cpu_timer): Make a local EMACS_INT rather than int, to avoid need for casting later. * src/syntax.c (uninitialized_interval): Use 1u rather than 1 so the cast is always useful. A compound literal wouldn’t do here, as this macro needs to be an integer constant expression. * src/xfns.c (XICCallback, XICProc): Remove macros. (Xxic_preedit_start_callback): Use a cleaner way to specify it, avoiding the need for type macros, and for a cast if HAVE_XICCALLBACK_CALLBACK. * src/xterm.c (handle_one_xevent): 2nd arg is now XEvent * on all platforms, as there is no need to diverge, and diverging meant we needed lots of unnecessary casts.
2026-05-23Prefer ptrdiff_t to size_t when either will doPaul Eggert
Signed types are a bit safer, as they avoid some comparison confusion and -fsanitize=undefined can check more misuses of them. * src/alloc.c (lisp_malloc, lisp_align_malloc) (allocate_string_data, allocate_vector_from_block, object_bytes): * src/coding.c (from_unicode_buffer): * src/decompress.c (acc_size, accumulate_and_process_md5): * src/emacs.c (load_seccomp, shut_down_emacs): * src/fns.c (sxhash_bignum): * src/ftfont.c (get_adstyle_property): * src/image.c (lookup_image, xpm_init_color_cache) (xpm_cache_color): * src/json.c (json_out_str, struct json_parser) (json_make_object_workspace_for_slow_path) (json_make_object_workspace_for, json_parse_array) (json_parse_object): * src/sysdep.c (get_current_dir_name_or_unreachable) (init_sys_modes, convert_speed): * src/termchar.h (struct tty_display_info): * src/textconv.h (struct textconv_conversion_text): * src/xfns.c (struct x_xim_text_conversion_data) (x_encode_xim_text): * src/xselect.c (struct transfer, c_size_for_format) (x_size_for_format, selection_data_for_offset) (selection_data_size, x_start_selection_transfer) (x_continue_selection_transfer): Prefer ptrdiff_t to size_t when either will do. * src/term.c (Ftty__set_output_buffer_size): Limit output buffer size to PTRDIFF_MAX as well as to SIZE_MAX.
2026-05-23Document PTRDIFF_MAX <= SIZE_MAX assumptionPaul Eggert
* src/alloc.c: New static_assert.
2026-05-23Update src/alloc.c commentsPaul Eggert
2026-05-23Be more careful about size multiplicationPaul Eggert
* src/alloc.c (xcalloc): New function. * src/dispnew.c (save_current_matrix): * src/fns.c (Finternal__hash_table_histogram): * src/nsfns.m (Fns_display_monitor_attributes_list): * src/pgtkfns.c (Fpgtk_display_monitor_attributes_list): * src/pgtkselect.c (pgtk_own_selection): * src/profiler.c (make_log): * src/sfnt.c (sfnt_poly_edges_exact): * src/xfns.c (x_get_monitor_attributes_xinerama) (x_get_monitor_attributes_xrandr, Fx_display_monitor_attributes_list): Use it instead of multiplying by hand, conceivably with overflow. * src/profiler.c (make_log): Check for overflow in internal size calculations. Use xnmalloc instead of multiply + xmalloc. * src/sfnt.c (xzalloc) [TEST]: Remove, replacing with ... (xicalloc) [TEST]: ... this new function. All callers changed. (eassert) [TEST]: New macro. * src/treesit.c (treesit_calloc_wrapper): Remove, replacing its use with xcalloc.
2026-05-23Shrink STRING_BYTES_MAX slightlyPaul Eggert
* src/alloc.c (STRING_BYTES_MAX): Also don’t allow sizes to exceed PTRDIFF_MAX in internal calculations when calling malloc, as those are problematic even if the final number of bytes does not exceed PTRDIFF_MAX.
2026-05-23New function memory_full_upPaul Eggert
* src/alloc.c (memory_full_up): New function. Replace all callers of memory_full (SIZE_MAX) with callers to this function. This simplifies callers and should make future changes easier. It also saves a whopping 296 bytes in executable size with gcc 16.1.1 20260515 (Red Hat 16.1.1-2) x86-64.
2026-03-21Move the attribute field of charsets to a separate vectorHelmut Eller
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/alloc.c (garbage_collect): mark_charset no longer needed.
2026-01-21; * src/alloc.c (Fgarbage_collect_heapsize): Avoid compiler warning.Eli Zaretskii
2026-01-20(garbage-collect-heapsize): New functionStefan Monnier
The info returned from `garbage-collect` is really handy to track the evolution of the heap size, but sadly it's available only at the cost of running a full GC, which has two big downsides: it's slow, it affects what we're measuring, and it can't be used in `post-gc-hook`. So, this patch makes it available without running the GC. * src/alloc.c (Fgarbage_collect_heapsize): New function, extracted from `Fgarbage_collect`. (Fgarbage_collect): Use it. (syms_of_alloc): defsubr it. * doc/lispref/internals.texi (Garbage Collection): Extract documentation for it from that of `garbage-collect`.
2026-01-01; Add 2026 to copyright years.Sean Whitton
2025-12-07Include malloc.h early in alloc.cPaul Eggert
* src/alloc.c, src/gmalloc.c: Include <malloc.h> before <stdlib.h>. This mimics include patterns elsewhere, and avoids a problem if malloc.h declares realloc (i.e., rpl_realloc) early as extern, whereas Gnulib stdlib.h declares it later as inline which means it is extern inline, which clashes with gmalloc’s definition of rpl_realloc when gmalloc.o is used. Problem discovered when building Emacs on Ubuntu 25.10 with "./configure CC='gcc -m32' emacs_cv_struct_alignment=no gl_cv_header_working_stdalign_h=no".
2025-09-17Turn some checking macros into functions in the GC marker codeMattias Engdegård
This rids us of a bunch of unhygienic macros with free variables and makes the marking code actually readable again. Even better, it is all processed by the compiler even when the checks are disabled. * src/alloc.c (CHECK_ALLOCATED, CHECK_LIVE, CHECK_ALLOCATED_AND_LIVE) (CHECK_ALLOCATED_AND_LIVE_SYMBOL): Transform macros into... (check_live, check_allocated_and_live, check_allocated_and_live_symbol) (check_allocated_and_live_vectorlike): ...functions. Callers adapted.
2025-08-24Disallow string data resizing (bug#79784)Mattias Engdegård
Only allow string mutation that is certain not to require string data to be resized and reallocated: writing bytes into a unibyte string, and changing ASCII to ASCII in a multibyte string. This ensures that mutation will never transform a unibyte string to multibyte, that the size of a string in bytes never changes, and that the byte offsets of characters remain the same. Most importantly, it removes a long-standing obstacle to reform of string representation and allow for future performance improvements. * src/data.c (Faset): Disallow resizing string mutation. * src/fns.c (clear_string_char_byte_cache): * src/alloc.c (resize_string_data): Remove. * test/src/data-tests.el (data-aset-string): New test. * test/lisp/subr-tests.el (subr--subst-char-in-string): Skip error cases. * test/src/alloc-tests.el (aset-nbytes-change): Remove test that is no longer relevant. * doc/lispref/strings.texi (Modifying Strings): * doc/lispref/sequences.texi (Array Functions): * doc/lispref/text.texi (Substitution): Update manual. * etc/NEWS: Announce.
2025-04-15Avoid performance regressions in unoptimized buildsPo Lu
* src/alloc.c (lisp_malloc): Declare val register.
2025-04-14Remove unused XMALLOC_BLOCK_INPUT_CHECK debug facilityStefan Kangas
The compile-time option XMALLOC_BLOCK_INPUT_CHECK was added in 2012 (commit 4d7e6e51dd4acecff) to allow blocking input during malloc-family calls, in case any issues arose from related changes in Emacs 24.3. However, it has not been referenced on emacs-devel or the bug tracker in over a decade. It is clear that we do not need it, as our signal handlers do not allocate memory. Removing it simplifies the allocation function wrappers and eliminates dead debug code. Ref: https://debbugs.gnu.org/12450 * src/alloc.c [XMALLOC_BLOCK_INPUT_CHECK] (malloc_block_input, malloc_unblock_input): Delete functions. (MALLOC_BLOCK_INPUT, MALLOC_UNBLOCK_INPUT): Delete macros. Update all callers.
2025-03-09Re-port to 32-bit systems without alignment primitivesPo Lu
* configure.ac (ALIGNOF_INT, ALIGNOF_LONG, ALIGNOF_LONG_LONG): New variables. (emacs_cv_alignas_unavailable): Define if alignas and structure alignment primitives are unavailable. In such an environment, the MSB tagging scheme must be enabled, as must the GNU malloc. * msdos/sed2v2.inp: Adjust correspondingly. * src/alloc.c (union emacs_align_type): Remove types which contain flexible array members. The address of a field subsequent to an aggregate with flexible array members cannot validly be taken. (mark_memory) [!USE_LSB_TAG && !WIDE_EMACS_INT]: Strip type bits before scanning memory. * src/emacs.c (main): * src/eval.c (Fautoload_do_load): * src/fns.c (Frequire): Rename a number of illogically named fields. * src/lisp.h (ALIGNOF_EMACS_INT): Define to the natural alignment of EMACS_INT. (IDEAL_GCALIGNMENT): New macro. (USE_LSB_TAG): Disable if no alignment specifiers are available, WIDE_EMACS_INT is undefined, and the natural alignment of EMACS_INT falls short of LSB tagging's requirements. (gflags): Rename illogically named fields and don't define them as bitfields, which runs afoul of certain compiler issues. (will_dump_p, will_bootstrap_p, will_dump_with_pdumper_p) (dumped_with_pdumper_p): Adjust accordingly. * src/pdumper.c (VM_SUPPORTED): Define to 0 when !USE_LSB_TAG. It is better to read dump files into the heap by hand than to be supplied with an address that is not representable. (_dump_object_start_pseudovector): Rename to dump_object_start_pseudovector, to avoid encroaching on reserved names. (START_DUMP_PVEC): Adjust correspondingly. (dump_mmap_contiguous_vm): Preserve errno around failure cleanup. (dump_bitset_bit_set_p): Work around certain compiler issues. (pdumper_load) [!USE_LSB_TAG]: Reject dump file allocations that are not representable as Lisp_Objects. Tested on i386-unknown-solaris2.10, sparc-sun-solaris2.10.
2025-02-01Improve malloc Lisp alignment commentaryPaul Eggert
Prompted by a private email from Pip Cet.
2025-02-01Fix compilation warnings on AndroidPo Lu
* src/alloc.c (pointer_align): Only define if !USE_ALIGNED_ALLOC.
2025-02-01Merge branch 'scratch/no-purespace' into 'master'Stefan Kangas
2025-01-27Avoid some make_formatted_string mallocsPaul Eggert
* src/alloc.c (make_formatted_string): Grow the local buffer from 64 to MAX_ALLOCA bytes.
2025-01-26Simplify make_formatted_string APIPaul Eggert
From a suggestion by Pip Cet. * src/alloc.c (make_formatted_string): Omit first argument, to simplify the calling convention. All callers changed. * src/doprnt.c (doprnt): Also support %u. Update doc.
2025-01-20Remove redundant case_Lisp_Int macroStefan Kangas
The case_Lisp_Int macro was originally introduced with different definitions depending on USE_2_TAGS_FOR_INTS. However, since commit 2b5701247845, we have assumed that USE_2_TAGS_FOR_INTS is always defined, and the macro has only a single definition. As a result, the macro is now unnecessary, and replacing it with standard C case labels improves readability and understanding. * src/lisp.h (case_Lisp_Int): Delete macro. * src/alloc.c (process_mark_stack, survives_gc_p): * src/data.c (Fcl_type_of): * src/fns.c (value_cmp, sxhash_obj): * src/pdumper.c (dump_object): * src/print.c (print_object): * src/xfaces.c (face_attr_equal_p): Remove uses of above macro.
2025-01-19Replace call[1-8] with callnStefan Kangas
Since the introduction of the 'calln' macro, the 'call1', 'call2', ..., 'call8' macros are just aliases for the former. This is slightly misleading and potentially unhelpful. The number of arguments N can also easily go out-of-synch with the used alias callN. There is no reason not to replace these aliases with using 'calln' directly. To reduce the risk for mistakes, the tool Coccinelle was used to make these changes. See <https://coccinelle.gitlabpages.inria.fr/website/>. * src/alloc.c, src/androidvfs.c, src/androidfns.c, src/buffer.c: * src/callint.c, src/callproc.c, src/casefiddle.c, src/charset.c: * src/chartab.c, src/cmds.c, src/coding.c, src/composite.c: * src/data.c, src/dbusbind.c, src/dired.c, src/doc.c: * src/emacs.c, src/eval.c, src/fileio.c, src/filelock.c: * src/fns.c, src/frame.c, src/gtkutil.c, src/haikufns.c: * src/haikumenu.c, src/image.c, src/insdel.c, src/intervals.c: * src/keyboard.c, src/keymap.c, src/lisp.h, src/lread.c: * src/minibuf.c, src/nsfns.m, src/nsselect.m, src/pgtkfns.c: * src/pgtkselect.c, src/print.c, src/process.c, src/sort.c: * src/syntax.c, src/textconv.c, src/textprop.c, src/undo.c: * src/w32fns.c, src/window.c, src/xfaces.c, src/xfns.c: * src/xmenu.c, src/xselect.c, src/xterm.c: Replace all uses of 'call1', 'call2', ..., 'call8' with 'calln'.
2025-01-17Simplify alloc by assuming MALLOC_IS_LISP_ALIGNEDPaul Eggert
Problem reported by Hong Xu <https://bugs.gnu.org/75551#14>. * src/alloc.c (MALLOC_IS_LISP_ALIGNED): static_assert it, since it is true on all current Emacs platforms. All uses simplified to assume it is true. (xmalloc, xzalloc, xrealloc, lisp_malloc): Just use malloc/calloc/realloc. Since we are using the malloc-gnu and realloc-posix modules, we need not worry about whether these functions return a null pointer for zero-size requests. (xrealloc): Stop worrying about no-longer-existing platforms where realloc (nullptr, ...) did not work. (laligned, lmalloc, lrealloc): Remove. All uses removed.
2025-01-01Update copyright year to 2025Paul Eggert
Run "TZ=UTC0 admin/update-copyright".
2024-12-15Improve purify-flag docstringStefan Kangas
* src/alloc.c (syms_of_alloc): Improve purify-flag docstring.
2024-12-12Make 'purecopy' an obsolete function alias for 'identity'Stefan Kangas
* lisp/subr.el (purecopy): New obsolete function alias for 'identity'. * src/alloc.c (purecopy): Remove function. (Fpurecopy): Remove DEFUN. (syms_of_alloc): Remove defsubr for above DEFUN. * lisp/loadup.el (purify-flag): Don't set to hash table. * doc/lispref/spellfile: * doc/lispref/keymaps.texi (Tool Bar): * lisp/emacs-lisp/byte-opt.el (side-effect-free-fns): Delete references to 'purecopy'
2024-12-12Delete obsolete comment about using purespaceStefan Kangas
* src/alloc.c (Fmake_byte_code): Delete obsolete comment.
2024-12-12Remove unused function my_heap_startStefan Kangas
* src/alloc.c (my_heap_start) [DOUG_LEA_MALLOC && GNU_LINUX]: Remove unused function. Update callers.
2024-12-12Remove check for working malloc_set_stateStefan Kangas
This check was added to 'malloc_initialize_hook' in order to "insulate Emacs better from configuration screwups" (commit b4788b9394f3). With unexec gone, we no longer use 'malloc_set_state', and thus don't need this check. Note that this patch removes the last uses of the deprecated glibc functions 'malloc_set_state' and 'malloc_get_state' from our code. * src/alloc.c (malloc_initialize_hook) [DOUG_LEA_MALLOC]: Remove check for working 'malloc_set_state'. (alloc_unexec_pre) [DOUG_LEA_MALLOC]: Delete unused function. (alloc_unexec_post) [DOUG_LEA_MALLOC]: Delete function. (malloc_state_ptr) [DOUG_LEA_MALLOC]: Delete variable. * configure.ac (emacs_cv_var_doug_lea_malloc): Don't check for malloc_set_state and malloc_get_state.
2024-12-12Avoid compiler warning in process_mark_stackPip Cet
* src/alloc.c (process_mark_stack): Only declare and assign to 'po' if it's needed. Problem reported by: Stefan Kangas <stefankangas@gmail.com>.
2024-12-12Pure storage removal: Remove documentationPip Cet
As pure storage is now gone, it no longer needs to be documented. * doc/lispref/elisp.texi (Top): * doc/lispref/internals.texi (GNU Emacs Internals): Remove "Pure Storage" section. (Building Emacs, Garbage Collection, Writing Emacs Primitives): * doc/lispref/symbols.texi (Standard Properties): Remove references to pure storage. * src/alloc.c (Fgarbage_collect): Remove docstring text referring to pure storage.
2024-12-12Pure storage removal: Remove support for pinned objectsPip Cet
* src/alloc.c (symbol_block_pinned): Remove variable. (init_symbol): Don't initialize 'pinned flag'. (pinned_objects): Remove variable. (mark_pinned_objects, mark_pinned_symbols): Remove functions. (garbage_collect): Don't call 'mark_pinned_objects', 'mark_pinned_symbols'. * src/lisp.h (struct Lisp_Symbol): Remove 'pinned' flag. * src/pdumper.c (dump_symbol): Remove 'pinned' flag from dump.
2024-12-12Pure storage removal: Replace calls to removed functionsPip Cet
* src/alloc.c (string_bytes, pin_string, valid_lisp_object_p) (process_mark_stack, survives_gc_p, syms_of_alloc): * src/androidterm.c (android_term_init): Replace call to 'build_pure_c_string'. * src/buffer.c (init_buffer_once, syms_of_buffer): * src/bytecode.c (exec_byte_code): * src/callint.c (syms_of_callint): * src/callproc.c (syms_of_callproc): * src/category.c (Fdefine_category): * src/coding.c (syms_of_coding): * src/comp.c (Fcomp__compile_ctxt_to_file0) (maybe_defer_native_compilation, syms_of_comp): * src/data.c (Fsetcar, Fsetcdr, Fdefalias, Faset, syms_of_data): * src/dbusbind.c (syms_of_dbusbind): * src/doc.c (Fsnarf_documentation): * src/emacs-module.c (syms_of_module): * src/eval.c (Finternal__define_uninitialized_variable) (Fdefconst_1, define_error, syms_of_eval): * src/fileio.c (syms_of_fileio): * src/fns.c (Ffillarray, Fclear_string, check_mutable_hash_table): * src/fontset.c (syms_of_fontset): * src/frame.c (make_initial_frame): * src/haikufns.c (syms_of_haikufns): * src/intervals.c (create_root_interval): * src/keyboard.c (syms_of_keyboard): * src/keymap.c (Fmake_sparse_keymap, Fset_keymap_parent) (store_in_keymap, syms_of_keymap): * src/lisp.h: * src/lread.c (Fload, read0, intern_c_string_1, define_symbol) (Fintern, defsubr, syms_of_lread): * src/pdumper.c (Fdump_emacs_portable): * src/pgtkfns.c (syms_of_pgtkfns): * src/pgtkterm.c (syms_of_pgtkterm): * src/process.c (syms_of_process): * src/search.c (syms_of_search): * src/sqlite.c (syms_of_sqlite): * src/syntax.c (syms_of_syntax): * src/treesit.c (syms_of_treesit): * src/w32fns.c (syms_of_w32fns): * src/xdisp.c (syms_of_xdisp): * src/xfaces.c (syms_of_xfaces): * src/xfns.c (syms_of_xfns): * src/xftfont.c (syms_of_xftfont): * src/xterm.c (syms_of_xterm): Remove calls to 'PURE_P', 'CHECK_IMPURE', 'Fpurecopy', and replace calls to 'build_pure_c_string', 'pure_list', 'pure_listn', etc., by impure equivalents.
2024-12-12Pure storage removal: Main partPip Cet
* src/alloc.c (pure, PUREBEG, purebeg, pure_size) (pure_bytes_used_before_overflow, pure_bytes_used_lisp) (pure_bytes_used_non_lisp): Remove definitions. (init_strings): Make empty strings impure. (cons_listn): Drop 'cons' argument. (pure_listn): Remove function. (init_vectors): Allocate zero vector manually to avoid freelist issues. (pure_alloc, check_pure_size, find_string_data_in_pure) (make_pure_string, make_pure_c_string, pure_cons, make_pure_float) (make_pure_bignum, make_pure_vector, purecopy_hash_table): Remove functions. (purecopy): Reduce to hash consing our argument. (init_alloc_once_for_pdumper): Adjust to lack of pure space. (pure-bytes-used): Adjust docstring to mark as obsolete. (purify-flag): Keep for hash consing, but adjust docstring. * src/bytecode.c: * src/comp.c: Don't include "puresize.h". * src/conf_post.h (SYSTEM_PURESIZE_EXTRA): Remove definition. * src/data.c (pure_write_error): Remove function. * src/deps.mk: Remove puresize.h dependency throughout. * src/emacs.c: * src/fns.c: * src/intervals.c: * src/keymap.c: Don't include "puresize.h". * src/lisp.h (struct Lisp_Hash_Table): Adjust comment. (pure_listn, pure_list, build_pure_c_string): Remove. * src/w32heap.c (FREEABLE_P): Don't do use 'dumped_data'. (malloc_before_dump, realloc_before_dump, free_before_dump): Remove functions. * src/w32heap.h: Adjust prototype. * lisp/loadup.el: * lisp/startup.el: Remove purespace code.
2024-12-12Unexec removal: Remove HYBRID_MALLOC supportPip Cet
* src/gmalloc.c (gdefault_morecore): Remove HYBRID_MALLOC code. (allocated_via_gmalloc, hybrid_malloc, hybrid_calloc, hybrid_free_1) (hybrid_free, hybrid_aligned_alloc, hybrid_realloc): Remove functions. * msdos/sed1v2.inp: * msdos/sedlibmk.inp: * src/alloc.c (GC_MALLOC_CHECK, USE_ALIGNED_ALLOC) (refill_memory_reserve, aligned_alloc): * src/emacs.c (main): * src/lastfile.c (my_edata): * src/lisp.h: * src/ralloc.c: * src/sysdep.c (get_current_dir_name_or_unreachable): * src/xdisp.c (decode_mode_spec): Remove HYBRID_MALLOC conditions. * configure.ac (hybrid_malloc, HYBRID_MALLOC): Remove variables and dependent code. * src/conf_post.h (hybrid_malloc, hybrid_calloc, hybrid_free) (hybrid_aligned_alloc, hybrid_realloc): Remove conditional prototypes. * src/Makefile.in (HYBRID_MALLOC): Remove variable. (base_obj): Remove sheap.o (LIBEGNU_ARCHIVE): * lib/Makefile.in (libgnu_a_OBJECTS): Remove libegnu.a support.
2024-12-12Unexec removal: Main partPip Cet
* configure.ac: Remove unexec-specific parts. (EMACS_CONFIG_FEATURES): Always report that we do not have the UNEXEC feature. (AC_ECHO): No longer display a line about the unexec feature. * lisp/loadup.el: * lisp/startup.el: Remove unexec-specific code. * src/Makefile.in (base_obj): Drop 'UNEXEC_OBJ'. * src/alloc.c (staticvec): Never initialize this variable. (BLOCK_ALIGN): Always allow large blocks. (mmap_lisp_allowed_p): Remove unexec-specific code. * src/buffer.c (init_buffer): * src/conf_post.h (ADDRESS_SANITIZER): * src/emacs.c (load_pdump, main): Remove unexec-specific code. (Fdump_emacs): Remove function. (syms_of_emacs): Remove 'Fdump_emacs'. * src/lastfile.c: Remove unexec-specific code. * src/lisp.h (gflags): Remove unexec-specific flags. (will_dump_p, will_bootstrap_p, will_dump_with_unexec_p) (dumped_with_unexec_p, definitely_will_not_unexec_p): Remove or adjust predicates. (SUBR_SECTION_ATTRIBUTE): Remove unexec-specific definition. * src/pdumper.c (Fdump_emacs_portable): Remove unexec-specific warning. * src/process.c (init_process_emacs): Remove !unexec condition * src/sysdep.c (maybe_disable_address_randomization): Adjust comment. (init_signals): * src/timefns.c (init_timefns): Remove unexec-specific code. * src/w32heap.c (report_temacs_memory_usage): Remove function. * src/w32heap.h: Adjust comment. * src/w32image.c (globals_of_w32image): Remove unexec-specific code.
2024-10-22Initial child frames based on masterGerd Möllmann
This is based on a diff from 2024-10-15 which still applied. Since then, I've inadvertantly modified the igc branch so that it is no longer possible to get a clean diff of what has changed since I created the branch.
2024-09-21Merge from origin/emacs-30Eli Zaretskii
4b9a8fd6074 etags-regen-file-extensions: Add .pm 956f14ae5e9 * src/treesit.c (treesit_debug_print_parser_list): Fix co... 300d05ecb4c Type-check argument to network-lookup-address-info 0f0f21b7f27 ; Improve doc strings of options related to numbered backups f0daa2f2153 Conservative heuristic for tree-sitter parser ranges (bug... 035024b4e5a ; Fix treesit.c printing 8771310a10d ; * admin/notes/unicode: Need to run textsec-tests (bug#7... 4c6f45fa8ee Re-enable GC mark trace buffer by default c6077015894 ; * src/haiku_support.cc: Correct last change. ae22ad7f624 ; Add even more tests for previous commit 460b9d705ab Fix treesit_sync_visible_region's range fixup code (bug#7... 81347c1aaf2 ; * etc/PROBLEMS: Fix last change (bug#73207). a82b7f3e823 Document unavailability of frame geometry on Wayland
2024-09-17Re-enable GC mark trace buffer by defaultMattias Engdegård
Enable GC_REMEMBER_LAST_MARKED by default (it was disabled in Emacs 29) to make it easier to debug difficult-to-reproduce GC problems encountered by users. This increases GC costs by about 5 %, which can be avoided by turning the mark trace buffer back off using the new --disable-gc-mark-trace option. See discussion at https://lists.gnu.org/archive/html/emacs-devel/2024-09/msg00240.html * configure.ac (--disable-gc-mark-trace): New config option. * etc/NEWS: Mention it. * src/alloc.c: Enable it by default and avoid a compiler warning.
2024-09-07Remove low-level keyboard hook when attaching GDB to Emacs on WindowsEli Zaretskii
This fixes the problem whereby attaching GDB to a running Emacs on MS-Windows would slow down keyboard input, because the low-level keyboard hook installed by Emacs at startup was still installed, but with Emacs stopped, the hook code couldn't run, and therefore the OS would time-out waiting for the hook to return. Now when GDB is attached to Emacs, it will remove the hook right away. * src/.gdbinit: Call 'remove_w32_kbdhook' if the keyboard hook is already installed. * src/alloc.c (defined_WINDOWSNT): New enum. (gdb_make_enums_visible): Add 'defined_WINDOWSNT'.
2024-08-22Prefer static_assert to verifyStefan Kangas
Although static_assert is C11-specific, and Emacs remains on C99, it has been backported to older compilers by Gnulib. Gnulib has already changed to prefer static_assert, and we can do the same. * lib-src/asset-directory-tool.c (main_2): * src/alloc.c (BLOCK_ALIGN, aligned_alloc, lisp_align_malloc) (vectorlike_nbytes, allocate_pseudovector): * src/android.c (android_globalize_reference, android_set_dashes): * src/android.h: * src/androidfont.c (androidfont_draw, androidfont_text_extents): * src/androidvfs.c: * src/bidi.c (BIDI_CACHE_MAX_ELTS_PER_SLOT, bidi_find_bracket_pairs): * src/buffer.c (init_buffer_once): * src/casefiddle.c (do_casify_multibyte_string): * src/dispnew.c (scrolling_window, scrolling): * src/editfns.c (styled_format): * src/emacs-module.c (module_extract_big_integer): * src/fileio.c (Fdo_auto_save): * src/fns.c (next_almost_prime, hash_string): * src/fringe.c (init_fringe): * src/keyboard.h (kbd_buffer_store_event_hold): * src/keymap.c: * src/lisp.h (memclear, reduce_emacs_uint_to_hash_hash, modiff_incr): * src/lread.c (skip_lazy_string): * src/pdumper.c (dump_bignum, Fdump_emacs_portable) (dump_do_dump_relocation, pdumper_load): * src/process.c (make_process, Fmake_process, connect_network_socket): * src/regex-emacs.c: * src/sort.c (tim_sort): * src/sysdep.c (init_random, SSIZE_MAX): * src/thread.c: * src/timefns.c (trillion_factor): * src/unexelf.c: * src/xterm.c (x_send_scroll_bar_event): Prefer static_assert to Gnulib verify. Remove import of verify.h, except when used for other reasons.
2024-08-01Improve window/buffer handling codeMartin Rudalics
The purpose of these changes is to improve the code handling the display of buffers in windows, switching to previous and next buffers in windows and restoring a previous state after quitting or killing buffers. In particular it does: - Add a new window parameter 'quit-restore-prev' so a window can keep its initial 'quit-restore' parameter and undoing a sequence of quit window operations becomes more reliable (Bug#59862). - Optionally have 'kill-buffer' call 'quit-restore-window' for all windows showing the argument buffer (Bug#59862). - Add a new hook so it's possible to avoid that a window gets deleted implicitly by functions like 'kill-buffer' (Bug#71386). - Add a new option to make 'quit-restore-window' delete windows more aggressively (Bug#59862). - Immediately remove killed buffers from all windows' previous and next buffers. For windows that are already dead, use a weak hash table to be used by 'kill-buffer'. This avoids any special handling of such windows by the garbage collector. - Immediately remove 'quit-restore' and 'quit-restore-prev' window parameters that reference killed buffers. These parameters have no more use once their buffers got killed. - Make sure that internal windows do not have any previous and next buffers. This fixes a silly memory leak. - Make sure that after set_window_buffer and some wset_buffer calls the buffer now shown in the window does not appear in the lists of that window's previous and next buffers. The old behavior could make functions investigating these lists erroneously believe that there still existed some other buffer to switch to. * src/alloc.c (mark_discard_killed_buffers): Remove function. (mark_window): No more filter previous and next buffer lists. * src/window.h (struct window): Move up prev_buffers and next-buffers in structure; they are now treated by the collector as usual. * src/window.c (window_discard_buffer_from_alist) (window_discard_buffer_from_list) (window_discard_buffer_from_window) (window_discard_buffer_from_dead_windows) (Fwindow_discard_buffer): New functions. (set_window_buffer): Discard BUFFER from WINDOW's previous and next buffers. (make_parent_window): Make sure internal windows have no previous and next buffers. (make_window): Don't initialize window's previous and next buffers, they are handled by allocate_window now. (Fdelete_window_internal): Add WINDOW to window_dead_windows_table. (Fset_window_configuration): Remove resurrected window from window_dead_windows_table. Make sure buffers set by wset_buffer calls are not recorded in window's previous and next buffers. (delete_all_child_windows): Add deleted windows to window_dead_windows_table. (window_dead_windows_table): New weak hash table to record dead windows that are stored in saved window configurations. * src/buffer.c (Fkill_buffer): Call new function 'window_discard_buffer_from_dead_windows'. * lisp/window.el (window-deletable-functions): New hook. (window-deletable-p): Update doc-string. Run 'window-deletable-functions' (Bug#71386). (unrecord-window-buffer): New argument ALL. Move body to 'window-discard-buffer-from-window' so that if ALL is non-nil, WINDOW's 'quit-restore' and 'quit-restore-prev' parameters get removed too. (switch-to-prev-buffer): Don't care about killed buffers here; 'replace-buffer-in-windows' should have done that already. Use 'unrecord-window-buffer'. (switch-to-next-buffer): Don't care about killed buffers here; 'replace-buffer-in-windows' should do that now. (kill-buffer-quit-windows): New option. (delete-windows-on): Update doc-string. Handle new option 'kill-buffer-quit-windows'. Update 'unrecord-window-buffer' calls. (replace-buffer-in-windows): Update doc-string. Handle new option 'kill-buffer-quit-windows' (Bug#59862). Update call to 'unrecord-window-buffer'. (quit-restore-window-no-switch): New option. (quit-restore-window): Update doc-string. Handle additional values of BURY-OR-KILL so to not kill a buffer about to be killed by the caller. Handle 'quit-restore-prev' parameter (Bug#59862). Handle new option 'quit-restore-window-no-switch' (Bug#59862). (quit-windows-on): Update doc-string. Call 'quit-window-hook' and call 'quit-restore-window' directly so that the buffer does not get buried or killed by the latter. Update 'unrecord-window-buffer' call. (display-buffer-record-window): Update doc-string. Handle new `quit-restore-prev' parameter (Bug#59862). (switch-to-buffer): Call 'display-buffer-record-window' so a latter 'quit-restore-window' can use its parameters. * doc/lispref/windows.texi (Deleting Windows): Describe implicit deletion of windows and new hook 'window-deletable-functions'. (Buffers and Windows): Update description of 'replace-buffer-in-windows'. Describe new option 'kill-buffer-quit-windows'. (Quitting Windows): Describe 'quit-restore-prev' parameter and new option 'quit-restore-window-no-switch'. Update description of 'quit-restore-window'. (Window Parameters): Mention 'quit-restore-prev' parameter. * etc/NEWS: Add entries for 'window-deletable-functions', 'kill-buffer-quit-windows', 'quit-restore-window-no-switch'. mention new parameter 'quit-restore-prev' and new argument values for 'quit-restore-window'.
2024-07-20Fix bool vector length overflowPaul Eggert
* src/alloc.c (make_clear_bool_vector): It’s now the caller’s responsibility to make sure the bool vector length is in range. Add an eassert to double-check this. This lets some locals be ptrdiff_t not EMACS_INT. (Fmake_bool_vector, Fbool_vector): Check that bool vector lengths are in range. * src/lisp.h (BOOL_VECTOR_LENGTH_MAX): New macro. (bool_vector_words, bool_vector_bytes): Avoid undefined behavior if size == EMACS_INT_MAX - (BITS_PER_BITS_WORD - 1). This is mostly theoretical but it’s easy to do it right. * src/lread.c (read_bool_vector): Use EMACS_INT, not just ptrdiff_t. Check that length doesn’t exceed BOOL_VECTOR_LENGTH_MAX. This fixes an unlikely integer overflow where the calculated size went negative.
2024-07-20Avoid accessing uninitialized bool_vector wordsPaul Eggert
Although loading uninitialized works from memory and then ignoring the result works fine on conventional architectures, it technically has undefined behavior in C, so redo bool_vector allocation so that the code never does that. This can improve performance when allocating large vectors of nil, since calloc can clear the memory lazily. * src/alloc.c (make_clear_bool_vector): New function, a generalization of make_uninit_bool_vector. (make_uninit_bool_vector): Use it. (Fmake_bool_vector): If !INIT, rely on make_clear_bool_vector. * src/alloc.c (Fbool_vector): * src/fns.c (Freverse): Don’t access uninitialized bool_vector words.
2024-07-16alloc.c: ckd_add, not by-hand checksPaul Eggert
* src/alloc.c (lmalloc, lrealloc): Prefer ckd_add to by-hand checks for integer addition overflow.
2024-07-16Pacify -Wmissing-variable-declarations for lisp_malloc_userPaul Eggert
* src/alloc.c (lisp_malloc_user) [!USE_LSB_TAG]: Provide extern decl.
2024-06-20Correctly cache images when frames vary in their font metricsPo Lu
* src/alloc.c (mark_frame): Mark this frame's image cache, if it exist. (mark_terminals): Cease marking T->image_cache. * src/androidfns.c (unwind_create_frame, Fx_create_frame) (android_create_tip_frame): * src/haikufns.c (unwind_create_frame, haiku_create_frame) (haiku_create_tip_frame): * src/nsfns.m (unwind_create_frame): * src/pgtkfns.c (unwind_create_frame, Fx_create_frame) (x_create_tip_frame): * src/xfns.c (unwind_create_frame, Fx_create_frame) (x_create_tip_frame): * src/w32fns.c (unwind_create_frame, Fx_create_frame) (w32_create_tip_frame): Remove adjustments of the frame image cache's reference count rendered redundant by the assignment of image caches to individual frames rather than terminals. * src/dispextern.h (struct image_cache) <scaling_col_width>: New field. * src/frame.c (gui_set_font): In lieu of clearing F's image cache unconditionally, establish whether the column width as considered by compute_image_size has changed, and if so, adjust or reassign the frame's image cache. (make_frame): Clear F->image_cache. * src/frame.h (struct frame) <image_cache>: New field. (FRAME_IMAGE_CACHE): Return F->image_cache. * src/image.c (make_image_cache): Clear C->scaling_col_width. (cache_image): Adjust to new means of assigning image caches to frames. * src/termhooks.h (struct terminal) <image_cache>: Delete field. * src/xfaces.c (init_frame_faces): Do image cache assignment with all new frames.