Karsten Hopp 8bbf39
To: vim_dev@googlegroups.com
Karsten Hopp 8bbf39
Subject: Patch 7.3.1018
Karsten Hopp 8bbf39
Fcc: outbox
Karsten Hopp 8bbf39
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 8bbf39
Mime-Version: 1.0
Karsten Hopp 8bbf39
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 8bbf39
Content-Transfer-Encoding: 8bit
Karsten Hopp 8bbf39
------------
Karsten Hopp 8bbf39
Karsten Hopp 8bbf39
Patch 7.3.1018
Karsten Hopp 8bbf39
Problem:    New regexp engine wastes memory.
Karsten Hopp 8bbf39
Solution:   Allocate prog with actual number of states, not estimated maximum
Karsten Hopp 8bbf39
            number of sates.
Karsten Hopp 8bbf39
Files:      src/regexp_nfa.c
Karsten Hopp 8bbf39
Karsten Hopp 8bbf39
Karsten Hopp 8bbf39
*** ../vim-7.3.1017/src/regexp_nfa.c	2013-05-25 20:19:45.000000000 +0200
Karsten Hopp 8bbf39
--- src/regexp_nfa.c	2013-05-25 20:57:21.000000000 +0200
Karsten Hopp 8bbf39
***************
Karsten Hopp 8bbf39
*** 3758,3764 ****
Karsten Hopp 8bbf39
      char_u	*expr;
Karsten Hopp 8bbf39
      int		re_flags;
Karsten Hopp 8bbf39
  {
Karsten Hopp 8bbf39
!     nfa_regprog_T	*prog;
Karsten Hopp 8bbf39
      size_t		prog_size;
Karsten Hopp 8bbf39
      int			*postfix;
Karsten Hopp 8bbf39
  
Karsten Hopp 8bbf39
--- 3758,3764 ----
Karsten Hopp 8bbf39
      char_u	*expr;
Karsten Hopp 8bbf39
      int		re_flags;
Karsten Hopp 8bbf39
  {
Karsten Hopp 8bbf39
!     nfa_regprog_T	*prog = NULL;
Karsten Hopp 8bbf39
      size_t		prog_size;
Karsten Hopp 8bbf39
      int			*postfix;
Karsten Hopp 8bbf39
  
Karsten Hopp 8bbf39
***************
Karsten Hopp 8bbf39
*** 3774,3788 ****
Karsten Hopp 8bbf39
      if (nfa_regcomp_start(expr, re_flags) == FAIL)
Karsten Hopp 8bbf39
  	return NULL;
Karsten Hopp 8bbf39
  
Karsten Hopp 8bbf39
-     /* Space for compiled regexp */
Karsten Hopp 8bbf39
-     prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * nstate_max;
Karsten Hopp 8bbf39
-     prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
Karsten Hopp 8bbf39
-     if (prog == NULL)
Karsten Hopp 8bbf39
- 	goto fail;
Karsten Hopp 8bbf39
-     vim_memset(prog, 0, prog_size);
Karsten Hopp 8bbf39
- 
Karsten Hopp 8bbf39
      /* Build postfix form of the regexp. Needed to build the NFA
Karsten Hopp 8bbf39
!      * (and count its size) */
Karsten Hopp 8bbf39
      postfix = re2post();
Karsten Hopp 8bbf39
      if (postfix == NULL)
Karsten Hopp 8bbf39
  	goto fail;	    /* Cascaded (syntax?) error */
Karsten Hopp 8bbf39
--- 3774,3781 ----
Karsten Hopp 8bbf39
      if (nfa_regcomp_start(expr, re_flags) == FAIL)
Karsten Hopp 8bbf39
  	return NULL;
Karsten Hopp 8bbf39
  
Karsten Hopp 8bbf39
      /* Build postfix form of the regexp. Needed to build the NFA
Karsten Hopp 8bbf39
!      * (and count its size). */
Karsten Hopp 8bbf39
      postfix = re2post();
Karsten Hopp 8bbf39
      if (postfix == NULL)
Karsten Hopp 8bbf39
  	goto fail;	    /* Cascaded (syntax?) error */
Karsten Hopp 8bbf39
***************
Karsten Hopp 8bbf39
*** 3809,3814 ****
Karsten Hopp 8bbf39
--- 3802,3814 ----
Karsten Hopp 8bbf39
       * Count number of NFA states in "nstate". Do not build the NFA.
Karsten Hopp 8bbf39
       */
Karsten Hopp 8bbf39
      post2nfa(postfix, post_ptr, TRUE);
Karsten Hopp 8bbf39
+ 
Karsten Hopp 8bbf39
+     /* Space for compiled regexp */
Karsten Hopp 8bbf39
+     prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * nstate;
Karsten Hopp 8bbf39
+     prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
Karsten Hopp 8bbf39
+     if (prog == NULL)
Karsten Hopp 8bbf39
+ 	goto fail;
Karsten Hopp 8bbf39
+     vim_memset(prog, 0, prog_size);
Karsten Hopp 8bbf39
      state_ptr = prog->state;
Karsten Hopp 8bbf39
  
Karsten Hopp 8bbf39
      /*
Karsten Hopp 8bbf39
*** ../vim-7.3.1017/src/version.c	2013-05-25 20:19:45.000000000 +0200
Karsten Hopp 8bbf39
--- src/version.c	2013-05-25 21:17:39.000000000 +0200
Karsten Hopp 8bbf39
***************
Karsten Hopp 8bbf39
*** 730,731 ****
Karsten Hopp 8bbf39
--- 730,733 ----
Karsten Hopp 8bbf39
  {   /* Add new patch number below this line */
Karsten Hopp 8bbf39
+ /**/
Karsten Hopp 8bbf39
+     1018,
Karsten Hopp 8bbf39
  /**/
Karsten Hopp 8bbf39
Karsten Hopp 8bbf39
-- 
Karsten Hopp 8bbf39
Sometimes you can protect millions of dollars in your budget simply by buying
Karsten Hopp 8bbf39
a bag of cookies, dropping it on the budget anylyst's desk, and saying
Karsten Hopp 8bbf39
something deeply personal such as "How was your weekend, big guy?"
Karsten Hopp 8bbf39
				(Scott Adams - The Dilbert principle)
Karsten Hopp 8bbf39
Karsten Hopp 8bbf39
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 8bbf39
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 8bbf39
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 8bbf39
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///