1. 30 May, 2019 1 commit
    • Paul Eggert's avatar
      Pacify GCC 9 -Wredundant-decls · 4b24b018
      Paul Eggert authored
      * src/gmalloc.c (_fraghead) [!HYBRID_MALLOC]:
      Make it static in this case, too.  This avoids having both
      ‘extern struct list _fraghead[];’ and
      ‘static struct list _fraghead[BLOCKLOG];’, which
      GCC 9 complains about.
  2. 15 Jan, 2019 1 commit
    • Daniel Colascione's avatar
      Add portable dumper · d12e5d00
      Daniel Colascione authored
      Add a new portable dumper as an alternative to unexec.  Use it by default.
      * src/dmpstruct.awk: New file.
      * src/doc.c (get_doc_string): use will_dump_p().
      * src/editfns.c (styled_format): silence compiler warning
      with UNINIT.
      * src/emacs-module.c (syms_of_module): staticpro ltv_mark.
      * src/emacs.c (gflags): new variable.
      (init_cmdargs): unwrap
      (string_starts_with_p, find_argument, dump_error_to_string)
      (load_pdump): new functions.
      (main): detect pdumper and --temacs invocation; actually load
      portable dump when detected; set gflags as appropriate; changes to
      init functions throughout to avoid passing explicit
      'initialized' argument.
      * src/eval.c (inhibit_lisp_code): remove unused variable.
      (init_eval_once_for_pdumper): new function.
      (init_eval_once): call it.
      * src/filelock.c: CANNOT_DUMP -> will_dump_p()
      * src/fingerprint-dummy.c: new file
      * src/fingerprint.h: new file
      * src/fns.c: CANNOT_DUMP -> will_dump_p(), etc.
      (weak_hash_tables): remove
      (hashfn_equal, hashfn_eql): un-staticify
      (make_hash_table): set new 'next_weak' hash table field; drop
      global weak_hash_tables logic.
      (copy_hash_table): drop global weak_hash_tables logic.
      (hash_table_rehash): new function.
      (hash_lookup, hash_put, hash_remove_from_table, hash_clear):
      rehash if needed.
      (sweep_weak_table): un-staticify; explain logic; bool-ify.
      (sweep_weak_hash_tables): remove function.
      * src/font.c (syms_of_font): remember pdumper stuff.
      * src/fontset.c (syms_of_fontset): remember pdumper stuff.
      * src/frame.c (make_initial_frame): don't reset Vframe_list.
      (init_frame_once_for_pdumper, init_frame_once): new functions.
      (syms_of_frame): remove redundant staticpro.
      * src/fringe.c (init_fringe_once_for_pdumper): new functin.
      (init_fringe_once): call it.
      * src/ftcrfont.c (syms_of_ftcrfont_for_pdumper): new function.
      (syms_of_ftcrfont): call it.
      * src/ftfont.c (syms_of_ftfont_for_pdumper): new function.
      (syms_of_ftfont): call it.
      * src/ftxont.c (syms_of_ftxfont_for_pdumper): new function.
      (syms_of_ftxfont): call it.
      * src/gmalloc.c: adjust for pdumper througout
      (DUMPED): remove weird custom dumped indicator.
      * src/gnutls.c (syms_of_gnutls): pdumper note for
      * src/image.c (syms_of_image): add pdumper comment,
      initializer note.
      * src/insdel.c (prepare_to_modify_buffer_1): account
      for buffer contents possibly being in dump image.
      * src/keyboard.c (syms_of_keyboard_for_pdumper): new function.
      (syms_of_keyboard): staticpro more; call pdumper syms function.
      * src/lisp.h: add comments throughout
      (gflags): declare.
      (will_dump_p, will_bootstrap_p, will_dump_with_pdumper_p)
      (dumped_with_pdumper_p, will_dump_with_unexec_p)
      (dumped_with_unexec_p, definitely_will_not_unexec_p): new
      (POWER_OF_2, ROUNDUP): move macros.
      (PSEUDOVECTOR_TYPE, PSEUDOVECTOR_TYPEP): take vectorlike header
      pointer instead of vector; constify.
      (Lisp_Hash_Table): add comment about need to rehash on access; add
      comment for next_weak.
      (hash_table_rehash): declare.
      (hash_rehash_needed_p, hash_rehash_if_needed): new functions.
      (finalizers, doomed_finalizers): declare extern.
      (SUBR_SECTION_ATTRIBUTE): new macro.
      (staticvec, staticidx): un-static-ify.
      (sweep_weak_hash_tables): remove declaration.
      (sweep_weak_table): declare.
      (hashfn_eql, hashfn_equal): declare.
      (number_finalizers_run): new variable.
      (Vdead): externify when ENABLE_CHECKING.
      (gc_root_type): new enumeration.
      (gc_root_visitor): new struct.
      (visit_static_gc_roots): declare.
      (vectorlike_nbytes): declare.
      (vector_nbytes): define as trivial inline function wrapper for
      (init_obarray_once): change signature.
      (primary_thread): extern-ify.
      (init_buffer): change signature.
      (init_frame_once): declare.
      * src/lread.c (readevalloop): adjust for new dumped predicates.
      (init_obarray_once): new function.
      (ndefsubr): new variable.
      (defsubr): increment it.
      (load_path_check): adjust for pdumper.
      (load_path_default): use pdumper functions; adjust for
      dump search.
      * src/macfont.m (macfont_init_font_change_handler): avoid
      shadowing global.
      (syms_of_macfont_for_pdumper): new function.
      (syms_of_macfont): call it.
      * src/menu.c (syms_of_menu): staticpro more stuff.
      * src/minibuf.c (Ftry_completion): rehash if needed.
      (init_minibuf_once_for_pdumper): new function.
      (init_minibuf_once): call it.
      * src/nsfont.m (syms_of_nsfns): staticpro more.
      * src/nsfont.m (syms_of_nsfont_for_pdumper): new function.
      (syms_of_nsfont): call it.
      * src/nsterm.m (syms_of_nsfont): remember pdumper stuff.
      * src/pdumper.c: new file.
      * src/pdumper.h: new file.
      * src/process.c (init_process_emacs): use new pdumper functions
      instead of CANNOT_DUMP.
      * src/profiler.c (syms_of_profiler_for_pdumper): new function.
      (syms_of_profiler_for_pdumper): call it.
      * src/search.c (syms_of_search_for_pdumper): new function.
      (syms_of_search_for_pdumper): call it.
      * src/sheap.c (bss_sbrk_did_unexec): remove.
      * src/sheap.h (bss_sbrk_did_unexec): remove.
      * src/syntax.c (syms_of_syntax): don't redundantly staticpro
      * src/sysdep.c: use will_dump_with_unexec_p() instead of bss
      hack thing.
      * src/syssignals.h (init_sigsegv): declare.
      * src/systime.h (init_timefns): remove bool from signature.
      * src/textprop.c (syms_of_textprop): move staticpro.
      * src/thread.c (main_thread_p): constify.
      * src/thread.h (main_thread_p): constify.
      * src/timefns.c (init_timefns): remove bool from signature.
      (syms_of_timefns_for_pdumper): new function.
      (syms_of_timefns): call it.
      * src/w32.c: rearrange code.
      * src/w32.h (w32_relocate): declare.
      * src/w32fns.c (syms_of_w32fns): add pdumper note.
      * src/w32font.c (syms_of_w32font_for_pdumper): new function.
      (syms_of_w32font): call it.
      * src/w32heap.c (using_dynamic_heap): new variable.
      (init_heap): use it.
      * src/w32menu.c (syms_of_w32menu): add pdumper note.
      * src/w32proc.c
      (ctrl_c_handler, mainCRTStartup, _start, open_input_file)
      (rva_to_section, close_file_data): move here.
      * src/w32uniscribe.c (syms_of_w32uniscribe_for_pdumper):
      new function.
      (syms_of_w32uniscribe): call it.
      * src/window.c (init_window_once_for_pdumper): new function.
      (init_window_once): call it; staticpro more stuff.
      * src/xfont.c (syms_of_xfont_for_pdumper): new function.
      (syms_of_xfont): call it.
      * src/xftfont.c (syms_of_xftfont_for_pdumper): new function.
      (syms_of_xftfont): call it.
      * src/xmenu.c (syms_of_xmenu_for_pdumper): new function.
      (syms_of_xmenu): call it.
      * src/xselect.c (syms_of_xselect_for_pdumper): new function.
      (syms_of_xselect): call it.
      * src/xsettings.c (syms_of_xsettings): add more pdumper notes.
      * src/term.c (syms_of_xterm): add pdumper note.
      * src/dispnew.c (init_faces_initial): new function.
      (init_display_interactive): rename from init_display; use
      will_dump_p instead of !initialized.  Initialize faces early for
      pdumper if needed.
      (init_display): new function.
      (syms_of_display_for_pdumper): new function.
      (syms_of_display): call it.
      * src/dbusbind.c (syms_of_dbusbind): Add TODO for bus reset
      on pdumper load.
      * src/data.c (Fdefalias): Use will_dump_p
      instead of Vpurify_flag.
      (Fmake_variable_buffer_local): silence compiler warning with -Og
      by making valcontents UNINIT.
      (arith_driver): silence compiler warning with UNINIT.
      * src/conf_post.h (ATTRIBUTE_SECTION): new macro.
      * src/composite.c (composition_gstring_put_cache): rehash hash
      table if needed.
      * src/coding.c (init_coding_once, syms_of_coding): remember
      pdumper stuff.
      * src/charset.h (charset_table_size, charset_table_user): declare.
      * src/charset.c (charset_table_used, charset_table_size): un-static.
      (init_charset_oncem, syms_of_charset): remember pdumper stuff.
      * src/category.c (category_table_version): remove obsolete
      * src/callint.c (syms_of_callint): staticpro 'preserved_fns'
      (init_callproc): use will_dump_p instead of !CANNOT_DUMP.
      * src/bytecode.c (exec_byte_code): rehash table tables if needed
      * src/buffer.c (alloc_buffer_text, free_buffer_text): account for
      (init_buffer_once): add TODO; remember stuff for pdumper.
      (init_buffer): don't take initialized argument; adjust
      for pdumper.
      * src/atimer.c (init_atimer): initialize subr only if
      * src/alloc.c: (vector_marked_p, set_vector_marked)
      (vectorlike_marked_p, set_vectorlike_marked, cons_marked_p)
      (set_cons_marked, string_marked_p, set_string_marked)
      (symbol_marked_p, set_symbol_marked, interval_marked_p)
      (set_interval_marked): new accessor routines.  Use them
      instead of raw GC access throughout.
      (Vdead): make non-static when ENABLE_CHECKING.
      (vectorlike_nbytes): rename of 'vector_nbytes'; take a vectorlike
      header as input instead of a vector.
      (number_finalizers_run): new internal C variable.
      (mark_maybe_object): check for pdumper objects.
      (valid_pointer_p): don't be gratuitously inefficient under rr(1).
      (make_pure_c_string): add support for size_byte = -2 mode
      indicating that string data points into Emacs image rodata.
      (visit_vectorlike_root): visits GC roots embedded in
      vectorlike objects.
      (visit_buffer_root): visits GC roots embedded in
      our totally-not-a-buffer buffer global objects.
      (visit_static_gc_roots): visit GC roots in the Emacs data section.
      (mark_object_root_visitor): root callback used for conventional GC
      (weak_hash_tables): new internal variable for tracking found weak
      hash tables during GC.
      (mark_and_sweep_weak_table_contents): new weak hash table marking.
      (garbage_collect_1): use new GC root visitor machinery.
      (mark_vectorlike): accept a vectorlike_header instead of a
      (mark_frame, mark_window, mark_hash_table): new functions.
      (mark_object): initialize 'm'; check for pdumper objects and use
      new mark-bit accessors throughout.  Remove some object-specific
      marking code and move to helper functions above.
      (survives_gc_p): check for pdumper objects.
      (gc-sweep): clear pdumper mark bits.
      (init_alloc_once_for_pdumper): new helper function for early init
      called both during normal init and pdumper load.
      (init_alloc_once): pdumper integration.
      * src/Makefile.in: Rewrite dumping for pdumper; add pdumper.o;
      invoke temacs with --temacs command line option; build dmpstruct.h
      from dmpstruct.awk; stop relying on CANNOT_DUMP; clean up pdumper
      intermediate files during build.
      * nextstep/Makefile.in: build emacs.pdmp into NS packages
      * lisp/startup.el: account for new '--temacs' and '--dump-file'
      command line option.
      * lisp/loadup.el: rewrite early init to account for pdumper; use
      injected 'dump-mode' variable (set via the new '--temacs' option)
      instead of parsing command line.
      * lisp/cus-start.el: Check 'dump-mode' instead of 'purify-flag',
      since the new 'dump-mode'
      * lib-src/make-fingerprint.c: new program
      * lib-src/Makefile.in: built make-fingerprint utility program
      * configure.ac: Add --with-pdumper toggle to control pdumper
      support; add --with-unexec toggle to control unexec support.
      Add --with-dumping option to control which dumping strategy we use
      by default.  Adjust for pdumper throughout.  Check for
      * Makefile.in: Add @DUMPING@ substitution; add pdumper mode.
      * .gitignore: Add make-fingerprint, temacs.in, fingerprint.c,
      dmpstruct.h, and pdumper dump files.
  3. 01 Jan, 2019 1 commit
  4. 17 Dec, 2018 1 commit
    • Paul Eggert's avatar
      Assume ‘emacs’ is defined in Emacs-only code · 4d77c4ac
      Paul Eggert authored
      * src/charset.c, src/coding.c, src/coding.h, src/gmalloc.c:
      * src/ralloc.c, src/regex-emacs.c: Simplify slightly by
      assuming that ‘emacs’ is defined.  These modules have long
      been specific to Emacs, and are not used elsewhere.
  5. 01 Jan, 2018 1 commit
  6. 12 Dec, 2017 2 commits
    • Paul Eggert's avatar
      Narrow pointer bounds when appropriate · 4295050e
      Paul Eggert authored
      This typically occurs in a storage manager, where the caller
      is expected to access only the newly-allocated object,
      instead of using the returned value to access unrelated
      parts of the heap.
      * src/alloc.c (allocate_string, allocate_string_data)
      (compact_small_strings, find_string_data_in_pure)
      (sweep_strings, setup_on_free_list, allocate_vectorlike
      * src/bytecode.c (exec_byte_code):
      * src/callint.c (Fcall_interactively):
      * src/dispnew.c (scrolling):
      * src/editfns.c (styled_format):
      * src/frame.c (xrdb_get_resource, x_get_resource_string):
      * src/fringe.c (Fdefine_fringe_bitmap):
      * src/gmalloc.c (malloc, realloc, aligned_alloc):
      Narrow pointer bounds when appropriate.
      * src/alloc.c (SDATA_OF_STRING):
      * src/lisp.h (make_lisp_symbol) [__CHKP__]:
      Widen bounds here, though.
      * src/bytecode.c, src/callint.c, src/dispnew.c, src/editfns.c:
      * src/emacs.c, src/frame.c, src/fringe.c:
      Include ptr-bounds.h.
      * src/ptr-bounds.h (ptr_bounds_clip): New function.
    • Paul Eggert's avatar
      Port to gcc -fcheck-pointer-bounds · 881abfc7
      Paul Eggert authored
      This is a minimal port, just to get Emacs running;
      it does not attempt to make the pointer bounds at all tight.
      * src/ptr-bounds.h: New file.
      * src/alloc.c, src/gmalloc.c: Include it.
      * src/alloc.c (live_string_holding, live_cons_holding)
      (live_symbol_holding, live_misc_holding, garbage_collect_1)
      (sweep_conses, sweep_floats):
      * src/gmalloc.c (malloc_initialize_1, _free_internal_nolock)
      Widen pointer bounds as necessary.
      We're in a memory allocator so this is OK.
      * src/lisp.h (lisp_h_XSYMBOL, make_lisp_symbol) [__CHKP__]:
      Do not convert from pointer to integer and back again, so
      that GCC does not lose track of pointer bounds.
      (XSYMBOL) [__CHKP__ && !USE_LSB_TAG]: Now a compile-time error.
      Although it's possible to support both -fcheck-pointer-bounds and
      --with-wide-int, it's more work; keep things simple for now.
      (DEFINE_LISP_SYMBOL) [__CHKP__]: Now a no-op, to avoid
      trouble with unbounded pointers.
  7. 04 Nov, 2017 1 commit
    • Noam Postavsky's avatar
      Use hybrid malloc for FreeBSD (Bug#28308) · 918a2dda
      Noam Postavsky authored
      FreeBSD aarch64 does not provide sbrk, so gmalloc cannot be used; when
      using system malloc dumping does not work correctly (allocated data is
      invalid after dumping).
      * configure.ac: Set hybrid_malloc for freebsd.
      * src/gmalloc.c (gdefault_morecore) [!HAVE_SBRK]: Don't call sbrk.
  8. 13 Sep, 2017 1 commit
    • Paul Eggert's avatar
      Prefer HTTPS to FTP and HTTP in documentation · bc511a64
      Paul Eggert authored
      Most of this change is to boilerplate commentary such as license URLs.
      This change was prompted by ftp://ftp.gnu.org's going-away party,
      planned for November.  Change these FTP URLs to https://ftp.gnu.org
      instead.  Make similar changes for URLs to other organizations moving
      away from FTP.  Also, change HTTP to HTTPS for URLs to gnu.org and
      fsf.org when this works, as this will further help defend against
      man-in-the-middle attacks (for this part I omitted the MS-DOS and
      MS-Windows sources and the test tarballs to keep the workload down).
      HTTPS is not fully working to lists.gnu.org so I left those URLs alone
      for now.
  9. 21 Jun, 2017 2 commits
    • Paul Eggert's avatar
      Remove malloc_find_address relic · b7dfd39c
      Paul Eggert authored
      * src/gmalloc.c (register_heapinfo, _malloc_internal_nolock):
      Omit unnecessary initialization.
    • Paul Eggert's avatar
      Fix temacs hybrid_malloc core dump · ac1ceadc
      Paul Eggert authored
      Without this patch, ./temacs would dump core sometimes on Fedora
      25 x86-64.  The problem was that the hybrid allocator assumed that
      all pointers into bss_sbrk_buffer are allocated via gmalloc.  This
      assumption is not true on Fedora, because the standard memory
      allocator calls gdefault_morecore, which means its blocks are
      interleaved with our blocks.  Usually the code happened to work,
      because our data structures agreed with the glibc data structures,
      but this was merely luck due to a shared pedigree, and as glibc
      mutates our luck has run out.
      Remove; no longer needed.
      (BLOCK): Use unsigned division, as that does the right thing near zero.
      (register_heapinfo, __malloc_internal_nolock, __free_internal_nolock)
      Big blocks now have type -1, not 0, as 0 now means the block is
      not ours.
      (morecore_nolock): Omit now-unnecessary casts to size_t.
      (allocated_via_gmalloc) [HYBRID_MALLOC]: New function.
      (hybrid_free, hybrid_realloc) [HYBRID_MALLOC]: Use it, to
      avoid calling the wrong free or realloc function in some cases.
  10. 01 Jan, 2017 1 commit
  11. 13 Nov, 2016 1 commit
    • Paul Eggert's avatar
      Port --enable-gcc-warnings to Ubuntu 16.10 · 9b3a853a
      Paul Eggert authored
      * src/gmalloc.c: Include <stdlib.h>, so it declares
      hybrid_aligned_alloc (the definiens of the aligned_alloc macro),
      so that GCC doesn't complain that hybrid_aligned_alloc is
      defined without being declared.
  12. 24 Oct, 2016 1 commit
    • Paul Eggert's avatar
      Port --enable-gcc-warnings to bleeding-edge glibc · 7bb5c4f2
      Paul Eggert authored
      Bleeding-edge glibc sets emacs_cv_var_doug_lea_malloc to 'no'.
      Do not merge to master.
      * configure.ac: Check for valloc decl when compiling gmalloc.c.
      * src/gmalloc.c (emacs_abort) [emacs]: Adjust decl to match
      what is in lisp.h.  Remove duplicate decl.
      (aligned_alloc): #undef before defining.
      (aligned_alloc, memalign) [!MSDOS]: Declare.
      (valloc) [HAVE_DECL_VALLOC]: Remove duplicate decl.
  13. 23 Oct, 2016 1 commit
  14. 15 Sep, 2016 1 commit
    • Paul Eggert's avatar
      Prefer now-standard int width macros · 0bbf00c7
      Paul Eggert authored
      * src/data.c (ULL_WIDTH):
      * src/lisp.h (EMACS_INT_WIDTH, BITS_PER_BITS_WORD):
      * src/lread.c (read_integer):
      * src/term.c (produce_glyphless_glyph):
      * src/xterm.c (x_send_scroll_bar_event):
      Use *_WIDTH macros instead of CHAR_BIT * sizeof.
      * src/data.c (ULL_WIDTH): Rename from BITS_PER_ULL for consistency
      with the *_WIDTH standard macros.  All uses changed.
      * src/gmalloc.c (INT_BIT): Remove.  All uses replaced with INT_WIDTH.
      * src/lisp.h (EMACS_INT_WIDTH): Rename from BITS_PER_EMACS_INT
      for consistency with the *_WIDTH standard macros.  All uses changed.
      (BITS_PER_CHAR): Remove; all uses replaced by CHAR_BIT.  This must
      be the same as CHAR_WIDTH and avoids confusion with Elisp
      char-width, which counts columns not bits.
      (BITS_PER_SHORT): Remove; all uses replaced by SHRT_WIDTH.
      (BITS_PER_LONG): Remove; all uses replaced by LONG_WIDTH.
      * src/lread.c: Do not include limits.h since CHAR_BIT is no longer
      used directly.
  15. 12 Jun, 2016 1 commit
    • Paul Eggert's avatar
      New macro GNUC_PREREQ for GCC version · ab182c62
      Paul Eggert authored
      * src/conf_post.h (GNUC_PREREQ): New macro.
      Change uses of __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ to use this
      macro instead, for clarity and consistency.
      (PRINTF_ARCHETYPE): New macro.  Define it to __gnu_printf__ only
      if glibc, since non-GNU platforms don’t necessarily support GNU
      printf formats.
  16. 09 Feb, 2016 2 commits
    • Paul Eggert's avatar
      Omit valloc decl if redundant · 812cddf3
      Paul Eggert authored
      * src/gmalloc.c (valloc): Omit decl if malloc.h is included,
      to pacify --enable-gcc-warnings.
    • Wolfgang Jenkner's avatar
      Restore the calloc family. · 09ece4d3
      Wolfgang Jenkner authored
      * src/gmalloc.c (calloc, gcalloc, hybrid_calloc): Restore definitions.
      They were lost in a4817d83 but calloc is still (marginally) used in
      code statically liked with emacs, so hybrid_calloc is needed.
      Also, in the non-hybrid case, we can't get rid of calloc anyway as
      other libraries liked with emacs may need it.
      * src/conf_post.h: Restore redefinition of calloc to hybrid_calloc.
  17. 31 Jan, 2016 1 commit
  18. 30 Jan, 2016 6 commits
    • Paul Eggert's avatar
      Fix extern symbols defined and not used · 3d82a8ee
      Paul Eggert authored
      * src/alloc.c: Always include <signal.h>.
      (malloc_warning) [!SIGDANGER && (SYSTEM_MALLOC || HYBRID_MALLOC)]:
      Do not define; unused.
      * src/emacs.c, src/lisp.h (might_dump) [!DOUG_LEA_MALLOC]: Now static.
      * src/gmalloc.c (gdefault_morecore): Rename from __default_morecore,
      to avoid collision with glibc.  Now static.  All uses changed.
      * src/lastfile.c (my_edata): Define only if
      ((!defined SYSTEM_MALLOC && !defined HYBRID_MALLOC && !defined
      WINDOWSNT) \ || defined CYGWIN || defined DARWIN_OS).
    • Paul Eggert's avatar
      Build lib/e-*.o only on platforms that need it · 7fdc3cf0
      Paul Eggert authored
      * configure.ac (hybrid malloc): Simplify configuration.
      (SHEAP_OBJ): Remove; no longer needed.
      (HYBRID_MALLOC): New var. Subst it.
      (HYBRID_MALLOC_LIB): New Automake conditional.
      * lib/Makefile.am (noinst_LIBRARIES): Add libegnu.a only if
      (libegnu_a_CPPFLAGS): Omit AM_CPPFLAGS; not needed.
      (MOSTLYCLEANFILES): Add libegnu.a.
      * src/Makefile.in (SHEAP_OBJ): Remove.
      (HYBRID_MALLOC): New macro.
      (base_obj): Use it to conditionally add sheap.o.
      (LIBEGNU_ARCHIVE): New macro.
      ($(LIBEGNU_ARCHIVE)): New rule, replacing $(lib)/libegnu.a.
      All uses of the latter replaced by the former.
      * src/alloc.c (USE_ALIGNED_ALLOC): Simplify configuration.
      Correct misspelling ALIGNED_ALLOC to HAVE_ALIGNED_ALLOC.
      * src/gmalloc.c: Update comment.
      * src/lisp.h (aligned_alloc)
      New decl.
    • Paul Eggert's avatar
      Include <malloc.h> when advisable · a4817d83
      Paul Eggert authored
      This should help insulate us better from future glibc changes.
      It is good hygiene to include .h files for APIs that Emacs uses.
      Fix type clashes between Emacs and GNU <malloc.h> (Bug#22086).
      * configure.ac: Check for malloc.h.
      * src/alloc.c: Include <malloc.h> depending on HAVE_MALLOC_H,
      not on DOUG_LEA_MALLOC.
      * src/emacs.c, src/gmalloc.c (malloc_enable_thread):
      Remove decl (now in lisp.h).
      * src/gmalloc.c: Include stddef.h earlier, for ptrdiff_t.
      [emacs]: Include lisp.h.
      [HAVE_MALLOC_H]: Include <malloc.h>.
      (__MALLOC_HOOK_VOLATILE): New macro, if not already defined.
      (__after_morecore_hook, __malloc_initialize_hook, __morecore)
      [!HAVE_MALLOC_H]: New decls near non-inclusion of <malloc.h>.
      (calloc): Make it clear that the macro should not be used.
      Remove unused decl.
      (malloc_info): New macro, to avoid clash with glibc <malloc.h>.
      (__morecore, __default_morecore, __after_morecore_hook)
      (__malloc_extra_blocks, __malloc_initialize_hook, __free_hook)
      (__malloc_hook, __realloc_hook, __memalign_hook, memory_warnings):
      Remove later decls.
      (gmalloc_hook, gfree_hook, grealloc_hook):
      Rename from __malloc_hook, __free_hook, __realloc_hook to
      avoid type collision with glibc <malloc.h>.  All uses changed.
      (__malloc_extra_blocks) [DOUG_LEA_MALLOC||HYBRID_MALLOC||SYSTEM_MALLOC]:
      Now static.
      (gmalloc_hook, __malloc_extra_blocks): Define even if [!HYBRID_MALLOC].
      (__malloc_initialize_hook, __after_morecore_hook):
      Declare with types compatible with glibc.
      (__memalign_hook, hybrid_calloc) [HYBRID_MALLOC]:
      Remove.  All uses removed.
      * src/lisp.h (__malloc_extra_blocks, malloc_enable_thread): New decls.
      * src/ralloc.c, src/vm-limit.c:
      Simplify includes and include <malloc.h> if available.
    • Paul Eggert's avatar
      Pacify --enable-gcc-warnings when HYBRID_MALLOC · e1a9f209
      Paul Eggert authored
      * src/buffer.c (init_buffer):
      * src/emacs.c (main):
      * src/xsmfns.c (smc_save_yourself_CB, x_session_initialize):
      Use emacs_get_current_dir_name, not get_current_dir_name.
      * src/conf_post.h (aligned_alloc) [HYBRID_MALLOC && emacs]: New macro.
      (HYBRID_GET_CURRENT_DIR_NAME, get_current_dir_name): Remove.
      * src/emacs.c: Include "sheap.h".
      (report_sheap_usage): Remove decl.
      (Fdump_emacs) [HYBRID_MALLOC]: Report usage directly.
      Don't assume ptrdiff_t can be printed as int.
      * src/gmalloc.c [HYBRID_MALLOC]:
      Include "sheap.h" rather than declaring its contents by hand.
      (get_current_dir_name, gget_current_dir_name)
      (hybrid_get_current_dir_name): Remove.
      (emacs_abort): Remove duplicate decl.
      (aligned_alloc): Undef, like malloc etc.
      (ALLOCATED_BEFORE_DUMPING): Now a static function, not a macro.
      Make it a bit more efficient.
      (malloc_find_object_address): Remove unused decl.
      (enum mcheck_status, mcheck, mprobe, mtrace, muntrace, struct mstats)
      (mstats, memory_warnings): Declare only if GC_MCHECK.
      * src/lisp.h (emacs_get_current_dir_name):
      New decl, replacing get_current_dir_name.
      * src/sheap.c: Include sheap.h first.
      (STATIC_HEAP_SIZE): Remove; now in sheap.h.
      (debug_sheap): Now static.
      (bss_sbrk_buffer_end): Remove; no longer used.
      (bss_sbrk_ptr): Now static and private.
      (bss_sbrk_did_unexec): Now bool.
      (BLOCKSIZE): Remove, to avoid GCC warning about its not being used.
      (bss_sbrk): Don't treat request_size 0 as special, since the code
      works without this being a special case.
      Avoid overflow if request size exceeds INT_MAX.
      (report_sheap_usage): Remove; now done in emacs.c.
      * src/sheap.h: New file.
      * src/sysdep.c (get_current_dir_name): Remove macro.
      Include "sheap.h".
      (emacs_get_current_dir_name): Rename function from
      get_current_dir_name.  Handle HYBRID_MALLOC here;
      this is simpler.
    • Wolfgang Jenkner's avatar
      Add musl patch to support HYBRID_MALLOC on elf systems · d6585a91
      Wolfgang Jenkner authored
      * src/gmalloc.c: Adjust for HYBRID_MALLOC in the non CYGWIN case.
      (__default_morecore): Here, in particular.
      * configure.ac: Define HYBRID_MALLOC when unexelf.o is used.
      New variable SHEAP_OBJ.
      * src/Makefile.in: Use it.
    • Wolfgang Jenkner's avatar
      Internal linkage for gmalloc etc. if HYBRID_MALLOC · cb22fce2
      Wolfgang Jenkner authored
      This avoids clashes with symbols if the after-dump malloc is
      derived from Doug Lea's implementation (Bug#22086).
      * src/gmalloc.c (emacs_abort, __morecore, __default_morecore):
      Move declarations up.  For HYBRID_MALLOC, turn all `extern'
      declarations below to `static' ones.
      (aligned_alloc): Declare for !MSDOS as well.
      (heapsize, _fraghead): Move resp. copy declaration downwards.
      For HYBRID_MALLOC, conditionalize out the other definitions,
      since the previous `static' declarations double as tentative
      definitions, anyway.
      (_malloc, _free, _realloc, __free_hook, _aligned_blocks)
      (__realloc_hook, __memalign_hook): Conditionalize out.
      (cfree, memalign, valloc): Ditto.
  19. 01 Jan, 2016 1 commit
  20. 26 Dec, 2015 1 commit
    • Wolfgang Jenkner's avatar
      Always define gmalloc etc. in src/gmalloc.c · 4b1436b7
      Wolfgang Jenkner authored
      This is a work-around to prevent the compiler from using semantic
      knowledge about malloc for optimization purposes.  E.g., gcc 5.2
      with -O2 replaces most of calloc's definition by a call to calloc;
      see Bug#22085.
      * src/gmalloc.c [!HYBRID_MALLOC] (malloc, realloc, calloc)
      (aligned_alloc, free): Do not undef.  Instead, define these as
      functions (perhaps renamed to gmalloc etc.) in terms of gmalloc etc.
  21. 01 Jan, 2015 2 commits
  22. 03 Oct, 2014 1 commit
    • Dmitry Antipov's avatar
      Consistently use min and max macros from lisp.h. · 6846b003
      Dmitry Antipov authored
      * coding.c (min, max):
      * font.c (MAX):
      * unexhp9k800.c (min):
      * unexw32.c (min, max): Use definitions from lisp.h.
      * regex.c (MAX, MIN) [!emacs]: Define own max and min as such.
      Adjust users.
      * gmalloc.c (min): Tiny style change.
  23. 28 Sep, 2014 1 commit
  24. 27 Sep, 2014 1 commit
    • Ken Brown's avatar
      Fix implementation of HYBRID_MALLOC on Cygwin. · 6c300919
      Ken Brown authored
      * src/sheap.c (bss_sbrk_buffer_end): Cast to void *.
      (bss_sbrk_buffer_beg): New variable.  Use it...
      * src/gmalloc.c (ALLOCATED_BEFORE_DUMPING) [CYGWIN]: ...here, to fix
        incorrect definition.
  25. 31 Aug, 2014 1 commit
  26. 28 Aug, 2014 1 commit
    • Ken Brown's avatar
      Add support for HYBRID_MALLOC, allowing the use of gmalloc before · ea652500
      Ken Brown authored
      dumping and the system malloc after dumping.  (Bug#18222)
      * configure.ac (HYBRID_MALLOC): New macro; define to use gmalloc
      before dumping and the system malloc after dumping.  Define on Cygwin.
      * src/conf_post.h (malloc, realloc, calloc, free) [HYBRID_MALLOC]:
      Define as macros, expanding to hybrid_malloc, etc.
      (get_current_dir_name) [HYBRID_GET_CURRENT_DIR_NAME]: Define as
      * src/gmalloc.c: Set up the infrastructure for HYBRID_MALLOC, with a
      full implementation on Cygwin.  Remove Cygwin-specific code that
      is no longer needed.
      (malloc, realloc, calloc, free, aligned_alloc) [HYBRID_MALLOC]:
      Redefine as macros expanding to gmalloc, grealloc, etc.
      (get_current_dir_name) [HYBRID_GET_CURRENT_DIR_NAME]: Undefine.
      (USE_PTHREAD, posix_memalign) [HYBRID_MALLOC]: Don't define.
      (hybrid_malloc, hybrid_calloc, hybrid_free, hybrid_realloc)
      (hybrid_get_current_dir_name) [HYBRID_GET_CURRENT_DIR_NAME]:
      (hybrid_aligned_alloc) [HYBRID_MALLOC && (HAVE_ALIGNED_ALLOC ||
      HAVE_POSIX_MEMALIGN)]: New functions.
      * src/alloc.c (aligned_alloc) [HYBRID_MALLOC && (ALIGNED_ALLOC ||
      HAVE_POSIX_MEMALIGN)]: Define as macro expanding to
      hybrid_aligned_alloc; declare.
      HAVE_POSIX_MEMALIGN)]: Define.
      (refill_memory_reserve) [HYBRID_MALLOC]: Do nothing.
      * src/sysdep.c (get_current_dir_name) [HYBRID_GET_CURRENT_DIR_NAME]:
      Define as macro, expanding to gget_current_dir_name, and define
      the latter.
      * src/emacs.c (main) [HYBRID_MALLOC]: Don't call memory_warnings() or
      malloc_enable_thread().  Don't initialize malloc.
      * src/lisp.h (NONPOINTER_BITS) [CYGWIN]: Define (because GNU_MALLOC is
      no longer defined on Cygwin).
      (refill_memory_reserve) [HYBRID_MALLOC]: Don't declare.
      * src/sheap.c (bss_sbrk_buffer_end): New variable.
      * src/unexcw.c (__malloc_initialized): Remove variable.
      * src/ralloc.c: Throughout, treat HYBRID_MALLOC the same as
      * src/xdisp.c (decode_mode_spec) [HYBRID_MALLOC]: Don't check
  27. 11 Aug, 2014 1 commit
  28. 22 May, 2014 1 commit
    • Paul Eggert's avatar
      Supply malloc and alloc_size attributes for extern allocators. · 74fde0f4
      Paul Eggert authored
      This documents the C API, and helps GCC generate a bit better code.
      (ATTRIBUTE_MALLOC_SIZE): New macros.
      * gmalloc.c (malloc, realloc, calloc):
      * gtkutil.h (malloc_widget_value):
      * lisp.h (ralloc, r_re_alloc, xmalloc, xzalloc, xrealloc, xnmalloc)
      (xnrealloc, xstrdup, xlispstrdup, record_xmalloc):
      Use them.
  29. 04 Mar, 2014 2 commits
  30. 03 Mar, 2014 1 commit
    • Eli Zaretskii's avatar
      Fix crashes in lisp_align_free in a build with GC_MCHECK. · bd650c24
      Eli Zaretskii authored
       src/gmalloc.c (aligned_alloc): Fix adjustment of size of the
       allocated buffer due to alignment.
       (freehook): If the block to be freed was allocated by
       'aligned_alloc', find its real pointer before calling 'free'.
       (mabort) [emacs]: Call 'emacs_abort', not 'abort', to provide a
      Fixes: debbugs:16901