1. 28 Aug, 2018 1 commit
    • Paul Eggert's avatar
      Modularize bignums better · 9abaf5f3
      Paul Eggert authored
      * src/bignum.c, src/bignum.h: New files.  Only modules that
      need to know how bignums are implemented should include
      bignum.h.  Currently these are alloc.c, bignum.c (of course),
      data.c, emacs.c, emacs-module.c, floatfns.c, fns.c, print.c.
      * src/Makefile.in (base_obj): Add bignum.o.
      * src/alloc.c (make_bignum_str): Move to bignum.c.
      (make_number): Remove; replaced by bignum.c’s make_integer.
      All callers changed.
      * src/conf_post.h (ARG_NONNULL): New macro.
      * src/json.c (json_to_lisp): Use it.
      * src/data.c (Fnatnump):
      Move NATNUMP’s implementation here from lisp.h.
      * src/data.c (Fnumber_to_string):
      * src/editfns.c (styled_format):
      Move conversion of string to bignum to bignum_to_string, and
      call it here.
      * src/emacs-module.c (module_make_integer):
      * src/floatfns.c (Fabs):
      Simplify by using make_int.
      * src/emacs.c: Include bignum.h, to expand its inline fns.
      * src/floatfns.c (Ffloat): Simplify by using XFLOATINT.
      (rounding_driver): Simplify by using double_to_bignum.
      (rounddiv_q): Clarify use of temporaries.
      * src/lisp.h: Move decls that need to know bignum internals to
      bignum.h.  Do not include gmp.h or mini-gmp.h; that is now
      bignum.h’s job.
      (GMP_NUM_BITS, struct Lisp_Bignum, XBIGNUM, mpz_set_intmax):
      Move to bignum.h.
      (make_int): New function.
      (NATNUMP): Remove; all callers changed to use Fnatnump.
      (XFLOATINT): If arg is a bignum, use bignum_to_double, so that
      bignum internals are not exposed here.
      * src/print.c (print_vectorlike): Use SAFE_ALLOCA to avoid the
      need for a record_unwind_protect_ptr.
      9abaf5f3
  2. 26 Aug, 2018 1 commit
    • Eli Zaretskii's avatar
      Fix a typo in alloc.c · 18d52b90
      Eli Zaretskii authored
      * src/alloc.c (Fmemory_use_counts): The list we return now has
      only 7 elements, not 8.  (Bug#32531)
      18d52b90
  3. 23 Aug, 2018 1 commit
    • Paul Eggert's avatar
      Fix bugs when rounding to bignums · ee641b87
      Paul Eggert authored
      Also, since Emacs historically reported a range error when
      rounding operations overflowed, do that consistently for all
      bignum overflows.
      * doc/lispref/errors.texi (Standard Errors):
      * doc/lispref/numbers.texi (Integer Basics): Document range errors.
      * src/alloc.c (range_error): Rename from integer_overflow.
      All uses changed.
      * src/floatfns.c (rounding_driver): When the result of a floating
      point rounding operation does not fit into a fixnum, put it
      into a bignum instead of always signaling an range error.
      * test/src/floatfns-tests.el (divide-extreme-sign):
      These tests now return the mathematically-correct answer
      instead of signaling an error.
      (bignum-round): Check that integers round to themselves.
      ee641b87
  4. 21 Aug, 2018 1 commit
    • Paul Eggert's avatar
      Avoid libgmp aborts by imposing limits · d6a497dd
      Paul Eggert authored
      libgmp calls ‘abort’ when given numbers too big for its
      internal data structures.  The numeric limit is large and
      platform-dependent; with 64-bit GMP 6.1.2 it is around
      2**2**37.  Work around the problem by refusing to call libgmp
      functions with arguments that would cause an abort.  With luck
      libgmp will have a better way to do this in the future.
      Also, introduce a variable integer-width that lets the user
      control how large bignums can be.  This currently defaults
      to 2**16, i.e., it allows bignums up to 2**2**16.  This
      should be enough for ordinary computation, and should
      help Emacs to avoid thrashing or hanging.
      Problem noted by Pip Cet (Bug#32463#71).
      * doc/lispref/numbers.texi, etc/NEWS:
      Document recent bignum changes, including this one.
      Improve documentation for bitwise operations, in the light
      of bignums.
      * src/alloc.c (make_number): Enforce integer-width.
      (integer_overflow): New function.
      (xrealloc_for_gmp, xfree_for_gmp):
      Move here from emacs.c, as it's memory allocation.
      (init_alloc): Initialize GMP here, rather than in emacs.c.
      (integer_width): New var.
      * src/data.c (GMP_NLIMBS_MAX, NLIMBS_LIMIT): New constants.
      (emacs_mpz_size, emacs_mpz_mul)
      (emacs_mpz_mul_2exp, emacs_mpz_pow_ui): New functions.
      (arith_driver, Fash, expt_integer): Use them.
      (expt_integer): New function, containing integer code
      that was out of place in floatfns.c.
      (check_bignum_size, xmalloc_for_gmp): Remove.
      * src/emacs.c (main): Do not initialize GMP here.
      * src/floatfns.c (Fexpt): Use expt_integer, which
      now contains integer code moved from here.
      * src/lisp.h (GMP_NUMB_BITS): Define if gmp.h doesn’t.
      d6a497dd
  5. 19 Aug, 2018 2 commits
    • Paul Eggert's avatar
      Minor fixups for intmax_t→mpz_t conversion · b1840206
      Paul Eggert authored
      * src/alloc.c (mpz_set_intmax_slow): Tighten assertion.
      Work even in the unlikely case where libgmp uses nails.
      * src/data.c (FIXNUMS_FIT_IN_LONG): New constant.
      (arith_driver): Use it to tighten compile-time checks.
      * src/lisp.h (mpz_set_intmax): Do not assume that converting
      an out-of-range value to ‘long’ is harmless, as it might raise
      a signal.  Use simpler expression; compiler can optimize.
      b1840206
    • Paul Eggert's avatar
      Improve --with-wide-int mpz_t→fixnum conversion · 6eade1ef
      Paul Eggert authored
      These tuneups and minor simplifications should affect only
      platforms with EMACS_INT wider than ‘long’.
      * src/alloc.c (make_number): If the number fits in long but
      not in fixnum, do not attempt to convert to fixnum again.
      Tighten the compile-time check for whether the second attempt
      is worth trying, from sizeof (long) < sizeof (EMACS_INT) to
      LONG_WIDTH < FIXNUM_BITS.  Do not bother computing the sign of
      the value to tighten the bounds for whether to try the second
      attempt, as it’s not worth the effort.  Do not call mpz_size,
      which is unnecessary since the number of bits is already known
      and the loop can iterate over a shift count instead.  Avoid
      unnecessary casts.  Use + instead of | where either will do,
      as + is typically better for optimization.
      
      Improve mpz_t to fixnum when --with-wide-int
      * src/alloc.c (make_number): Avoid undefined behavior
      when shifting an EMACS_UINT by more than EMACS_UINT_WIDTH bits.
      Check for integer overflow when shifting.
      6eade1ef
  6. 17 Aug, 2018 1 commit
    • Paul Eggert's avatar
      Fix problems with logxor etc. and fixnums · 64eb9b71
      Paul Eggert authored
      These operations incorrectly treated negative fixnums as
      bignums greater than most-positive-fixnum.
      * src/alloc.c (mpz_set_intmax_slow): Avoid undefined
      behavior if signed unary negation overflows, while
      we’re in the neighborhood.
      (mpz_set_uintmax_slow): Remove.  All uses removed.
      * src/data.c (arith_driver): Treat fixnums as signed, not
      unsigned, even for logical operations.
      * src/lisp.h (mpz_set_uintmax): Remove.  All uses removed.
      * test/src/data-tests.el (data-tests-logand)
      (data-tests-logior, data-tests-logxor): New tests.
      64eb9b71
  7. 14 Aug, 2018 1 commit
    • Paul Eggert's avatar
      Remove more traces of misc (Bug#32405) · 11c7c2f7
      Paul Eggert authored
      Remove misc-objects-consed and the misc component of
      memory-use-count, since misc objects no longer exist.
      * doc/lispref/internals.texi, etc/NEWS: Mention this,
      and adjust better to recent removal of misc objects.
      * src/alloc.c (MEM_TYPE_MISC): Remove; no longer used.
      (Fmemory_use_counts): Omit misc count, since miscs
      no longer exist.
      (misc-objects-consed): Remove.
      11c7c2f7
  8. 12 Aug, 2018 2 commits
    • Paul Eggert's avatar
      Simplify mark_object for pseudovectors · 6c12f4e6
      Paul Eggert authored
      Suggested by Pip Cet (Bug#32405#14).
      * src/alloc.c (mark_object): Remove unnecessary special cases for
      PVEC_MARKER, PVEC_BOOL_VECTOR, PVEC_MISC_PTR, PVEC_USER_PTR, and
      PVEC_FINALIZER.
      
      change is to free up an enum Lisp_Type tag value, a scarce
      6c12f4e6
    • Paul Eggert's avatar
      Turn misc objects into pseudovectors · d614e4a8
      Paul Eggert authored
      Eliminate the category of miscellaneous objects, and turn all
      such objects into pseudovectors.  The immediate motivation
      for this change is to free up an enum Lisp_Type tag value, a
      scarce resource that can be better used elsewhere.  However,
      this change is worthwhile in its own right, as it improves
      performance slightly on my platform, 0.3% faster for 'make
      compile-always' on Fedora 28, and it simplifies the garbage
      collector and interpreter (Bug#32405).
      * doc/lispref/internals.texi (Garbage Collection):
      * etc/NEWS:
      Document change to garbage-collect return value.
      * src/alloc.c (total_markers, total_free_markers):
      (union aligned_Lisp_Misc, MARKER_BLOCK_SIZE)
      (struct marker_block, marker_block, marker_block_index)
      (misc_free_list, allocate_misc, live_misc_holding)
      (live_misc_p, sweep_misc):
      * src/lisp.h (lisp_h_MARKERP, lisp_h_MISCP, MARKERP, MISCP)
      (Lisp_Misc, enum Lisp_Misc_Type, Lisp_Misc_Free)
      (Lisp_Misc_Marker, Lisp_Misc_Overlay, Lisp_Misc_Finalizer)
      (Lisp_Misc_Ptr, Lisp_Misc_User_Ptr, Lisp_Misc_Limit)
      (Lisp_Misc_Bignum)
      (XSETMISC, struct Lisp_Misc_Any, XMISCANY, XMISCTYPE)
      (struct Lisp_Free, union Lisp_Misc, XMISC):
      Remove.  All uses removed.
      (cleanup_vector): Clean up objects that were formerly misc
      and are now pseudovectors.
      (make_misc_ptr, build_overlay, Fmake_marker, build_marker)
      (make_bignum_str, make_number, make_pure_bignum)
      (make_user_ptr, Fmake_finalizer):
      Build as pseudovectors, not as misc objects.
      (mark_finalizer_list, queue_doomed_finalizers)
      (compact_undo_list, mark_overlay, mark_object)
      (unchain_dead_markers):
      Mark as vector-like objects, not as misc objects.
      (mark_maybe_object, mark_maybe_pointer, valid_lisp_object_p)
      (total_bytes_of_live_objects, survives_gc_p):
      * src/fns.c (sxhash):
      No need to worry about misc objects.
      (garbage_collect_1): Do not generate a 'misc' component.
      (syms_of_alloc): No need for 'misc' symbol.
      * src/buffer.c (overlays_at, overlays_in, overlay_touches_p)
      (overlay_strings, recenter_overlay_lists)
      (fix_start_end_in_overlays, fix_overlays_before)
      (Foverlay_lists, report_overlay_modification)
      (evaporate_overlays):
      * src/editfns.c (overlays_around):
      * src/data.c (Ftype_of):
      * src/fns.c (internal_equal):
      * src/lisp.h (mint_ptrp, xmint_pointer, FINALIZERP)
      (XFINALIZER, MARKERP, XMARKER, OVERLAYP, XOVERLAY, USER_PTRP)
      (XUSER_PTR, BIGNUMP, XBIGNUM):
      * src/print.c (print_vectorlike, print_object):
      * src/undo.c (record_marker_adjustments):
      * src/xdisp.c (load_overlay_strings):
      Formerly misc objects are now pseudovectors.
      * src/lisp.h (PVEC_MARKER, PVEC_OVERLAY, PVEC_FINALIZER)
      (PVEC_BIGNUM, PVEC_MISC_PTR, PVEC_USER_PTR):
      New constants, replacing their misc versions.  All uses changed.
      (struct Lisp_Marker, struct Lisp_Overlay, struct Lisp_Misc_Ptr)
      (struct Lisp_Bignum, struct Lisp_User_Ptr, struct Lisp_Finalizer):
      Make usable as a pseudovector by using a pseudovector header,
      replacing any DIY components, and putting Lisp_Object members
      first.  All uses changed.
      d614e4a8
  9. 11 Aug, 2018 1 commit
  10. 09 Aug, 2018 2 commits
    • Andy Moreton's avatar
      Do not use GMP_NUMB_BITS · f9667537
      Andy Moreton authored
      * src/alloc.c (make_number): Use mp_bits_per_limb, not GMP_NUMB_BITS.
      f9667537
    • Paul Eggert's avatar
      Minor pseudovector allocation cleanups · 63a8f4cf
      Paul Eggert authored
      * src/alloc.c (VECTOR_BLOCK_SIZE, VECTOR_BLOCK_BYTES)
      (VBLOCK_BYTES_MIN, VBLOCK_BYTES_MAX, VECTOR_MAX_FREE_LIST_INDEX):
      Prefer enums to macros where either will do.
      (allocate_vector_from_block): Arg is ptrdiff_t, not size_t.
      Use eassume instead of eassert.
      (PSEUDOVEC_STRUCT): New macro, which verifies the already-existing
      assumption that the vector-like objects are small.
      (cleanup_vector): Use it.  Use if-then-else systematically;
      this lets GCC do a bit better job.
      
      2018-08-08  Paul Eggert  <eggert@cs.ucla.edu>
      
      * src/alloc.c (VBLOCK_BYTES_MAX): Use vroundup_ct, not
      vroundup, so that can be used in static assertions.
      63a8f4cf
  11. 08 Aug, 2018 3 commits
    • Tom Tromey's avatar
      Use mpz_import in mpz_set_uintmax_slow · d3549c19
      Tom Tromey authored
      * src/alloc.c (mpz_set_uintmax_slow): Use mpz_import.
      d3549c19
    • Tom Tromey's avatar
      Make purecopy work for bignums · fb26c9fd
      Tom Tromey authored
      * src/alloc.c (make_pure_bignum): New function.
      (purecopy): Use it.
      fb26c9fd
    • Tom Tromey's avatar
      More macro renamings for bignum · d1ec3a0a
      Tom Tromey authored
      * src/alloc.c, src/bidi.c, src/buffer.c, src/buffer.h, src/bytecode.c,
      src/callint.c, src/callproc.c, src/casefiddle.c, src/casetab.c,
      src/category.c, src/ccl.c, src/character.c, src/character.h,
      src/charset.c, src/charset.h, src/chartab.c, src/cmds.c, src/coding.c,
      src/composite.c, src/composite.h, src/data.c, src/dbusbind.c,
      src/decompress.c, src/dired.c, src/dispextern.h, src/dispnew.c,
      src/disptab.h, src/doc.c, src/dosfns.c, src/editfns.c,
      src/emacs-module.c, src/emacs.c, src/eval.c, src/fileio.c,
      src/floatfns.c, src/fns.c, src/font.c, src/font.h, src/fontset.c,
      src/frame.c, src/frame.h, src/fringe.c, src/ftcrfont.c, src/ftfont.c,
      src/gfilenotify.c, src/gnutls.c, src/gtkutil.c, src/image.c,
      src/indent.c, src/insdel.c, src/intervals.c, src/json.c,
      src/keyboard.c, src/keymap.c, src/kqueue.c, src/lcms.c, src/lisp.h,
      src/lread.c, src/macros.c, src/marker.c, src/menu.c, src/minibuf.c,
      src/msdos.c, src/print.c, src/process.c, src/profiler.c, src/search.c,
      src/sound.c, src/syn...
      d1ec3a0a
  12. 04 Aug, 2018 1 commit
    • Andy Moreton's avatar
      Make bignums work better when EMACS_INT is larger than long · bc8ff54e
      Andy Moreton authored
      * lisp/international/ccl.el (ccl-fixnum): New function.
      (ccl-embed-data, ccl-embed-current-address, ccl-dump): Use it.
      * src/alloc.c (make_number): Handle case where EMACS_INT is
      larger than long.
      * src/data.c (bignumcompare): Handle case where EMACS_INT is
      larger than long.
      (arith_driver): Likewise.  Coerce markers.
      (float_arith_driver): Coerce markers.
      (Flogcount): Use mpz_sgn.
      (ash_lsh_impl): Fix bugs.
      (Fsub1): Fix underflow check.
      * src/lisp.h (NUMBERP): Don't check BIGNUMP.
      (CHECK_FIXNUM_OR_FLOAT_COERCE_MARKER): Fix indentation.
      * test/lisp/international/ccl-tests.el: New file.
      bc8ff54e
  13. 20 Jul, 2018 1 commit
    • Paul Eggert's avatar
      Prefer NILP (x) to EQ (x, Qnil) · fb24ce37
      Paul Eggert authored
      This simplifies the code a bit, and also simplifies some
      potential future changes slightly (e.g., altering eq vs eql).
      * src/alloc.c (mark_object):
      * src/callint.c (fix_command):
      * src/chartab.c (Fchar_table_range, Fset_char_table_range):
      * src/dbusbind.c (XD_OBJECT_TO_DBUS_TYPE, xd_signature):
      * src/dired.c (Fsystem_users):
      * src/fileio.c (Fdo_auto_save):
      * src/fns.c (concat):
      * src/frame.c (get_frame_param, frame_inhibit_resize)
      (store_in_alist, store_frame_param, x_set_autoraise)
      (x_set_autolower, x_get_arg):
      * src/image.c (Fclear_image_cache):
      * src/intervals.c (intervals_equal):
      * src/intervals.h (DEFAULT_INTERVAL_P):
      * src/lread.c (substitute_object_recurse):
      * src/menu.c (digest_single_submenu)
      (find_and_call_menu_selection)
      (find_and_return_menu_selection):
      * src/nsfns.m (x_set_icon_name, Fx_create_frame):
      * src/nsmenu.m (ns_menu_show):
      * src/nsselect.m (ns_string_to_pasteboard_internal)
      (Fns_selection_exists_p, Fns_selection_owner_p):
      * src/process.c (Faccept_process_output)
      (wait_reading_process_output):
      * src/terminal.c (store_terminal_param):
      * src/textprop.c (verify_interval_modification):
      * src/xdisp.c (next_element_from_buffer):
      * src/xfaces.c (Finternal_set_lisp_face_attribute):
      * src/xfns.c (x_set_icon_type, Fx_synchronize):
      * src/xmenu.c (x_menu_show):
      * src/xselect.c (Fx_selection_owner_p)
      (Fx_selection_exists_p):
      * src/xwidget.c (xwidget_view_lookup):
      Prefer NILP (x) to EQ (x, Qnil).
      fb24ce37
  14. 19 Jul, 2018 1 commit
    • Tom Tromey's avatar
      Fix bignum creation when EMACS_INT is wider than long · 76715f89
      Tom Tromey authored
      * src/alloc.c (mpz_set_intmax_slow, mpz_set_uintmax_slow): New
      functions.
      * src/data.c (arith_driver, Frem, Fmod, ash_lsh_impl, Fadd1)
      (Fsub1): Use mpz_set_intmax, mpz_set_uintmax.
      * src/emacs-module.c (module_make_integer): Use mpz_set_intmax.
      * src/floatfns.c (Fabs): Use mpz_set_intmax.
      * src/lisp.h (mpz_set_intmax, mpz_set_uintmax): New inline
      functions.
      (mpz_set_uintmax_slow, mpz_set_intmax_slow): Declare.
      76715f89
  15. 13 Jul, 2018 3 commits
    • Tom Tromey's avatar
      Provide new functions to create bignums · b2f3f4ee
      Tom Tromey authored
      * src/alloc.c (make_bignum_str, make_number): New functions.
      * src/lisp.h (make_bignum_str, make_number): Declare.
      b2f3f4ee
    • Tom Tromey's avatar
      Introduce the bignum type · a0f2adbf
      Tom Tromey authored
      * src/alloc.c (mark_object): Handle Lisp_Misc_Bignum.
      (sweep_misc): Call mpz_clear for Lisp_Misc_Bignum.
      * src/data.c (Ftype_of): Handle Lisp_Misc_Bignum.
      (Fintegerp, Finteger_or_marker_p, Fnatnump, Fnumberp)
      (Fnumber_or_marker_p): Update for bignum.
      (Ffixnump, Fbignump): New defuns.
      (syms_of_data): Update.
      * src/emacs.c (xrealloc_for_gmp, xfree_for_gmp): New functions.
      (main): Call mp_set_memory_functions.
      * src/lisp.h (enum Lisp_Misc_Type) <Lisp_Misc_Bignum>: New constant.
      (struct Lisp_Bignum): New.
      (union Lisp_Misc): Add u_bignum.
      (BIGNUMP, XBIGNUM, INTEGERP, NATNUMP, NUMBERP, CHECK_NUMBER)
      (CHECK_INTEGER, CHECK_NUMBER_COERCE_MARKER): New functions.
      * src/print.c (print_object): Handle Lisp_Misc_Bignum.
      a0f2adbf
    • Tom Tromey's avatar
      Rename integerp->fixnum, etc, in preparation for bignums · 42fe787b
      Tom Tromey authored
      * src/json.c, src/keyboard.c, src/keyboard.h, src/keymap.c,
      src/kqueue.c, src/lcms.c, src/lisp.h, src/lread.c, src/macros.c,
      src/marker.c, src/menu.c, src/minibuf.c, src/msdos.c, src/print.c,
      src/process.c, src/profiler.c, src/search.c, src/sound.c,
      src/syntax.c, src/sysdep.c, src/term.c, src/terminal.c,
      src/textprop.c, src/undo.c, src/w16select.c, src/w32.c,
      src/w32console.c, src/w32cygwinx.c, src/w32fns.c, src/w32font.c,
      src/w32inevt.c, src/w32proc.c, src/w32select.c, src/w32term.c,
      src/w32uniscribe.c, src/widget.c, src/window.c, src/xdisp.c,
      src/xfaces.c, src/xfns.c, src/xfont.c, src/xftfont.c, src/xmenu.c,
      src/xrdb.c, src/xselect.c, src/xterm.c, src/xwidget.c: Rename
      INTEGERP->FIXNUM, make_number->make_fixnum, CHECK_NUMBER->CHECK_FIXNUM,
      make_natnum->make_fixed_natum, NUMBERP->FIXED_OR_FLOATP,
      NATNUMP->FIXNATP, CHECK_NATNUM->CHECK_FIXNAT.
      42fe787b
  16. 30 Jun, 2018 1 commit
    • Paul Eggert's avatar
      unbind_to performance tuning · 2e281186
      Paul Eggert authored
      * src/alloc.c (which_symbols):
      * src/dispnew.c (Fredisplay):
      * src/editfns.c (Fsubst_char_in_region):
      * src/fileio.c (Fdo_auto_save):
      * src/indent.c (Fvertical_motion):
      * src/keymap.c (Fcurrent_active_maps):
      * src/lread.c (Feval_buffer):
      * src/minibuf.c (get_minibuffer):
      * src/sysdep.c (system_process_attributes):
      * src/textprop.c (Fnext_single_char_property_change)
      (Fprevious_single_char_property_change):
      * src/window.c (Fscroll_other_window, Fscroll_other_window_down):
      * src/xdisp.c (Fformat_mode_line):
      Help the compiler eliminate tail recursion in call to unbind_to.
      * src/coding.c (decode_coding_gap):
      Omit unnecessary unbind_to, as we’re about to call unbind_to anyway.
      * src/coding.c (Fread_coding_system):
      * src/eval.c (eval_sub):
      * src/xdisp.c (handle_single_display_spec, decode_mode_spec):
      * src/xselect.c (x_get_local_selection):
      Avoid need to save a machine register when calling unbind_to.
      * src/minibuf.c (Ftry_completion, Fall_completions):
      Omit unnecessary assignment.
      2e281186
  17. 16 Jun, 2018 1 commit
    • Paul Eggert's avatar
      Rewrite memory-limit in Lisp · ec1b4d9a
      Paul Eggert authored
      Have it return Emacs virtual memory size, not the sbrk value
      which is often useless newadays.
      * doc/lispref/internals.texi (Garbage Collection):
      * etc/NEWS: Document this.
      * lisp/subr.el (memory-limit): New implementation in Lisp,
      written in terms of process-attributes, and which returns
      virtual memory size.
      * src/alloc.c (Fmemory_limit): Remove C implementation.
      ec1b4d9a
  18. 15 Jun, 2018 4 commits
    • Paul Eggert's avatar
      Minor CANNOT_DUMP cleanups · b8b960e5
      Paul Eggert authored
      Mostly, this avoids munging executables when CANNOT_DUMP = yes,
      as the munging is needed only for unexec.
      * configure.ac (PAXCTL_dumped, PAXCTL_notdumped) [CANNOT_DUMP]:
      Leave these empty.
      (LD_SWITCH_SYSTEM_TEMACS) [CANNOT_DUMP]:
      Do not append -no-pie or -nopie.
      * src/alloc.c (my_heap_start) [CANNOT_DUMP]: Omit; not used.
      b8b960e5
    • Paul Eggert's avatar
      Remove Lisp_Misc_Save_Value · 4139c98e
      Paul Eggert authored
      This type and its associated routines are no longer used.
      * src/alloc.c (voidfuncptr): Move here from src/lisp.h.
      (free_misc, make_save_int_int_int)
      (make_save_obj_obj_obj_obj, make_save_ptr)
      (make_save_ptr_int, make_save_ptr_ptr)
      (make_save_funcptr_ptr_obj, make_save_memory)
      (free_save_value, mark_save_value):
      Remove.
      (mark_object): Remove mention of Lisp_Misc_Save_Value.
      * src/lisp.h (Lisp_Misc_Save_Value, SAVE_SLOT_BITS)
      (SAVE_VALUE_SLOTS, SAVE_TYPE_BITS, enum Lisp_Save_Type)
      (struct Lisp_Save_Value, SAVE_VALUEP, XSAVE_VALUE)
      (save_type, XSAVE_POINTER, set_save_pointer)
      (XSAVE_FUNCPOINTER, XSAVE_INTEGER, set_save_integer)
      (XSAVE_OBJECT): Remove.
      (union Lisp_Misc): Remove u_save_value.
      (voidfuncptr): Move from here to src/alloc.c.
      * src/print.c (print_object):
      Remove support for printing Lisp_Misc_Save_Value.
      4139c98e
    • Paul Eggert's avatar
      New type Lisp_Misc_Ptr · f8ad6b31
      Paul Eggert authored
      This is a streamlined version of Lisp_Save_Value, which contains just
      a pointer, as that is all Lisp_Save_Values are used for any more.
      With the previous changes, these objects are not primarily used as
      save values, so just call them "Misc" rather than "Save".
      * src/alloc.c (make_misc_ptr): New function.
      (mark_object): Mark Lisp_Misc_Ptr too.
      * src/lisp.h (Lisp_Misc_Ptr): New constant.
      (struct Lisp_Misc_Ptr): New type.
      (make_mint_ptr, mint_ptrp, xmint_pointer):
      Use Lisp_Misc_Ptr, not Lisp_Save_Value.
      (union Lisp_Misc): Add Lisp_Misc_Ptr.
      * src/print.c (print_object): Print Lisp_Misc_Ptr.
      f8ad6b31
    • Paul Eggert's avatar
      Avoid allocating Lisp_Save_Value for arrays · d98670eb
      Paul Eggert authored
      * src/alloc.c (mark_maybe_objects): New function.
      * src/eval.c (default_toplevel_binding)
      (backtrace_eval_unrewind, Fbacktrace__locals):
      Treat array unwindings like other miscellaneous pdl types.
      (record_unwind_protect_array): New function.
      (do_one_unbind): Free the array while unwinding.
      (mark_specpdl): Mark arrays directly.
      * src/lisp.h (SPECPDL_UNWIND_ARRAY): New constant.
      (union specbinding): New member unwind_array.
      (SAFE_ALLOCA_LISP_EXTRA): Use record_unwind_protect_array
      instead of make_save_memory + record_unwind_protect.
      d98670eb
  19. 13 Jun, 2018 1 commit
    • Paul Eggert's avatar
      Remove some wrong 8-byte alignment assumptions · 967d2c55
      Paul Eggert authored
      Do not assume that 8-byte alignment suffices for all C objects,
      as some platforms require 16-byte alignment for some objects,
      and this will start to bite us as time goes on (e.g., if an
      Emacs module ever uses an object containing a long
      double, which requires 16-byte alignment on x86-64).
      Conversely, on !USE_LSB_TAG platforms, do not insist on
      aligning Lisp objects to a multiple of 8, as this is not
      needed for high-order tag bits.
      * src/alloc.c (LISP_ALIGNMENT, MALLOC_IS_LISP_ALIGNED):
      New constants.
      (XMALLOC_BASE_ALIGNMENT, XMALLOC_HEADER_ALIGNMENT):
      Removed.  All uses replaced by LISP_ALIGNMENT.
      (aligned_alloc, laligned, lmalloc, lrealloc, union aligned_Lisp_Misc)
      (maybe_lisp_pointer, pure_alloc):
      Use LISP_ALIGNMENT rather than GCALIGNMENT.
      (aligned_alloc): Do not worry about an alignment of
      LISP_ALIGNMENT when MALLOC_IS_LISP_ALIGNED, as the code never
      uses aligned_alloc with alignment == LISP_ALIGNMENT in that case.
      (__alignof__): Remove.  All uses removed.
      (MALLOC_IS_GC_ALIGNED): Remove.
      All uses replaced with MALLOC_IS_LISP_ALIGNED.
      (vector_alignment): Remove.
      All uses replaced with LISP_ALIGNMENT.
      * src/alloc.c (mark_maybe_pointer):
      * src/emacs-module.c (value_to_lisp_bits):
      Do not assume GCALIGNMENT == 1 << GCTYPEBITS, as GCALIGNMENT
      is 1 on !USE_LSB_TAG platforms now.
      * src/lisp.h (GCALIGNMENT) [!USE_LSB_TAG]: Now 1.
      (struct Lisp_Symbol, union vectorlike_header, struct Lisp_Cons)
      (struct Lisp_String): Simplify test for verifying alignment.
      967d2c55
  20. 10 Jun, 2018 1 commit
    • Paul Eggert's avatar
      Use native alignment to access Lisp object data · 0303fab3
      Paul Eggert authored
      Instead of using __builtin_assume_aligned (P, GCALIGNMENT) to
      tell GCC that P has alignment 8, use (T *) P where T is the
      type of the pointed-to object, to tell GCC that P has native
      alignment.  This is simpler, matches the intent better, and
      should help simplify future improvements.  Some of these
      changes are to pacify gcc -Wnull-dereference, since GCC is
      smarter about pointers now that Emacs no longer uses
      __builtin_assume_aligned; these minor changes should improve
      code efficiency slightly.  On Fedora 28 x86-64 with default
      optimization this patch shrinks the size of the Emacs text
      segment by 0.36%.
      * src/conf_post.h (__has_builtin, __builtin_assume_aligned):
      Remove; no longer used.
      * src/dbusbind.c (XD_OBJECT_TO_DBUS_TYPE):
      Pacify -Wnull-dereference by using XCAR instead of CAR_SAFE
      and XCDR instead of CDR_SAFE when this is safe.
      * src/fileio.c (Fexpand_file_name):
      * src/font.c (clear_font_cache):
      Pacify -Wnull-dereference by removing unnecessary NILP test.
      * src/keyboard.c (xevent_start): New function.
      (read_char, read_key_sequence): Pacify -Wnull-dereference by
      using xevent_start instead of EVENT_START.
      * src/lisp.h (lisp_h_XUNTAG): Remove; XUNTAG is always a macro
      now, since it can no longer be implemented as a function.
      (XUNTAG): New third argument CTYPE.  All uses changed.
      Cast result to CTYPE * instead of using __builtin_assume_aligned.
      Simplify by using LISP_WORD_TAG.
      (LISP_WORD_TAG): New macro.
      (TAG_PTR): Use it.
      * src/menu.c (x_popup_menu_1):
      Pacify -Wnull-dereference by using XCAR instead of Fcar and
      XCDR instead of Fcdr where this is safe.
      0303fab3
  21. 09 Jun, 2018 1 commit
  22. 03 Jun, 2018 2 commits
    • Stefan Monnier's avatar
      Fix bug#30846, along with misc cleanups found along the way · ed962f2b
      Stefan Monnier authored
      * test/src/data-tests.el (data-tests-kill-all-local-variables): New test.
      
      * src/buffer.c (swap_out_buffer_local_variables): Remove.
      Fuse the body of its loop into that of reset_buffer_local_variables.
      (Fkill_buffer, Fkill_all_local_variables): Don't call it any more.
      (reset_buffer_local_variables): Make sure the buffer's local binding
      is swapped out before removing it from the alist (bug#30846).
      Call watchers before actually killing the var.
      
      * src/data.c (Fmake_local_variable): Simplify.
      Use swap_in_global_binding to swap out any local binding, instead of
      a mix of find_symbol_value followed by messing with where&found.
      Don't call swap_in_symval_forwarding since the currently swapped
      binding is never one we've modified.
      (Fkill_local_variable): Use swap_in_global_binding rather than messing
      with where&found to try and trick find_symbol_value into doing the same.
      
      * src/alloc.c (mark_localized_symbol): 'where' can't be a frame any more.
      
      (cherry picked from commit 3ddff080)
      ed962f2b
    • Noam Postavsky's avatar
      Fix another case of freed markers in the undo-list (Bug#30931) · daa60233
      Noam Postavsky authored
      * src/alloc.c (free_marker): Remove.
      * src/editfns.c (save_restriction_restore):
      * src/insdel.c (signal_before_change): Detach the markers from the
      buffer when we're done with them instead of calling free_marker on
      them.
      * test/src/editfns-tests.el (delete-region-undo-markers-1)
      (delete-region-undo-markers-2): New tests.
      
      (cherry picked from commit 96b8747d)
      daa60233
  23. 22 May, 2018 1 commit
  24. 18 May, 2018 2 commits
    • Paul Eggert's avatar
      * src/alloc.c: Fix comment. · 593c367b
      Paul Eggert authored
      593c367b
    • Paul Eggert's avatar
      Port to GCC 8 -fsanitize=undefined · a1c925fd
      Paul Eggert authored
      In GCC 8, gcc -fsanitize=undefined flags the undefined behavior
      that Emacs relies on in its XPNTR and XSYMBOL low-level functions.
      Disable undefined sanitization in these functions.  Although this
      disabling doesn’t suffice if DEFINE_KEY_OPS_AS_MACROS is true, it
      works for -fsanitize=undefined -DINLINING=0, which is good enough.
      * src/alloc.c (macro_PNTR_ADD): New macro.
      (PNTR_ADD): New function and macro.
      The function disables -fsanitize=undefined.
      (macro_XPNTR): Use it.
      * src/conf_post.h (ATTRIBUTE_NO_SANITIZE_UNDEFINED): New macro.
      * src/lisp.h (XSYMBOL): Disable -fsanitize=undefined.
      a1c925fd
  25. 18 Apr, 2018 1 commit
  26. 30 Mar, 2018 1 commit
    • Noam Postavsky's avatar
      Fix another case of freed markers in the undo-list (Bug#30931) · 96b8747d
      Noam Postavsky authored
      * src/alloc.c (free_marker): Remove.
      * src/editfns.c (save_restriction_restore):
      * src/insdel.c (signal_before_change): Detach the markers from the
      buffer when we're done with them instead of calling free_marker on
      them.
      * test/src/editfns-tests.el (delete-region-undo-markers-1)
      (delete-region-undo-markers-2): New tests.
      96b8747d
  27. 23 Mar, 2018 2 commits
    • Stefan Monnier's avatar
      Fix bug#30846, along with misc cleanups found along the way · 3ddff080
      Stefan Monnier authored
      * test/src/data-tests.el (data-tests-kill-all-local-variables): New test.
      
      * src/buffer.c (swap_out_buffer_local_variables): Remove.
      Fuse the body of its loop into that of reset_buffer_local_variables.
      (Fkill_buffer, Fkill_all_local_variables): Don't call it any more.
      (reset_buffer_local_variables): Make sure the buffer's local binding
      is swapped out before removing it from the alist (bug#30846).
      Call watchers before actually killing the var.
      
      * src/data.c (Fmake_local_variable): Simplify.
      Use swap_in_global_binding to swap out any local binding, instead of
      a mix of find_symbol_value followed by messing with where&found.
      Don't call swap_in_symval_forwarding since the currently swapped
      binding is never one we've modified.
      (Fkill_local_variable): Use swap_in_global_binding rather than messing
      with where&found to try and trick find_symbol_value into doing the same.
      
      * src/alloc.c (mark_localized_symbol): 'where' can't be a frame any more.
      3ddff080
    • Stefan Monnier's avatar
      * src/alloc.c: Avoid O(N²) complexity when unchaining markers (bug#24548). · cf316452
      Stefan Monnier authored
      Unchain all dead markers with a single scan of the markers list,
      instead of calling the O(N) 'unchain_marker' N times.
      
      (unchain_dead_markers): New function.
      (sweep_buffers): Use it.
      (gc_sweep): Sweep buffers before markers.
      (sweep_misc): Check that markers have been unchained when reclaiming them.
      cf316452