1. 01 Jan, 2019 1 commit
  2. 01 May, 2018 1 commit
    • Paul Eggert's avatar
      Port --enable-gcc-warnings to GCC 8 · 65ac2778
      Paul Eggert authored
      Backport from master.
      * lib-src/emacsclient.c (fail):
      Do not dereference a null pointer.
      * src/frame.c (delete_frame):
      Add a decl with UNINIT to work around GCC bug 85563.
      * src/menu.h (finish_menu_items):
      Do not use attribute const.
      * src/regex.c (analyze_first): Use FALLTHROUGH, not a comment.
      65ac2778
  3. 16 Feb, 2018 1 commit
  4. 01 Jan, 2018 1 commit
  5. 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.
      bc511a64
  6. 30 Jul, 2017 1 commit
  7. 06 Jul, 2017 1 commit
    • Paul Eggert's avatar
      Convert hex digits more systematically · d6662694
      Paul Eggert authored
      This makes the code a bit smaller and presumably faster, as
      it substitutes a single lookup for conditional jumps.
      * src/character.c (hexdigit): New constant.
      (syms_of_character) [HEXDIGIT_IS_CONST]: Initialize it.
      * src/character.h (HEXDIGIT_CONST, HEXDIGIT_IS_CONST): New macros.
      (hexdigit): New decl.
      (char_hexdigit): New inline function.
      * src/charset.c: Do not include c-ctype.h.
      * src/charset.c (read_hex):
      * src/editfns.c (styled_format):
      * src/image.c (xbm_scan):
      * src/lread.c (read_escape):
      * src/regex.c (ISXDIGIT) [emacs]:
      Use char_hexdigit insted of doing it by hand.
      d6662694
  8. 16 May, 2017 2 commits
    • Paul Eggert's avatar
      Pacify GCC 7 with --enable-gcc-warnings · c4ac34f2
      Paul Eggert authored
      * src/regex.c (regex_compile): Swap labels, so that the
      FALLTHROUGH immediately precedes the case label.
      c4ac34f2
    • Paul Eggert's avatar
      Merge with gnulib, pacifying GCC 7 · 2e1bebe2
      Paul Eggert authored
      This incorporates:
      2017-05-16 manywarnings: update for GCC 7
      2017-05-15 sys_select: Avoid "was expanded before it was required"
      * configure.ac (nw): Suppress GCC 7’s new -Wduplicated-branches and
      -Wformat-overflow=2 options, due to too many false alarms.
      * doc/misc/texinfo.tex, lib/strftime.c, m4/manywarnings.m4:
      Copy from gnulib.
      * m4/gnulib-comp.m4: Regenerate.
      * src/coding.c (decode_coding_iso_2022):
      Fix bug uncovered by -Wimplicit-fallthrough.
      * src/conf_post.h (FALLTHROUGH): New macro.
      Use it to mark all switch cases that fall through.
      * src/editfns.c (styled_format): Use !, not ~, on bool.
      * src/gtkutil.c (xg_check_special_colors):
      When using sprintf, don’t trust Gtk to output colors in [0, 1] range.
      (xg_update_scrollbar_pos): Avoid use of possibly-uninitialized bool;
      this bug was actually caught by Clang.
      * src/search.c (boyer_moore):
      Tell GCC that CHAR_BASE, if nonzero, must be a non-ASCII character.
      * src/xterm.c (x_draw_glyphless_glyph_string_foreground):
      Tell GCC that glyph->u.glyphless.ch must be a character.
      2e1bebe2
  9. 19 Feb, 2017 1 commit
  10. 01 Feb, 2017 1 commit
    • Paul Eggert's avatar
      Remove immediate_quit. · 33be5003
      Paul Eggert authored
      The old code that sets and clears immediate_quit was
      ineffective except when Emacs is running in terminal mode, and
      has problematic race conditions anyway, so remove it.  This
      will introduce some hangs when Emacs runs in terminal mode,
      and these hangs should be fixed in followup patches.
      * src/keyboard.c (immediate_quit): Remove.  All uses removed.
      33be5003
  11. 26 Jan, 2017 1 commit
    • Paul Eggert's avatar
      Replace QUIT with maybe_quit · b3a3ed52
      Paul Eggert authored
      There’s no longer need to have QUIT stand for a slug of C statements.
      Use the more-obvious function-call syntax instead.
      Also, use true and false when setting immediate_quit.
      These changes should not affect the generated machine code.
      * src/lisp.h (QUIT): Remove.  All uses replaced by maybe_quit.
      b3a3ed52
  12. 08 Jan, 2017 2 commits
    • Noam Postavsky's avatar
      Use expanded stack during regex matches · 13c6f1d1
      Noam Postavsky authored
      While the stack is increased in main(), to allow the regex stack
      allocation to use alloca we also need to modify regex.c to actually take
      advantage of the increased stack, and not limit stack allocations to
      SAFE_ALLOCA bytes.
      
      * src/regex.c (MATCH_MAY_ALLOCATE): Remove obsolete comment about
      allocations in signal handlers which no longer happens and correct
      description about when and why MATCH_MAY_ALLOCATE should be defined.
      (emacs_re_safe_alloca): New variable.
      (REGEX_USE_SAFE_ALLOCA): Use it as the limit of stack allocation instead
      of MAX_ALLOCA.
      (emacs_re_max_failures): Rename from `re_max_failures' to avoid
      confusion with glibc's `re_max_failures'.
      * src/emacs.c (main): Increase the amount of fixed 'extra' bytes we add
      to the stack.  Instead of changing emacs_re_max_failures based on the
      new stack size, just change emacs_re_safe_alloca; emacs_re_max_failures
      remains constant regardless, since if we run out stack space SAFE_ALLOCA
      will fall back to heap allocation.
      Co-authored-by: default avatarEli Zaretskii <eliz@gnu.org>
      13c6f1d1
    • Noam Postavsky's avatar
      Fix computation of regex stack limit · 9a19f26c
      Noam Postavsky authored
      The regex stack limit was being computed as the number of stack entries,
      whereas it was being compared with the current size as measured in
      bytes.  This could cause indefinite looping when nearing the stack limit
      if re_max_failures happened not to be a multiple of sizeof
      fail_stack_elt_t (Bug #24751).
      
      * src/regex.c (GROW_FAIL_STACK): Compute both current stack size and
      limit as numbers of stack entries.
      9a19f26c
  13. 06 Jan, 2017 1 commit
    • Philipp Stephani's avatar
      Add support for Unicode whitespace in [:blank:] · 512e9886
      Philipp Stephani authored
      See Bug#25366.
      
      * src/character.c (blankp): New function for checking Unicode
      horizontal whitespace.
      * src/regex.c (ISBLANK): Use 'blankp' for non-ASCII horizontal
      whitespace.
      (BIT_BLANK): New bit for range table.
      (re_wctype_to_bit, execute_charset): Use it.
      * test/lisp/subr-tests.el (subr-tests--string-match-p--blank): Add
      unit test for [:blank:] character class.
      * test/src/regex-tests.el (test): Adapt unit test.
      * doc/lispref/searching.texi (Char Classes): Document new Unicode
      behavior for [:blank:].
      512e9886
  14. 01 Jan, 2017 1 commit
  15. 10 Dec, 2016 1 commit
    • Eli Zaretskii's avatar
      Documentation and commentary improvements · 19bc4302
      Eli Zaretskii authored
      * src/lisp.h:
      * src/regex.c:
      * src/xgselect.c (xg_select): Improve commentary and formatting.
      
      * doc/lispref/objects.texi (Thread Type, Mutex Type)
      (Condition Variable Type): New subsections.
      (Type Predicates): Add thread-related predicates.
      * doc/lispref/objects.texi (Editing Types):
      * doc/lispref/elisp.texi (Top): Update higher-level menus.
      19bc4302
  16. 05 Dec, 2016 1 commit
  17. 26 Nov, 2016 1 commit
    • Paul Eggert's avatar
      Don't access pointers to freed storage in regex.c · b7f3a305
      Paul Eggert authored
      Remove __BOUNDED_POINTERS__ code, which does not work with
      -fcheck-pointer-bound and which has undefined behavior anyway.
      Problem found when trying to port to gcc -fcheck-pointer-bounds.
      (This code was removed from glibc and gnulib regex.c many years ago.)
      * src/regex.c (ELSE_EXTEND_BUFFER_HIGH_BOUND): Remove.
      (EXTEND_BUFFER): Use a more-portable approach that avoids
      undefined behavior due to inspecting pointers to freed storage.
      b7f3a305
  18. 26 Oct, 2016 1 commit
    • Noam Postavsky's avatar
      Revert fixes to allocation of regex matching · fee4cef7
      Noam Postavsky authored
      The fix was not complete, and completing it was proving too complicated.
      
      - Revert "* src/regex.c (re_search_2): Make new code safe for
                -Wjump-misses-init."
        This reverts commit c2a17924.
      - Revert "Port to GCC 6.2.1 + --enable-gcc-warnings"
        This reverts commit f6134bbd.
      - Revert "Fix handling of allocation in regex matching"
        This reverts commit ad66b3fa.
      - Revert "Fix handling of buffer relocation in regex.c functions"
        This reverts commit ee04aedc.
      fee4cef7
  19. 23 Oct, 2016 3 commits
  20. 22 Oct, 2016 1 commit
    • Noam Postavsky's avatar
      Fix handling of allocation in regex matching · ad66b3fa
      Noam Postavsky authored
      `re_match_2_internal' uses pointers to the lisp objects that it
      searches.  Since it may call malloc when growing the "fail stack", these
      pointers may be invalidated while searching, resulting in memory
      curruption (Bug #24358).
      
      To fix this, we check the pointer that the lisp object (as specified by
      re_match_object) points to before and after growing the stack, and
      update existing pointers accordingly.
      
      * src/regex.c (STR_BASE_PTR): New macro.
      (ENSURE_FAIL_STACK, re_search_2): Use it to convert pointers into
      offsets before possible malloc call, and back into pointers again
      afterwards.
      (POS_AS_IN_BUFFER): Add explanatory comment about punning trick.
      * src/search.c (search_buffer): Instead of storing search location as
      pointers, store them as pointers and recompute the corresponding address
      for each call to `re_search_2'.
      (string_match_1, fast_string_match_internal, fast_looking_at):
      * src/dired.c (directory_files_internal): Set `re_match_object' to Qnil
      after calling `re_search' or `re_match_2'.
      * src/regex.h (re_match_object): Mention new usage in commentary.
      ad66b3fa
  21. 30 Sep, 2016 1 commit
    • Paul Eggert's avatar
      Limit <config.h>’s includes · f4eb8900
      Paul Eggert authored
      This follows up on recent problems with the fact that config.h
      includes stdlib.h etc.; some files need to include stdlib.h later.
      config.h generally should limit itself to includes that are
      universally safe; outside of MS-Windows, only stdbool.h makes
      the cut among the files currently included.  So, move the
      other includes to just the files that need them (Bug#24506).
      * configure.ac (config_opsysfile): Remove, as this generic hook
      is no longer needed.
      * lib-src/etags.c, src/unexmacosx.c, src/w32.c, src/w32notify.c:
      * src/w32proc.c (_GNU_SOURCE):
      Remove, as it’s OK for config.h to do this now.
      * src/conf_post.h: Include <ms-w32.h>, instead of the generic
      config_opsysfile, for simplicity as this old way of configuring is
      now done only for the MS-Windows port.  Do not include <ms-w32.h>
      if DEFER_MS_W32_H, for the benefit of the few files that want its
      effects later.  Do not include <alloca.h>, <string.h>, or
      <stdlib.h>.  Other files modified to include these headers as
      needed, or to not include headers that are no longer needed.
      * src/lisp.h: Include <alloca.h> and <string.h> here, since
      some of the inline functions need them.
      * src/regex.c: Include <alloca.h> if not emacs.  (If emacs,
      we can rely on SAFE_ALLOCA.)  There is no longer any need to
      worry about HAVE_ALLOCA_H.
      * src/unexmacosx.c: Rely on config.h not including stdlib.h.
      * src/w32.c, src/w32notify.c, src/w32proc.c (DEFER_MS_W32_H):
      Define before including <config.h> first, and include <ms-w32.h>
      after the troublesome headers.
      f4eb8900
  22. 09 Sep, 2016 3 commits
    • Michal Nazarewicz's avatar
      Remove dead loop iterations in regex.c · 0e7eb640
      Michal Nazarewicz authored
      RE_CHAR_TO_MULTIBYTE(c) yields c for ASCII characters and a byte8
      character for c ≥ 0x80.  Furthermore, CHAR_BYTE8_P(c) is true only
      for byte8 characters.  This means that
      
      	c = RE_CHAR_TO_MULTIBYTE (ch);
      	if (! CHAR_BYTE8_P (c) && re_iswctype (c, cc))
      
      is equivalent to:
      
      	c = c;
      	if (! false && re_iswctype (c, cc))
      
      for 0 ⪬ c < 0x80, and
      
      	c = BYTE8_TO_CHAR (c);
      	if (! true && re_iswctype (c, cc))
      
      for 0x80 ⪬ c < 0x100.  In other words, the loop never executes for
      c ≥ 0x80 and RE_CHAR_TO_MULTIBYTE call is unnecessary for c < 0x80.
      
      * src/regex.c (regex_compile): Simplyfy a for loop by eliminating
      dead iterations and unnecessary macro calls.
      0e7eb640
    • Michal Nazarewicz's avatar
      Replace decimalnump with alphanumericp · c579b28f
      Michal Nazarewicz authored
      decimalnump was used in regex.c only in ISALNUM macro which ored it with
      alphabeticp.  Because both of those functions require Unicode general
      category lookup, this resulted in unnecessary lookups (if alphabeticp
      return false decimalp had to perform another lookup).  Drop decimalnump
      in favour of alphanumericp which combines decimelnump with alphabeticp.
      
      * src/character.c (decimalnump): Remove in favour of…
      (alphanumericp): …new function.
      
      * src/regex.c (ISALNUM): Use alphanumericp.
      c579b28f
    • Michal Nazarewicz's avatar
      Remove inaccurate comment in regex.c · b1c4c005
      Michal Nazarewicz authored
      * src/regex.c (regex_compile): Remove comment indicating that wctype of
      some character classes may be negative.  All wctypes are in fact
      non-negative.
      b1c4c005
  23. 05 Aug, 2016 1 commit
  24. 02 Aug, 2016 7 commits
    • Paul Eggert's avatar
      Port regex changes to strict ISO C · 0100805a
      Paul Eggert authored
      * src/regex.c (regex_compile): Redo casts.
      0100805a
    • Michal Nazarewicz's avatar
      Remove unused STREQ macro · edd5dd80
      Michal Nazarewicz authored
      This fixes the following compilation warning:
      
          regex.c:516:0: warning: macro "STREQ" is not used [-Wunused-macros]
           #define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
           ^
      
      * src/regex.c (STREQ): Remove unused macro.  It should have been removed
      in a [4538a5e3: Refactor regex character class parsing in [:name:]]
      commit but was mistakenly left out.
      edd5dd80
    • Michal Nazarewicz's avatar
      Hardcode regex syntax to remove dead code handling different syntax · 54a3c0c9
      Michal Nazarewicz authored
      Emacs only ever uses its own regex syntax so support for other syntaxes
      is never used.  Hardcode the syntax so that the compilar can detect such
      dead code and remove it from compiled code.
      
      The only exception is RE_NO_POSIX_BACKTRACKING which can be separatelly
      specified.  Handle this separatelly with a function argument (replacing
      now unnecessary syntax argument).
      
      With this patchset, size of Emacs binary on x86_64 machine is reduced by
      around 60 kB:
      
      	new-sizes:-rwx------ 3 mpn eng 30254720 Jul 27 23:31 src/emacs
      	old-sizes:-rwx------ 3 mpn eng 30314828 Jul 27 23:29 src/emacs
      
      * src/regex.h (re_pattern_buffer): Don’t define syntax field #ifdef emacs.
      (re_compile_pattern): Replace syntax with posix_backtracking argument.
      
      * src/regex.c (print_compiled_pattern): Don’t print syntax #ifdef emacs.
      (regex_compile): #ifdef emacs, replace syntax argument with
      posix_backtracking which is now used instead of testing for
      RE_NO_POSIX_BACKTRACKING syntax.
      (re_match_2_internal): Don’t access bufp->syntax #ifndef emacs.
      (re_compile_pattern): Replace syntax with posix_backtracking argument.
      
      * src/search.c (compile_pattern_1): Pass boolean posix_backtracking
      instead of syntax to re_compile_pattern.
      54a3c0c9
    • Michal Nazarewicz's avatar
      Get rid of re_set_whitespace_regexp · da9c55dd
      Michal Nazarewicz authored
      * src/regex.h (re_set_whitespace_regexp): Delete.
      (re_compile_pattern): Add whitespace_regexp argument #ifdef emacs.
      
      * src/regex.c (re_set_whitespace_regexp, whitespace_regexp): Delete.
      (regex_compile): Add whitespace_regexp argument #ifdef emacs and wrap
      whitespace_regexp-related code in an #ifdef emacs so it’s compiled out
      unless building Emacs.
      (re_compile_pattern): Pass whitespace_regexp argument to regex_compile
      
      * src/search.c (compile_pattern_1): Don’t use re_set_whitespace_regexp,
      pass the regex as argument to re_compile_pattern instead.
      da9c55dd
    • Michal Nazarewicz's avatar
      Get rid of re_set_syntax · 04d96eca
      Michal Nazarewicz authored
      Instead of using a global variable for storing regex syntax, pass it
      to re_compile_pattern.  This is only enabled when compiling Emacs (i.e.
      ‘#ifdef emacs’).
      
      * src/regex.h (re_set_syntax): Declare only #ifndef emacs.
      (re_compile_pattern): Now takes syntax argument #ifdef emacs.
      
      * src/regex.c (re_syntax_options): Define only #ifndef emacs.
      (re_compile_pattern): Use the new syntax argument #ifdef emacs.
      
      * src/search.c (compile_pattern_1): Don’t use re_set_syntax and
      instead pass syntax to re_compile_pattern directly.
      04d96eca
    • Michal Nazarewicz's avatar
      Remove dead opcodes in regex bytecode · 9a418e0f
      Michal Nazarewicz authored
      There is no way to specify before_dot and after_dot opcodes in a regex
      so code handling those ends up being dead.  Remove it.
      
      * src/regex.c (print_partial_compiled_pattern, regex_compile,
      analyze_first, re_match_2_internal): Remove handling and references to
      before_dot and after_dot opcodes.
      9a418e0f
    • Michal Nazarewicz's avatar
      Refactor regex character class parsing in [:name:] · 4538a5e3
      Michal Nazarewicz authored
      re_wctype function is used in three separate places and in all of
      those places almost exact code extracting the name from [:name:]
      surrounds it.  Furthermore, re_wctype requires a NUL-terminated
      string, so the name of the character class is copied to a temporary
      buffer.
      
      The code duplication and unnecessary memory copying can be avoided by
      pushing the responsibility of parsing the whole [:name:] sequence to
      the function.
      
      Furthermore, since now the function has access to the length of the
      character class name (since it’s doing the parsing), it can take
      advantage of that information in skipping some string comparisons and
      using a constant-length memcmp instead of strcmp which needs to take
      care of NUL bytes.
      
      * src/regex.c (re_wctype): Delete function.  Replace it with:
      (re_wctype_parse): New function which parses a whole [:name:] string
      and returns a RECC_* constant or -1 if the string is not of [:name:]
      format.
      (regex_compile): Use re_wctype_parse.
      * src/syntax.c (skip_chars): Use re_wctype_parse.
      4538a5e3
  25. 27 Jul, 2016 1 commit
  26. 25 Jul, 2016 1 commit
    • Michal Nazarewicz's avatar
      Fix ‘[[🇨🇨]]*literal’ regex failing to match ‘literal’ (bug#24020) · 6dc6b007
      Michal Nazarewicz authored
      The regex engine tries to optimise Kleene star by avoiding backtracking
      when it can detect that star’s operand cannot match what follows it in
      the pattern.
      
      For example, when ‘[[:alpha:]]*1’ tries to match a ‘foo’, the engine
      will test the longest match for ‘[[:alpha:]]*’, namely ’foo’ which is
      the entire string.  Literal digit one still present in the pattern will
      however not match the remaining empty string.
      
      Normally, backtracking would be performed trying a shorter match for the
      character class (namely ‘fo’ leaving ‘o’ in the string), but since the
      engine knows whatever would be put back into the string cannot possibly
      match literal digit one so no backtracking will be attempted.
      
      In the regexes of the form ‘[[:CC:]]*X’, the optimisation can be applied
      if the character class CC does not match character X.  In the above
      example, this holds because digit one is not in alpha character class.
      
      This test is performed by mutually_exclusive_p function but it did not
      check class bits of a charset opcode.  This resulted in an assumption
      that character classes do not match multibyte characters.  For example,
      it would incorrectly conclude that [[:alpha:]] doesn’t match ‘ż’.
      
      This, in turn, led to the aforementioned Kleene star optimisation being
      incorrectly applied in patterns such as ‘[[:graph:]]*’ (which should
      match ‘’ but doesn’t as can be tested by executing
          (string-match-p "[[:graph:]]*" "")
      which should return 0 but instead yields nil.
      
      This issue affects any class witch matches multibyte characters, i.e.
      if ‘[[🇨🇨]]’ matches a multibyte character X then ‘[[🇨🇨]]*X’ will
      fail to match ‘X’.
      
      * src/regex.c (executing_charset): A new function for executing the
      charset and charset_not opcodes.  It performs check on the character
      taking into consideration existing bitmap, range table and class bits.
      It also advances the pointer in the regex bytecode past the parsed
      opcode.
      (CHARSET_LOOKUP_RANGE_TABLE_RAW, CHARSET_LOOKUP_RANGE_TABLE): Removed.
      Code now included in executing_charset.
      (mutually_exclusive_p, re_match_2_internal): Changed to take advantage
      of executing_charset function.
      
      * test/src/regex-tests.el: New file with tests for the character class
      matching.
      6dc6b007
  27. 08 Jun, 2016 1 commit
  28. 30 May, 2016 1 commit
    • Paul Eggert's avatar
      Omit IF_LINT code that no longer seems needed · 237244bb
      Paul Eggert authored
      Nowadays GCC is smarter, or the Emacs code has mutated, or both,
      and now is as good a time as any to remove uses of IF_LINT that
      now seem to be unnecessary.
      * lib-src/emacsclient.c (set_local_socket):
      * lib-src/movemail.c (main) [MAIL_USE_MAILLOCK && HAVE_TOUCHLOCK]:
      * src/buffer.c (fix_start_end_in_overlays, fix_overlays_before):
      * src/casefiddle.c (casify_region):
      * src/charset.c (load_charset_map):
      * src/coding.c (decode_coding_object, encode_coding_object):
      * src/data.c (Fmake_variable_buffer_local, Fmake_local_variable)
      (cons_to_unsigned, cons_to_signed):
      * src/frame.c (make_frame, x_set_frame_parameters):
      * src/keyboard.c (read_event_from_main_queue):
      * src/regex.c (regex_compile):
      * src/syntax.c (back_comment):
      * src/window.c (Frecenter):
      * src/xfaces.c (Fx_list_fonts):
      Remove IF_LINT that no longer seems necessary.
      * src/image.c (png_load_body, jpeg_load_body): Simplify use of IF_LINT.
      * src/keyboard.c (read_char): Use IF_LINT (volatile) rather than
      a pragma dance to pacify GCC -Wclobbered.
      * src/xdisp.c (x_produce_glyphs): Rewrite to avoid need for IF_LINT.
      
      * src/xterm.c (x_connection_closed): Now _Noreturn, which should
      mean we do not need IF_LINT any more.
      (x_io_error_quitter): Now _Noreturn.  Put an 'assume (false)’
      at the end, to forestall warnings from older compilers.
      237244bb