1. 18 Jan, 2019 1 commit
    • Eli Zaretskii's avatar
      Clean up memory allocation and unexec support on MS-Windows · 5e3b0f52
      Eli Zaretskii authored
      * src/w32heap.c (report_temacs_memory_usage): Condition on
      !CANNOT_DUMP, in addition to ENABLE_CHECKING.
      (init_heap): Accept an argument, which tells us what heap
      allocation method to use.
      (DUMPED_HEAP_SIZE) [CANNOT_DUMP]: Define to a small value, as
      we don't use dumped_data[] in this case.
      * src/w32heap.h (init_heap): Adjust prototype.
      <using_dynamic_heap>: Remove declaration.
      * src/emacs.c (main) [WINDOWSNT]: Determine heap allocation
      method based on whether we are in temacs and whether unexec
      will be used to dump Emacs.  Pass the heap allocation method
      to init_heap, which is now called after parsing the
      --temacs=METHOD option.
      * src/unexw32.c (unexec): Don't fiddle with using_dynamic_heap.
      <using_dynamic_heap>: Remove definition.
      * src/w32proc.c (malloc_before_init, realloc_before_init)
      (free_before_init): New functions, to catch memory allocation
      before heap allocation method is set up.
      5e3b0f52
  2. 16 Jan, 2019 2 commits
    • Andy Moreton's avatar
      Avoid compilation warnings in MS-Windows build · 8bf51c38
      Andy Moreton authored
      * src/pdumper.c (dump_cold_bignum):
      * src/emacs.c(load_pdump) [WINDOWSNT]: Avoid compiler warnings
      due to 64-bit vs 32-bit data type mismatches.
      8bf51c38
    • Eli Zaretskii's avatar
      Improve documentation of pdumper; minor code cleanup · ebd174e2
      Eli Zaretskii authored
      * src/emacs.c (usage_message): Add the --dump-file option.
      (string_starts_with_p, find_argument): Functions removed; use
      'argmatch' instead.
      (PDUMP_FILE_ARG): Macro removed; use literal strings instead,
      as with other command-line options.  Use HAVE_PDUMPER for cpp
      conditionals which used PDUMP_FILE_ARG.
      (load_pdump, main): Use 'argmatch' for "--dump-file" and
      "--temacs" arguments, thus supporting the "-dump-file" and
      "-temacs" variants, for consistency with other options.
      (main): Remove the extra fatal error for using --dump-file in
      unexec'ed Emacs: load_pdump does that anyway.
      (standard_args): Add --dump-file and --temacs, with
      appropriate priorities.
      
      * etc/NEWS: Expand on the pdumper support.
      
      * doc/emacs/cmdargs.texi (Initial Options): Document the
      '--dump-file' command-line option.
      ebd174e2
  3. 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
      gnutls_global_initialized.
      * 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
      functions.
      (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_KEY, HASH_VALUE, HASH_HASH, HASH_TABLE_SIZE): const-ify.
      (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
      vectorlike_nbytes.
      (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
      re_match_object.
      * 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
      variable.
      
      * 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
      pdumper
      (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
      !initialized.
      
      * 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
      marking
      (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
      Lisp_Vector.
      (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
      posix_madvise.
      
      * Makefile.in: Add @DUMPING@ substitution; add pdumper mode.
      
      * .gitignore: Add make-fingerprint, temacs.in, fingerprint.c,
      dmpstruct.h, and pdumper dump files.
      d12e5d00
  4. 01 Jan, 2019 1 commit
  5. 07 Dec, 2018 1 commit
    • Eli Zaretskii's avatar
      Fix the value of default-directory upon startup on MS-Windows · e4a8f6eb
      Eli Zaretskii authored
      * src/w32.c (w32_get_current_directory): New function.
      (GetCachedVolumeInformation, init_environment): Use it.
      (w32_init_current_directory): New function.
      * src/w32.h (w32_init_current_directory): Add prototype.
      * src/emacs.c (main) [WINDOWSNT]: Use w32_init_current_directory
      to get the accurate value of cwd.  This is needed to record
      the correct directory in emacs_wd, which is now initialized
      way earlier in the startup process, when init_environment was
      not yet called.  For details, see the problems reported in
      http://lists.gnu.org/archive/html/emacs-devel/2018-12/msg00068.html.
      Reported by Angelo Graziosi <angelo.g0@libero.it>.
      e4a8f6eb
  6. 13 Nov, 2018 1 commit
    • Paul Eggert's avatar
      Act like POSIX sh if $HOME is relative · 90027650
      Paul Eggert authored
      POSIX says sh ~/foo should act like $HOME/foo even if $HOME is
      relative, so be consistent with that (Bug#33255).
      * admin/merge-gnulib (GNULIB_MODULES): Add dosname.
      * src/buffer.c (init_buffer): Use emacs_wd to get
      initial working directory with slash appended if needed.
      (default-directory): Say it must be absolute.
      * src/emacs.c (emacs_wd): New global variable.
      (init_cmdargs): Dir arg is now char const *.
      (main): Set emacs_wd.
      * src/emacs.c (main) [NS_IMPL_COCOA]:
      * src/fileio.c (Fexpand_file_name):
      Use get_homedir instead of egetenv ("HOME").
      * src/fileio.c: Include dosname.h, for IS_ABSOLUTE_FILE_NAME.
      (splice_dir_file, get_homedir): New functions.
      * src/xrdb.c (gethomedir): Remove.  All callers changed
      to use get_homedir and splice_dir_file.
      * test/src/fileio-tests.el (fileio-tests--relative-HOME): New test.
      90027650
  7. 12 Nov, 2018 2 commits
    • Glenn Morris's avatar
      Avoid kill-emacs-hook errors hanging batch mode · b8bbbe54
      Glenn Morris authored
      * src/emacs.c (Fkill_emacs): Prevent errors from kill-emacs-hook
      hanging Emacs in batch mode.  (Bug#29955)
      
      (cherry picked from commit 109da684)
      b8bbbe54
    • Paul Eggert's avatar
      Fix dumping on GNU/Linux ppc64le · c14eab22
      Paul Eggert authored
      Problem reported by Thomas Fitzsimmons (Bug#33174).
      * src/emacs.c (main): Adjust to sysdep.c changes.
      * src/sysdep.c (exec_personality): New static var.
      (disable_address_randomization): Remove, replacing with ...
      (maybe_disable_address_randomization): ... this new function.
      Do not set or use an environment variable; use a command-line
      argument instead, and set the new static var.  Migrate the emacs.c
      personality-change code to here, where it belongs.
      (emacs_exec_file): Simplify by using new static var.
      c14eab22
  8. 07 Oct, 2018 1 commit
    • Paul Eggert's avatar
      Move timestamp-related stuff to timefns.c · b5d08da1
      Paul Eggert authored
      This does not change behavior; it’s just long-overdue
      refactoring (Bug#32902).
      * src/emacs.c (main): Call init_timefns, syms_of_timefns.
      * src/timefns.c: New file, containing timestamp-related stuff
      from editfns.c and sysdep.c.
      * src/Makefile.in (base_obj): Add timefns.o.
      * src/editfns.c: Simplify by moving a big chunk to timefns.c.
      Do not include systime.h, sys/resource.h, sys/param.h,
      strftime.h, coding.h.
      (HAVE_TZALLOC_BUG, TM_YEAR_BASE, HAVE_TM_GMTOFF, tzeqlen)
      (local_tz, utc_tz, emacs_localtime_rz, emacs_mktime_z)
      (invalid_time_zone_specification, xtzfree, tzlookup)
      (TIME_T_MIN, TIME_T_MAX, time_overflow, invalid_time)
      (check_time_validity, hi_time, lo_time, Fcurrent_time)
      (time_add, time_subtract, time_arith, Ftime_add)
      (Ftime_subtract, Ftime_less_p, Fget_internal_run_time)
      (make_lisp_time, disassemble_lisp_time, decode_float_time)
      (lisp_to_timespec, lisp_time_struct, lisp_time_argument)
      (lisp_seconds_argument, Ffloat_time, emacs_nmemftime)
      (Fformat_time_string, format_time_string, Fdecode_time)
      (check_tm_member, Fencode_time, Fcurrent_time_string)
      (tm_gmtoff, Fcurrent_time_zone, Fset_time_zone_rule)
      (emacs_getenv_TZ, emacs_setenv_TZ): Move to timefns.c.
      * src/emacs.c (main): Adjust to initialization changes.
      * src/sysdep.c: Include <sys/resource.h> if it's present.
      Regularize includes a bit.
      (Fget_internal_run_time): Move here from editfns.c.
      (init_timefns, syms_of_timefns): New functions.
      * src/w32.h (w32_get_internal_run_time): Move decl here
      so that it need not be cloned.
      * test/src/editfns-tests.el:
      * test/src/editfns-tests.el (format-time-string-with-zone)
      (format-time-string-with-outlandish-zone)
      (editfns-tests--have-leap-seconds)
      (format-time-string-with-bignum-on-32-bit):
      Move to ...
      * test/src/timefns-tests.el: ... this new file.
      b5d08da1
  9. 04 Oct, 2018 1 commit
  10. 03 Oct, 2018 1 commit
  11. 04 Sep, 2018 2 commits
    • Paul Eggert's avatar
      Fix bignum initialization · 1d84e652
      Paul Eggert authored
      Problem reported by Andy Moreton in:
      https://lists.gnu.org/r/emacs-devel/2018-09/msg00072.html
      and crystal-ball diagnosis by Eli Zaretskii in:
      https://lists.gnu.org/r/emacs-devel/2018-09/msg00075.html
      * src/alloc.c (xrealloc_for_gmp, xfree_for_gmp): Move to bignum.c.
      (init_alloc): Move bignum initialization to init_bignum.
      * src/bignum.c (init_bignum): Rename from init_bignum_once.
      All users changed.
      * src/emacs.c (main): Call init_bignum after init_alloc,
      instead of calling init_bignum_once after init_bignum.
      1d84e652
    • Paul Eggert's avatar
      Speed up (+ 2 2) by a factor of 10 · fe042e9d
      Paul Eggert authored
      Improve arithmetic performance by avoiding bignums until needed.
      Also, simplify bignum memory management, fixing some unlikely leaks.
      This patch improved the performance of (+ 2 2) by a factor of ten
      on a simple microbenchmark computing (+ x 2), byte-compiled,
      with x a local variable initialized to 2 via means the byte
      compiler could not predict: performance improved from 135 to 13 ns.
      The platform was Fedora 28 x86-64, AMD Phenom II X4 910e.
      Performance also improved 0.6% on ‘make compile-always’.
      * src/bignum.c (init_bignum_once): New function.
      * src/emacs.c (main): Use it.
      * src/bignum.c (mpz): New global var.
      (make_integer_mpz): Rename from make_integer.  All uses changed.
      * src/bignum.c (double_to_bignum, make_bignum_bits)
      (make_bignum, make_bigint, make_biguint, make_integer_mpz):
      * src/data.c (bignum_arith_driver, Frem, Flogcount, Fash)
      (expt_integer, Fadd1, Fsub1, Flognot):
      * src/floatfns.c (Fabs, rounding_driver, rounddiv_q):
      * src/fns.c (Fnthcdr):
      Use mpz rather than mpz_initting and mpz_clearing private
      temporaries.
      * src/bignum.h (bignum_integer): New function.
      * src/data.c (Frem, Fmod, Fash, expt_integer):
      * src/floatfns.c (rounding_driver):
      Use it to simplify code.
      * src/data.c (FIXNUMS_FIT_IN_LONG, free_mpz_value):
      Remove.  All uses removed.
      (floating_point_op): New function.
      (floatop_arith_driver): New function, with much of the guts
      of the old float_arith_driver.
      (float_arith_driver): Use it.
      (floatop_arith_driver, arith_driver):
      Simplify by assuming NARGS is at least 2.
      All callers changed.
      (float_arith_driver):
      New arg, containing the partly converted value of the next arg.
      Reorder args for consistency.  All uses changed.
      (bignum_arith_driver): New function.
      (arith_driver): Use it.  Do fixnum-only integer calculations
      in intmax_t instead of mpz_t, when they fit.
      Break out mpz_t calculations into bignum_arith_driver.
      (Fquo): Use floatop_arith_driver instead of float_arith_driver,
      since the op is known to be valid.
      (Flogcount, Fash): Simplify by coalescing bignum and fixnum code.
      (Fadd1, Fsub1): Simplify by using make_int.
      fe042e9d
  12. 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
  13. 24 Aug, 2018 1 commit
    • Glenn Morris's avatar
      Update GNOME bugtracker URLs · 624e7dc7
      Glenn Morris authored
      * configure.ac, admin/notes/multi-tty, etc/PROBLEMS:
      * src/emacs.c (main):
      * src/xterm.c (x_connection_closed): Update GNOME bugtracker URLs.
      ; * src/gtkutil.c (xg_display_close):
      ; * src/image.c (svg_load_image): Update URLs in comments.
      624e7dc7
  14. 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
  15. 17 Aug, 2018 1 commit
    • Paul Eggert's avatar
      Reject outlandishly-wide bignums · 3b9017b5
      Paul Eggert authored
      Do not allow bignums that are so wide that their log base 2
      might not fit into a fixnum, as this will cause problems elsewhere.
      We already have a similar limitation for bool-vectors.
      * src/emacs.c (check_bignum_size, xmalloc_for_gmp): New function.
      (xrealloc_for_gmp): Check for too-large bignum.
      (main): Use xmalloc_for_gmp.
      3b9017b5
  16. 08 Aug, 2018 1 commit
    • 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/syntax.c, src/syntax.h, src/sysdep.c, src/term.c,
      src/termhooks.h, src/textprop.c, src/undo.c, src/w32.c,
      src/w32console.c, src/w32fns.c, src/w32font.c, src/w32inevt.c,
      src/w32proc.c, src/w32select.c, src/w32term.c, src/w32term.h,
      src/w32uniscribe.c, src/window.c, src/xdisp.c, src/xfaces.c,
      src/xfns.c, src/xfont.c, src/xftfont.c, src/xmenu.c, src/xml.c,
      src/xrdb.c, src/xselect.c, src/xsettings.c, src/xterm.c, src/xwidget.c
      Rename XINT->XFIXNUM, XFASTINT->XFIXNAT, XUINT->XUFIXNUM.
      d1ec3a0a
  17. 06 Aug, 2018 1 commit
    • Paul Eggert's avatar
      Rename src/regex.c to src/regex-emacs.c. · e5652268
      Paul Eggert authored
      This is in preparation for using Gnulib regex for etags,
      to avoid collisions in include directives.
      * src/regex-emacs.c: Rename from src/regex.c.
      * src/regex-emacs.h: Rename from src/regex.h.  All uses changed.
      * test/src/regex-emacs-tests.el: Rename from test/src/regex-tests.el.
      e5652268
  18. 26 Jul, 2018 1 commit
    • Lucas Werkmeister's avatar
      Notify systemd in daemon-initialized and kill-emacs (Bug#31498) · 19f5f7b1
      Lucas Werkmeister authored
      With --[bg-]daemon and Type=forking, systemd will only consider the
      daemon to have fully started up once the original process exits, and
      will wait until then to start units depending on the Emacs service.  To
      get the same functionality with --fg-daemon, use Type=notify instead of
      Type=simple and explicitly send a readiness notification to systemd at
      the point where the forked process would in --bg-daemon mode notify its
      parent process and cause it to exit.  Similarly, notify systemd at the
      beginning of the shutdown process as well.  (Both of these calls are
      successful no-ops if emacs was not started by systemd.)
      * etc/emacs.service: Update Type.
      * src/emacs.c (daemon-initialized) [HAVE_LIBSYSTEMD]:
      * src/emacs.c (kill-emacs) [HAVE_LIBSYSTEMD]: Call sd_notify().
      19f5f7b1
  19. 13 Jul, 2018 2 commits
    • 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
  20. 08 Jul, 2018 1 commit
  21. 26 May, 2018 1 commit
  22. 04 Apr, 2018 1 commit
    • Paul Eggert's avatar
      Pacify GCC when --enable-profiling · 9b0e8a4c
      Paul Eggert authored
      * src/conf_post.h (PROFILING): Undef if not on a platform that
      supports it.  Simplify uses accordingly.
      * src/emacs.c (etext) [PROFILING]:
      Declare at top level to avoid GCC warning.
      9b0e8a4c
  23. 12 Feb, 2018 2 commits
    • Paul Eggert's avatar
      Minor cleanups for server-name fix (Bug#24218) · d43a724f
      Paul Eggert authored
      * lisp/server.el (server--external-socket-initialized): Rename
      from server-external-socket-initialised, since it should be
      private and Emacs uses American spelling.  All uses changed.
      * src/emacs.c, src/lisp.h: Revert previous changes, as the
      initialization is now done in src/process.c, which already
      includes the relevant files.
      * src/process.c (union u_sockaddr): Move decl to top level.
      (external_sock_name, Fget_external_sockname): Remove, replacing
      with Vinternal__external_sockname.  All uses changed.
      (init_process_emacs): Deduce socket name ourselves rather than
      have main.c do it.  Use conv_sockaddr_to_lisp instead of doing
      it by hand.  Conditionalize it on HAVE_GETSOCKNAME.
      d43a724f
    • Matthew Leach's avatar
      Fix `server-name' and `server-socket-dir' for (Bug#24218) · e1ca0ea8
      Matthew Leach authored
      * lisp/server.el: (server-external-socket-initialised): New
      (server-name): Compute server name from `get-external-sockname'.
      (server-socket-dir): Compute socket dir from
      `get-external-sockname'.
      (server-start): Don't check for existing server when an
      uninitialised external socket has been passed to Emacs.
      * src/emacs.c: (main): Obtain socket name via getsockname and pass
      to `init_process_emacs'.
      * src/lisp.h: (init_process_emacs): Add second parameter.
      * src/process.c: (external_sock_name): New.
      (get-external-sockname): New.
      (init_process_emacs): Set `external_sock_name' to `sockname'
      parameter.
      e1ca0ea8
  24. 24 Jan, 2018 1 commit
  25. 13 Jan, 2018 1 commit
    • Ken Brown's avatar
      Add battery support to all Cygwin builds · 5af5df1f
      Ken Brown authored
      It already exists in the Cygwin-w32 build.
      * src/w32fns.c (Fw32_battery_status): Move to...
      * src/w32cygwinx: New file, to be used for functions common to
      the MS Windows and Cygwin builds.
      (syms_of_w32cygwinx): New function.
      * src/lisp.h: Add prototype of syms_of_w32cygwinx.
      * src/emacs.c (main) [HAVE_NTGUI or CYGWIN]: Call syms_of_w32cygwinx.
      * src/Makefile.in (SOME_MACHINE_OBJECTS):
      * configure.ac (W32_OBJ) [HAVE_W32]: Add w32cygwinx.o.
      (W32_LIBS) [CYGWIN]: Set equal to "-lkernel32" in non-w32 build.
      (W32_OBJ) [CYGWIN]: Set equal to "w32cygwinx.o" in non-w32 build.
      * etc/NEWS: Document the new battery support.
      5af5df1f
  26. 01 Jan, 2018 1 commit
  27. 12 Dec, 2017 1 commit
    • 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
      (pure_alloc):
      * 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.
      4295050e
  28. 10 Dec, 2017 2 commits
    • Eli Zaretskii's avatar
      Support dynamic loading of libjansson on MS-Windows · 2b8a1b76
      Eli Zaretskii authored
      * src/json.c [WINDOWSNT]: Define fn_* function pointers to jansson
      functions.
      (json_delete) [WINDOWSNT]: A wrapper around fn_json_delete, needed
      by json_decref.
      (init_json_functions) [WINDOWSNT]: New function.
      (Fjson_serialize, Fjson_insert, Fjson_parse_string)
      (Fjson_parse_buffer) [WINDOWSNT]: Call init_json_functions if
      needed, and record JSON in Vlibrary_cache.
      * src/emacs.c (main): Don't call init_json on WINDOWSNT.
      * src/w32fns.c (syms_of_w32fns): DEFSYM "json".
      
      * lisp/term/w32-win.el (dynamic-library-alist): Add JSON DLL to
      the list.
      
      * configure.ac (HAVE_JSON): Empty JSON_LIBS for MinGW.
      
      * nt/INSTALL.W64:
      * nt/INSTALL: Add information about libjansson.
      2b8a1b76
    • Philipp Stephani's avatar
      Implement native JSON support using Jansson · ab203e36
      Philipp Stephani authored
      * configure.ac: New option --with-json.
      
      * src/json.c (Fjson_serialize, Fjson_insert, Fjson_parse_string)
      (Fjson_parse_buffer): New defuns.
      (json_malloc, json_free, json_has_prefix, json_has_suffix)
      (json_make_string, json_build_string, json_encode)
      (json_out_of_memory, json_parse_error)
      (json_release_object, check_string_without_embedded_nulls, json_check)
      (lisp_to_json, lisp_to_json_toplevel, lisp_to_json_toplevel_1)
      (json_insert, json_insert_callback, json_to_lisp)
      (json_read_buffer_callback, Fjson_parse_buffer, define_error): New
      helper functions.
      (init_json, syms_of_json): New file.
      
      * src/lisp.h: Declaration for init_json and syms_of_json.
      
      * src/emacs.c (main): Enable JSON functions.
      
      * src/eval.c (internal_catch_all, internal_catch_all_1): New helper
      functions to catch all signals.
      (syms_of_eval): Add uninterned symbol to signify out of memory.
      
      * src/Makefile.in (JSON_LIBS, JSON_CFLAGS, JSON_OBJ, EMACS_CFLAGS)
      (base_obj, LIBES): Compile json.c if --with-json is enabled.
      
      * test/src/json-tests.el (json-serialize/roundtrip)
      (json-serialize/object, json-parse-string/object)
      (json-parse-string/string, json-serialize/string)
      (json-parse-string/incomplete, json-parse-string/trailing)
      (json-parse-buffer/incomplete, json-parse-buffer/trailing): New unit
      tests.
      
      * doc/lispref/text.texi (Parsing JSON): New manual section.
      ab203e36
  29. 03 Nov, 2017 1 commit
    • Robert Pluim's avatar
      New function 'libxml-available-p' · 620247ac
      Robert Pluim authored
      * src/emacs.c (main): Call syms_of_xml unconditionally.
      * src/lisp.h: Provide syms_of_xml prototype even when
      HAVE_LIBXML2 is not defined.
      * src/xml.c (Flibxml_available_p): New function, cloned from
      Fgnutls_available_p.
      (syms_of_xml): Provide Slibxml_available_p.
      
      * doc/lispref/text.texi (Parsing HTML/XML): Document libxml-available-p.
      (GnuTLS Cryptography, Format of GnuTLS Cryptography Inputs)
      (Document Object Model): Fix indentation of the first paragraph.
      
      * etc/NEWS (libxml-available-p): Mention libxml-available-p.
      620247ac
  30. 19 Sep, 2017 1 commit
  31. 18 Sep, 2017 2 commits
    • Philipp Stephani's avatar
      Revert "Implement native JSON support using Jansson" · 0925a20e
      Philipp Stephani authored
      This reverts commit cb99cf5a.
      0925a20e
    • Philipp Stephani's avatar
      Implement native JSON support using Jansson · cb99cf5a
      Philipp Stephani authored
      * configure.ac: New option --with-json.
      
      * src/json.c (Fjson_serialize, Fjson_insert, Fjson_parse_string)
      (Fjson_parse_buffer): New defuns.
      (json_out_of_memory, json_parse_error, json_release_object)
      (check_string_without_embedded_nulls, json_check, lisp_to_json)
      (json_insert, json_insert_callback, json_to_lisp)
      (json_read_buffer_callback, Fjson_parse_buffer, define_error): New
      helper function.
      (syms_of_json): New file.
      
      * src/lisp.h: Declaration for syms_of_json.
      
      * src/emacs.c (main): Enable JSON functions.
      
      * src/Makefile.in (JSON_LIBS, JSON_CFLAGS, JSON_OBJ, EMACS_CFLAGS)
      (base_obj, LIBES): Compile json.c if --with-json is enabled.
      
      * test/src/json-tests.el (json-serialize/roundtrip)
      (json-serialize/object, json-parse-string/object): New unit tests.
      cb99cf5a
  32. 13 Sep, 2017 2 commits
    • 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.
      bc511a64
    • Mark Oteiza's avatar
      Add lcms2 interface · 5d4c539b
      Mark Oteiza authored
      configure.ac: Add boilerplate for configuring and detecting liblcms2.
      etc/NEWS: Mention new configure option and color-distance change.
      src/Makefile.in: Add references to lcms.c and liblcms.
      src/emacs.c: Define lcms2 symbols.
      src/lcms.c: New file.
      src/lisp.h: Add declaration for lcms2.
      src/xfaces.c: Add optional METRIC argument.
      5d4c539b