summaryrefslogtreecommitdiff
path: root/src/alloc.c
Commit message (Collapse)AuthorAgeFilesLines
* Make Emacs compile with musl instead of glibcLars Ingebrigtsen2021-08-151-2/+2
| | | | * src/alloc.c: musl doesn't have malloc_info (bug#50058).
* Pacify gcc -Woverflow more clearlyPaul Eggert2021-07-141-1/+3
| | | | | * src/alloc.c (mark_maybe_pointer): Make it clearer that ANDing with UINTPTR_MAX is intended. Omit a now-unnecessary cast.
* Pacify gcc -Woverflow more nicelyPaul Eggert2021-07-121-6/+1
| | | | | * src/alloc.c (mark_maybe_pointer): Simplify pacification of gcc -Woverflow (unknown GCC version).
* Fix compilation of the --with-wide-int configurationEli Zaretskii2021-07-111-0/+4
| | | | | * src/alloc.c (mark_maybe_pointer): Fix a recent change for WIDE_EMACS_INT builds. (Bug#49261)
* Make pdumper-marking pickierPaul Eggert2021-07-111-9/+25
| | | | | | | | | Prevent some false-positives in conservative GC marking. This doesn’t fix any correctness bugs; it’s merely to reclaim some memory instead of keeping it unnecessarily. * src/alloc.c (mark_maybe_pointer): New arg SYMBOL_ONLY. All callers changed. Check that the pointer’s tag, if any, matches the pdumper-reported type.
* Fix pdumper-related GC bugPaul Eggert2021-07-111-0/+11
| | | | | | * src/alloc.c (mark_maybe_pointer): Also mark pointers to pdumper objects, even when the pointers are tagged. Add a FIXME saying why this isn’t enough.
* Merge remote-tracking branch 'savannah/master' into native-compAndrea Corallo2021-04-191-1/+1
|\
| * Fix 'garbage-collect-maybe'Eli Zaretskii2021-04-151-1/+1
| | | | | | | | | | * src/alloc.c (Fgarbage_collect_maybe): No longer interactive. (Bug#47805)
* | Zero stale pointer when unloading comp units (bug#46256)Pip Cet2021-03-091-2/+1
| | | | | | | | | | * src/alloc.c (cleanup_vector): Call unload_comp_unit. * src/comp.c (unload_comp_unit): New function.
* | Merge remote-tracking branch 'savannah/master' into HEADAndrea Corallo2021-02-211-0/+33
|\|
| * Faster, more compact, and readable closure creationMattias Engdegård2021-02-211-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Simplify closure creation by calling a single function at run time instead of putting it together from small pieces. This is faster (by about a factor 2), takes less space on disk and in memory, and makes internal functions somewhat readable in disassembly listings again. This is done by creating a prototype function at compile-time whose closure variables are placeholder values V0, V1... which can be seen in the disassembly. The prototype is then cloned at run time using the new make-closure function that replaces the placeholders with the actual closure variables. * lisp/emacs-lisp/bytecomp.el (byte-compile-make-closure): Generate call to make-closure from a prototype function. * src/alloc.c (Fmake_closure): New function. (syms_of_alloc): Defsubr it. * src/data.c (syms_of_data): Defsym byte-code-function-p.
* | Merge remote-tracking branch 'savannah/master' into native-compAndrea Corallo2021-01-241-2/+4
|\|
| * Don't let `maybe_quit` prevent resetting `consing_until_gc` (bug#43389)Stefan Monnier2021-01-201-2/+4
| | | | | | | | | | * src/alloc.c (garbage_collect): Postpone `unblock_input` a bit. * src/window.c (window_parameter): Avoid `maybe_quit`.
* | Merge remote-tracking branch 'savannah/master' into HEADAndrea Corallo2021-01-021-1/+1
|\|
| * Update copyright year to 2021Paul Eggert2021-01-011-1/+1
| | | | | | | | Run "TZ=UTC0 admin/update-copyright".
* | Store function type and expose it with `subr-type'Andrea Corallo2020-12-281-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/lisp.h (struct Lisp_Subr): Add 'type' field. (SUBR_TYPE): New inline accessor. * src/pdumper.c (dump_subr): Update for 'type' field. * src/data.c (Fsubr_type): New primitive. (syms_of_data): Update. * src/comp.c (ABI_VERSION): Bump new ABI version. (make_subr): Set type. (Fcomp__register_lambda, Fcomp__register_subr) (Fcomp__late_register_subr): Receive and pass subr type to 'make_subr'. * src/alloc.c (mark_object): Mark subr type. * lisp/emacs-lisp/comp.el (comp-func): Change slot type into mvar. (comp-emit-for-top-level, comp-emit-lambda-for-top-level): Pass type mvar to subr register functions. (comp-compute-function-type): Fix-up subr type mvars. * test/src/comp-tests.el (comp-tests-check-ret-type-spec): Use `subr-type'.
* | Merge remote-tracking branch 'savannah/master' into HEADAndrea Corallo2020-12-271-1/+5
|\|
| * Adjust to recent Gnulib changesPaul Eggert2020-12-251-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The latest Gnulib merge brought in free-posix, which causes 'free' to preserve errno. This lets us simplify some Emacs code that calls 'free'. * admin/merge-gnulib (GNULIB_MODULES): Add free-posix. This module is pulled in by canonicalize-lgpl anyway, so we might as well rely on it. * lib-src/emacsclient.c (get_current_dir_name): Sync better with src/sysdep.c. * lib-src/etags.c (process_file_name, etags_mktmp): * lib-src/update-game-score.c (unlock_file): * src/fileio.c (file_accessible_directory_p): * src/sysdep.c (get_current_dir_name_or_unreachable): Simplify by assuming that 'free' preserves errno. * src/alloc.c (malloc_unblock_input): Preserve errno, so that xfree preserves errno. * src/sysdep.c (get_current_dir_name_or_unreachable): Simplify by using strdup instead of malloc+memcpy. No need for realloc (and the old code leaked memory anyway on failure); just use free+malloc.
* | Merge remote-tracking branch 'savannah/master' into HEADAndrea Corallo2020-12-231-1/+1
|\|
| * Fix use of obsolete 'emergency' warning levelStefan Kangas2020-12-231-1/+1
| | | | | | | | | | * src/alloc.c (display_malloc_warning): Use new style ':emergency' warning level instead of obsolete 'emergency'.
* | Merge remote-tracking branch 'savannah/master' into HEADAndrea Corallo2020-12-061-0/+25
|\|
| * * src/alloc.c (Fgarbage_collect_maybe): New functionSpencer Baugh2020-12-041-0/+25
| |
* | Merge remote-tracking branch 'savannah/master' into HEADAndrea Corallo2020-11-291-5/+8
|\|
| * garbage-collect doc string clarificationLars Ingebrigtsen2020-11-291-1/+8
| | | | | | | | | | * src/alloc.c (Fgarbage_collect): Mention that calling this function is not guaranteed to collect all the garbage (bug#34404).
| * Fix incorrect handling of module runtime and environment pointers.Philipp Stephani2020-11-271-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We used to store module runtime and environment pointers in the static lists Vmodule_runtimes and Vmodule_environments. However, this is incorrect because these objects have to be kept per-thread. With this naive approach, interleaving module function calls in separate threads leads to environments being removed in the wrong order, which in turn can cause local module values to be incorrectly garbage-collected. The fix isn't completely trivial: specbinding the lists wouldn't work either, because then the garbage collector wouldn't find the environments in other threads than the current ones, again leading to objects being garbage-collected incorrectly. While introducing custom pseudovector types would fix this, it's simpler to put the runtime and environment pointers into the specbinding list as new specbinding kinds. This works since we need to unwind them anyway, and we only ever treat the lists as a stack. The thread switching machinery ensures that the specbinding lists are thread-local, and that all elements of the specbinding lists in all threads are marked during garbage collection. Module assertions now have to walk the specbinding list for the current thread, which is more correct since they now only find environments for the current thread. As a result, we can now remove the faulty Vmodule_runtimes and Vmodule_environments variables entirely. Also add a unit test that exemplifies the problem. It interleaves two module calls in two threads so that the first call ends while the second one is still active. Without this change, this test triggers an assertion failure. * src/lisp.h (enum specbind_tag): Add new tags for module runtimes and environments. * src/eval.c (record_unwind_protect_module): New function to record a module object in the specpdl list. (do_one_unbind): Unwind module objects. (backtrace_eval_unrewind, default_toplevel_binding, lexbound_p) (Fbacktrace__locals): Deal with new specbinding types. (mark_specpdl): Mark module environments as needed. * src/alloc.c (garbage_collect): Remove call to 'mark-modules'. Garbage collection of module values is now handled as part of marking the specpdl of each thread. * src/emacs-module.c (Fmodule_load, funcall_module): Use specpdl to record module runtimes and environments. (module_assert_runtime, module_assert_env, value_to_lisp): Walk through specpdl list instead of list variables. (mark_module_environment): Rename from 'mark_modules'. Don't attempt to walk though current thread's environments only, since that would miss other threads. (initialize_environment, finalize_environment): Don't change Vmodule_environments variable; environments are now in the specpdl list. (finalize_environment_unwind, finalize_runtime_unwind): Make 'extern' since do_one_unbind now calls them. (finalize_runtime_unwind): Don't change Vmodule_runtimes variable; runtimes are now in the specpdl list. (syms_of_module): Remove Vmodule_runtimes and Vmodule_environments. * test/data/emacs-module/mod-test.c (Fmod_test_funcall): New test function. (emacs_module_init): Bind it. * test/src/emacs-module-tests.el (emacs-module-tests--variable): New helper type to guard access to state in a thread-safe way. (emacs-module-tests--wait-for-variable) (emacs-module-tests--change-variable): New helper functions. (emacs-module-tests/interleaved-threads): New unit test.
* | Merge remote-tracking branch 'savannah/master' into devAndrea Corallo2020-11-141-0/+17
|\|
| * New debugging command 'malloc-info'Eli Zaretskii2020-11-101-0/+17
| | | | | | | | | | * src/alloc.c (Fmalloc_info) [GNU_LINUX]: New command. (syms_of_alloc): Defsubr it. (Bug#43389)
* | Merge remote-tracking branch 'savannah/master' into HEADAndrea Corallo2020-10-101-1/+1
|\|
| * Use the full name of the null byte/character, not its abbreviationAndreas Schwab2020-10-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lisp/subr.el (inhibit-nul-byte-detection): Make it an obsolete alias. * src/coding.c (setup_coding_system): Use original name. (detect_coding): Rename nul_byte_found => null_byte_found. (detect_coding_system): Use original name. Rename nul_byte_found => null_byte_found. (Fdefine_coding_system_internal): Use original name. (syms_of_coding): Rename inhibit-nul-byte-detection to inhibit-null-byte-detection. * src/w16select.c (get_clipboard_data): Rename nul_char to null_char. * src/json.c (check_string_without_embedded_nulls): Rename from check_string_without_embedded_nuls. (Fjson_parse_string): Adjust accordingly. * src/coding.h (enum define_coding_undecided_arg_index) (enum coding_attr_index): Rename ...nul_byte... to ...null_byte.... * lisp/info.el (info-insert-file-contents, Info-insert-dir): * lisp/international/mule.el (define-coding-system): * lisp/vc/vc-git.el (vc-git--call): * doc/lispref/nonascii.texi (Lisp and Coding Systems): Use original name.
* | Rework eln deletion strategy for new eln-cache folder structureAndrea Corallo2020-09-061-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When recompiling remove the corresponding stale elns found in the `comp-eln-load-path'. When removing a package remove the corresponding elns too. On Windows both of these are performed only when possible, when it's not the file is renamed as .eln.old and a last attempt to remove this is performed closing the Emacs session. When a file being deleted was loaded by multiple Emacs sessions the last one being closed should delete it. * lisp/emacs-lisp/comp.el (comp-clean-up-stale-eln): New function. (comp-delete-or-replace-file): Rename from `comp--replace-output-file' and update so it can be used for replacing or deleting shared libs safetly. * lisp/emacs-lisp/package.el (package--delete-directory): When native compiled just call `comp-clean-up-stale-eln' for each eln file we want to clean-up. * src/alloc.c (cleanup_vector): Call directly the dynlib_close. * src/comp.c (syms_of_comp): Update for comp_u->cfile removal. Make 'all_loaded_comp_units_h' key-value weak as now the key will be the filename. (load_comp_unit): Register the compilation unit only when the load is fully completed. (register_native_comp_unit): Make the key of all_loaded_comp_units_h the load filename. (eln_load_path_final_clean_up): New function. (dispose_comp_unit) (finish_delayed_disposal_of_comp_units) (dispose_all_remaining_comp_units) (clean_package_user_dir_of_old_comp_units): Remove. (Fcomp__compile_ctxt_to_file): Update for `comp--replace-output-file' -> `comp-delete-or-replace-file' rename. * src/comp.h (dispose_comp_unit) (finish_delayed_disposal_of_comp_units) (dispose_all_remaining_comp_units) (clean_package_user_dir_of_old_comp_units): Remove. (eln_load_path_final_clean_up): Add. (struct Lisp_Native_Comp_Unit): Remove cfile field. * src/emacs.c (Fkill_emacs): Call 'eln_load_path_final_clean_up'. * src/pdumper.c (dump_do_dump_relocation): Do not set comp_u->cfile.
* | Merge remote-tracking branch 'savannah/master' into HEADAndrea Corallo2020-09-061-129/+118
|\|
| * Reinstall recent GC-related changesPaul Eggert2020-09-051-129/+118
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The report that they broke macOS was a false alarm, as the previous commit was also broken (Bug#43152#62). * src/alloc.c (live_string_holding, live_cons_holding) (live_symbol_holding): Count only pointers that point to a struct component, or are a tagged pointer to the start of the struct. Exception: for non-bool-vector pseudovectors, count any pointer past the header, since it’s too much of a pain to write code for every pseudovector. (live_float_holding, live_vector_pointer): New functions, which are similar about counting pointers. (live_float_p, live_large_vector_holding) (live_small_vector_pointer, mark_maybe_pointer): Use them. (mark_maybe_object, mark_maybe_objects): Remove, and remove all callers; mark_maybe_pointer now suffices. (mark_objects): New function. * src/alloc.c (mark_vectorlike, mark_face_cache): * src/eval.c (mark_specpdl): * src/fringe.c (mark_fringe_data): * src/keyboard.c (mark_kboards): Simplify by using mark_objects. * src/lisp.h (SAFE_ALLOCA_LISP_EXTRA): Clear any Lisp_Object arrays large enough to not fit into the stack, so that GC need not worry about whether they contain objects.
| * Revert recent GC-related changes (Bug#43152)Paul Eggert2020-09-031-118/+129
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/alloc.c (live_string_holding, live_cons_holding) (live_symbol_holding, live_large_vector_holding) (live_small_vector_holding): Go back to old approach of treating every would-be pointer to any byte in the object (though not to just past the object end) as addressing the object. (live_float_p): Require that the would-be float point to the start of the Lisp_Float, and not anywhere else. (live_vector_pointer, live_float_holding, mark_objects): Remove. All uses removed. (mark_maybe_object, mark_maybe_objects): Bring back these functions. * src/lisp.h (SAFE_ALLOCA_LISP_EXTRA): Do not clear the new slots, as they're now checked via mark_maybe_objects, not via mark_objects.
| * * src/alloc.c (live_symbol_holding): Pacify gcc -Wlogical-op.Paul Eggert2020-08-311-2/+2
| |
| * Use mark_objects elsewhere tooPaul Eggert2020-08-311-7/+3
| | | | | | | | | | | | | | | | * src/alloc.c (mark_vectorlike, mark_face_cache): * src/eval.c (mark_specpdl): * src/fringe.c (mark_fringe_data): * src/keyboard.c (mark_kboards): Use mark_objects instead of doing it by hand.
| * Remove mark_maybe_objectPaul Eggert2020-08-311-91/+14
| | | | | | | | | | | | | | | | | | | | | | * src/alloc.c (mark_maybe_object, mark_maybe_objects): Remove. (mark_objects): New function. * src/eval.c (mark_specpdl): Use mark_objects instead of mark_maybe_objects, since the array now has only valid Lisp objects. * src/lisp.h (SAFE_ALLOCA_LISP_EXTRA): When allocating a large array, clear it so that it contains only valid Lisp objects. This is simpler and safer, and does not hurt performance significantly on my usual benchmark as the code is executed so rarely.
| * Avoid some false matches in mark_maybe_pointerPaul Eggert2020-08-311-14/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This lets Emacs avoid marking some garbage as if it were in use. On one test platform (RHEL 7.8, Intel Xeon Silver 4116) it sped up ‘cd lisp; make compile-always’ by a bit over 1%. * src/alloc.c (live_string_holding, live_cons_holding) (live_symbol_holding, live_large_vector_holding) (live_small_vector_holding): Count only pointers that point to a struct component, or are a tagged pointer to the start of the struct. Exception: for non-bool-vector pseudovectors, count any pointer past the header, since it’s too much of a pain to write code for every pseudovector. (live_vector_pointer): New function.
| * Omit no-longer-needed stack mark_maybe_objectPaul Eggert2020-08-311-5/+0
| | | | | | | | | | | | * src/alloc.c (mark_memory): Do not bother using mark_maybe_object on the stack, since mark_maybe_pointer now marks everything that mark_maybe_object would.
| * Fix GC bug with Lisp floats and --with-wide-intPaul Eggert2020-08-311-12/+31
| | | | | | | | | | | | | | | | | | | | On --with-wide-int platforms where Lisp_Object can be put into non-adjacent registers, mark_maybe_pointer failed to mark a float whose only reference was as a tagged pointer. * src/alloc.c (live_float_holding): New function, a generalization of the old live_float_p. (live_float_p): Use it. (mark_maybe_pointer): Use live_float_holding, not live_float_p.
* | Merge remote-tracking branch 'savannah/master' into HEADAndrea Corallo2020-08-091-34/+18
|\|
| * Drop support for -fcheck-pointer-boundsPaul Eggert2020-08-041-20/+11
| | | | | | | | | | | | | | | | | | | | | | GCC has removed the -fcheck-pointer bounds option, and the Linux kernel has also removed support for Intel MPX, so there’s no point to keeping this debugging option within Emacs. * src/bytecode.c (BYTE_CODE_THREADED): * src/lisp.h (DEFINE_LISP_SYMBOL, XSYMBOL, make_lisp_symbol): Assume __CHKP__ is not defined. * src/ptr-bounds.h: Remove. All uses of ptr_bounds_clip, ptr_bounds_copy, ptr_bounds_init, ptr_bounds_set removed.
| * Simplify pointer computation in mark_maybe_objectPaul Eggert2020-08-031-17/+7
| | | | | | | | | | | | | | | | * src/alloc.c (mark_maybe_object): Use simpler way to avoid -fsanitize=undefined false alarms, by converting the word tag to intptr_t first. Omit now-unnecessary runtime overflow check. (mark_memory): Work even if UINTPTR_MAX <= INT_MAX (!).
| * * src/alloc.c (mark_maybe_object): Avoid signed integer overflowPhilipp Stephani2020-08-021-1/+2
| |
| * Fix last change in alloc.c.Eli Zaretskii2020-08-021-0/+2
| | | | | | | | | | * src/alloc.c (mark_maybe_object) [WIDE_EMACS_INT]: Avoid compiler warning about 'overflow' being unused.
* | Merge remote-tracking branch 'savannah/master' into HEADAndrea Corallo2020-08-021-29/+18
|\|
| * * src/alloc.c (mark_memory): Avoid signed integer overflowPhilipp Stephani2020-08-021-1/+1
| |
| * * src/alloc.c (mark_maybe_object): Make overflow check conditional.Philipp Stephani2020-08-011-0/+6
| |
| * Improve offset calculation in wide int buildsPhilipp Stephani2020-08-011-2/+4
| | | | | | | | | | * src/alloc.c (mark_maybe_object): Make sure that OFFSET isn’t widened during subtraction.
| * * src/alloc.c (resize_string_data): Adjust string bytes (Bug#42540)Philipp Stephani2020-08-011-0/+3
| |
| * Suppress sanitizer errors about pointer arithmetic in a few placesPhilipp Stephani2020-08-011-2/+3
| | | | | | | | | | | | | | | | | | | | We perform weird pointer arithmetic due to the layout of Lisp_Objects holding symbols. ASan/UBSan warns about that (Bug#42530). Suppress the warnings by performing the arithmetic on integer types and casting back to pointers. * src/alloc.c (mark_maybe_object, mark_memory): Temporarily cast pointer to 'intptr_t'.