Karsten Hopp b4e514
To: vim_dev@googlegroups.com
Karsten Hopp b4e514
Subject: Patch 7.3.1025
Karsten Hopp b4e514
Fcc: outbox
Karsten Hopp b4e514
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp b4e514
Mime-Version: 1.0
Karsten Hopp b4e514
Content-Type: text/plain; charset=UTF-8
Karsten Hopp b4e514
Content-Transfer-Encoding: 8bit
Karsten Hopp b4e514
------------
Karsten Hopp b4e514
Karsten Hopp b4e514
Patch 7.3.1025
Karsten Hopp b4e514
Problem:    New regexp: not matching newline in string. (Marc Weber)
Karsten Hopp b4e514
Solution:   Check for "\n" character.
Karsten Hopp b4e514
Files:	    src/regexp_nfa.c, src/testdir/test64.in, src/testdir/test64.ok
Karsten Hopp b4e514
Karsten Hopp b4e514
Karsten Hopp b4e514
*** ../vim-7.3.1024/src/regexp_nfa.c	2013-05-26 16:57:23.000000000 +0200
Karsten Hopp b4e514
--- src/regexp_nfa.c	2013-05-26 17:38:27.000000000 +0200
Karsten Hopp b4e514
***************
Karsten Hopp b4e514
*** 165,173 ****
Karsten Hopp b4e514
  static int *post_end;
Karsten Hopp b4e514
  static int *post_ptr;
Karsten Hopp b4e514
  
Karsten Hopp b4e514
! static int nstate;	/* Number of states in the NFA. */
Karsten Hopp b4e514
  static int istate;	/* Index in the state vector, used in new_state() */
Karsten Hopp b4e514
- static int nstate_max;	/* Upper bound of estimated number of states. */
Karsten Hopp b4e514
  
Karsten Hopp b4e514
  
Karsten Hopp b4e514
  static int nfa_regcomp_start __ARGS((char_u*expr, int re_flags));
Karsten Hopp b4e514
--- 165,173 ----
Karsten Hopp b4e514
  static int *post_end;
Karsten Hopp b4e514
  static int *post_ptr;
Karsten Hopp b4e514
  
Karsten Hopp b4e514
! static int nstate;	/* Number of states in the NFA. Also used when
Karsten Hopp b4e514
! 			 * executing. */
Karsten Hopp b4e514
  static int istate;	/* Index in the state vector, used in new_state() */
Karsten Hopp b4e514
  
Karsten Hopp b4e514
  
Karsten Hopp b4e514
  static int nfa_regcomp_start __ARGS((char_u*expr, int re_flags));
Karsten Hopp b4e514
***************
Karsten Hopp b4e514
*** 219,228 ****
Karsten Hopp b4e514
      int		re_flags;	    /* see vim_regcomp() */
Karsten Hopp b4e514
  {
Karsten Hopp b4e514
      size_t	postfix_size;
Karsten Hopp b4e514
  
Karsten Hopp b4e514
      nstate = 0;
Karsten Hopp b4e514
      istate = 0;
Karsten Hopp b4e514
!     /* A reasonable estimation for size */
Karsten Hopp b4e514
      nstate_max = (int)(STRLEN(expr) + 1) * NFA_POSTFIX_MULTIPLIER;
Karsten Hopp b4e514
  
Karsten Hopp b4e514
      /* Some items blow up in size, such as [A-z].  Add more space for that.
Karsten Hopp b4e514
--- 219,229 ----
Karsten Hopp b4e514
      int		re_flags;	    /* see vim_regcomp() */
Karsten Hopp b4e514
  {
Karsten Hopp b4e514
      size_t	postfix_size;
Karsten Hopp b4e514
+     int		nstate_max;
Karsten Hopp b4e514
  
Karsten Hopp b4e514
      nstate = 0;
Karsten Hopp b4e514
      istate = 0;
Karsten Hopp b4e514
!     /* A reasonable estimation for maximum size */
Karsten Hopp b4e514
      nstate_max = (int)(STRLEN(expr) + 1) * NFA_POSTFIX_MULTIPLIER;
Karsten Hopp b4e514
  
Karsten Hopp b4e514
      /* Some items blow up in size, such as [A-z].  Add more space for that.
Karsten Hopp b4e514
***************
Karsten Hopp b4e514
*** 1968,1977 ****
Karsten Hopp b4e514
   * Frag_T.out is a list of places that need to be set to the
Karsten Hopp b4e514
   * next state for this fragment.
Karsten Hopp b4e514
   */
Karsten Hopp b4e514
  typedef union Ptrlist Ptrlist;
Karsten Hopp b4e514
  struct Frag
Karsten Hopp b4e514
  {
Karsten Hopp b4e514
!     nfa_state_T   *start;
Karsten Hopp b4e514
      Ptrlist	*out;
Karsten Hopp b4e514
  };
Karsten Hopp b4e514
  typedef struct Frag Frag_T;
Karsten Hopp b4e514
--- 1969,1988 ----
Karsten Hopp b4e514
   * Frag_T.out is a list of places that need to be set to the
Karsten Hopp b4e514
   * next state for this fragment.
Karsten Hopp b4e514
   */
Karsten Hopp b4e514
+ 
Karsten Hopp b4e514
+ /* Since the out pointers in the list are always
Karsten Hopp b4e514
+  * uninitialized, we use the pointers themselves
Karsten Hopp b4e514
+  * as storage for the Ptrlists. */
Karsten Hopp b4e514
  typedef union Ptrlist Ptrlist;
Karsten Hopp b4e514
+ union Ptrlist
Karsten Hopp b4e514
+ {
Karsten Hopp b4e514
+     Ptrlist	*next;
Karsten Hopp b4e514
+     nfa_state_T	*s;
Karsten Hopp b4e514
+ };
Karsten Hopp b4e514
+ 
Karsten Hopp b4e514
  struct Frag
Karsten Hopp b4e514
  {
Karsten Hopp b4e514
!     nfa_state_T *start;
Karsten Hopp b4e514
      Ptrlist	*out;
Karsten Hopp b4e514
  };
Karsten Hopp b4e514
  typedef struct Frag Frag_T;
Karsten Hopp b4e514
***************
Karsten Hopp b4e514
*** 1999,2015 ****
Karsten Hopp b4e514
  }
Karsten Hopp b4e514
  
Karsten Hopp b4e514
  /*
Karsten Hopp b4e514
-  * Since the out pointers in the list are always
Karsten Hopp b4e514
-  * uninitialized, we use the pointers themselves
Karsten Hopp b4e514
-  * as storage for the Ptrlists.
Karsten Hopp b4e514
-  */
Karsten Hopp b4e514
- union Ptrlist
Karsten Hopp b4e514
- {
Karsten Hopp b4e514
-     Ptrlist	*next;
Karsten Hopp b4e514
-     nfa_state_T	*s;
Karsten Hopp b4e514
- };
Karsten Hopp b4e514
- 
Karsten Hopp b4e514
- /*
Karsten Hopp b4e514
   * Create singleton list containing just outp.
Karsten Hopp b4e514
   */
Karsten Hopp b4e514
      static Ptrlist *
Karsten Hopp b4e514
--- 2010,2015 ----
Karsten Hopp b4e514
***************
Karsten Hopp b4e514
*** 3358,3365 ****
Karsten Hopp b4e514
  #endif
Karsten Hopp b4e514
  
Karsten Hopp b4e514
  	    case NFA_NEWL:
Karsten Hopp b4e514
! 		if (!reg_line_lbr && REG_MULTI
Karsten Hopp b4e514
! 				     && curc == NUL && reglnum <= reg_maxline)
Karsten Hopp b4e514
  		{
Karsten Hopp b4e514
  		    go_to_nextline = TRUE;
Karsten Hopp b4e514
  		    /* Pass -1 for the offset, which means taking the position
Karsten Hopp b4e514
--- 3358,3365 ----
Karsten Hopp b4e514
  #endif
Karsten Hopp b4e514
  
Karsten Hopp b4e514
  	    case NFA_NEWL:
Karsten Hopp b4e514
! 		if (curc == NUL && !reg_line_lbr && REG_MULTI
Karsten Hopp b4e514
! 						    && reglnum <= reg_maxline)
Karsten Hopp b4e514
  		{
Karsten Hopp b4e514
  		    go_to_nextline = TRUE;
Karsten Hopp b4e514
  		    /* Pass -1 for the offset, which means taking the position
Karsten Hopp b4e514
***************
Karsten Hopp b4e514
*** 3367,3372 ****
Karsten Hopp b4e514
--- 3367,3378 ----
Karsten Hopp b4e514
  		    addstate(nextlist, t->state->out, &t->sub, -1,
Karsten Hopp b4e514
  							  listid + 1, &match);
Karsten Hopp b4e514
  		}
Karsten Hopp b4e514
+ 		else if (curc == '\n' && reg_line_lbr)
Karsten Hopp b4e514
+ 		{
Karsten Hopp b4e514
+ 		    /* match \n as if it is an ordinary character */
Karsten Hopp b4e514
+ 		    addstate(nextlist, t->state->out, &t->sub, 1,
Karsten Hopp b4e514
+ 							  listid + 1, &match);
Karsten Hopp b4e514
+ 		}
Karsten Hopp b4e514
  		break;
Karsten Hopp b4e514
  
Karsten Hopp b4e514
  	    case NFA_CLASS_ALNUM:
Karsten Hopp b4e514
***************
Karsten Hopp b4e514
*** 3832,3838 ****
Karsten Hopp b4e514
--- 3838,3849 ----
Karsten Hopp b4e514
       * (and count its size). */
Karsten Hopp b4e514
      postfix = re2post();
Karsten Hopp b4e514
      if (postfix == NULL)
Karsten Hopp b4e514
+     {
Karsten Hopp b4e514
+ 	/* TODO: only give this error for debugging? */
Karsten Hopp b4e514
+ 	if (post_ptr >= post_end)
Karsten Hopp b4e514
+ 	    EMSGN("Internal error: estimated max number of states insufficient: %ld", post_end - post_start);
Karsten Hopp b4e514
  	goto fail;	    /* Cascaded (syntax?) error */
Karsten Hopp b4e514
+     }
Karsten Hopp b4e514
  
Karsten Hopp b4e514
      /*
Karsten Hopp b4e514
       * In order to build the NFA, we parse the input regexp twice:
Karsten Hopp b4e514
*** ../vim-7.3.1024/src/testdir/test64.in	2013-05-26 16:57:23.000000000 +0200
Karsten Hopp b4e514
--- src/testdir/test64.in	2013-05-26 17:37:51.000000000 +0200
Karsten Hopp b4e514
***************
Karsten Hopp b4e514
*** 250,255 ****
Karsten Hopp b4e514
--- 250,258 ----
Karsten Hopp b4e514
  :call add(tl, [2, 'abc[0-9]*ddd', 'adf abc44482ddd oijs', 'abc44482ddd'])
Karsten Hopp b4e514
  :call add(tl, [2, '\_[0-9]\+', 'asfi9888u', '9888'])
Karsten Hopp b4e514
  :call add(tl, [2, '[0-9\n]\+', 'asfi9888u', '9888'])
Karsten Hopp b4e514
+ :call add(tl, [2, '\_[0-9]\+', "asfi\n9888u", "\n9888"])
Karsten Hopp b4e514
+ :call add(tl, [2, '\_f', "  \na ", "\n"])
Karsten Hopp b4e514
+ :call add(tl, [2, '\_f\+', "  \na ", "\na"])
Karsten Hopp b4e514
  :"
Karsten Hopp b4e514
  :"
Karsten Hopp b4e514
  :"""" Test recognition of some character classes
Karsten Hopp b4e514
*** ../vim-7.3.1024/src/testdir/test64.ok	2013-05-26 16:57:23.000000000 +0200
Karsten Hopp b4e514
--- src/testdir/test64.ok	2013-05-26 17:38:51.000000000 +0200
Karsten Hopp b4e514
***************
Karsten Hopp b4e514
*** 576,581 ****
Karsten Hopp b4e514
--- 576,590 ----
Karsten Hopp b4e514
  OK 0 - [0-9\n]\+
Karsten Hopp b4e514
  OK 1 - [0-9\n]\+
Karsten Hopp b4e514
  OK 2 - [0-9\n]\+
Karsten Hopp b4e514
+ OK 0 - \_[0-9]\+
Karsten Hopp b4e514
+ OK 1 - \_[0-9]\+
Karsten Hopp b4e514
+ OK 2 - \_[0-9]\+
Karsten Hopp b4e514
+ OK 0 - \_f
Karsten Hopp b4e514
+ OK 1 - \_f
Karsten Hopp b4e514
+ OK 2 - \_f
Karsten Hopp b4e514
+ OK 0 - \_f\+
Karsten Hopp b4e514
+ OK 1 - \_f\+
Karsten Hopp b4e514
+ OK 2 - \_f\+
Karsten Hopp b4e514
  OK 0 - [0-9]
Karsten Hopp b4e514
  OK 1 - [0-9]
Karsten Hopp b4e514
  OK 2 - [0-9]
Karsten Hopp b4e514
*** ../vim-7.3.1024/src/version.c	2013-05-26 16:57:23.000000000 +0200
Karsten Hopp b4e514
--- src/version.c	2013-05-26 17:44:16.000000000 +0200
Karsten Hopp b4e514
***************
Karsten Hopp b4e514
*** 730,731 ****
Karsten Hopp b4e514
--- 730,733 ----
Karsten Hopp b4e514
  {   /* Add new patch number below this line */
Karsten Hopp b4e514
+ /**/
Karsten Hopp b4e514
+     1025,
Karsten Hopp b4e514
  /**/
Karsten Hopp b4e514
Karsten Hopp b4e514
-- 
Karsten Hopp b4e514
Every engineer dreams about saving the universe and having sex with aliens.
Karsten Hopp b4e514
This is much more glamorous than the real life of an engineer, which consists
Karsten Hopp b4e514
of hiding from the universe and having sex without the participation of other
Karsten Hopp b4e514
life forms.                     (Scott Adams - The Dilbert principle)
Karsten Hopp b4e514
Karsten Hopp b4e514
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp b4e514
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp b4e514
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp b4e514
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///