[Python-checkins] python/dist/src/Modules _sre.c,2.94,2.95

niemeyer@users.sourceforge.net niemeyer@users.sourceforge.net
Sun, 27 Apr 2003 06:25:24 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv24491/Modules

Modified Files:
	_sre.c 
Log Message:
Fix for part of the problem mentioned in #725149 by Greg Chapman.

This problem is related to a wrong behavior from mark_save/restore(),
which don't restore the mark_stack_base before restoring the marks.
Greg's suggestion was to change the asserts, which happen to be
the only recursive ops that can continue the loop, but the problem would
happen to any operation with the same behavior. So, rather than
hardcoding this into asserts, I have changed mark_save/restore() to
always restore the stackbase before restoring the marks.

Both solutions should fix these two cases, presented by Greg:

>>> re.match('(a)(?:(?=(b)*)c)*', 'abb').groups()
('b', None)
>>> re.match('(a)((?!(b)*))*', 'abb').groups()
('b', None, None)

The rest of the bug and patch in #725149 must be discussed further.


Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.94
retrieving revision 2.95
diff -C2 -d -r2.94 -r2.95
*** _sre.c	27 Apr 2003 12:34:14 -0000	2.94
--- _sre.c	27 Apr 2003 13:25:21 -0000	2.95
***************
*** 280,284 ****
  
  static int
! mark_save(SRE_STATE* state, int lo, int hi)
  {
      void* stack;
--- 280,284 ----
  
  static int
! mark_save(SRE_STATE* state, int lo, int hi, int *mark_stack_base)
  {
      void* stack;
***************
*** 324,332 ****
      state->mark_stack_base += size;
  
      return 0;
  }
  
  static int
! mark_restore(SRE_STATE* state, int lo, int hi)
  {
      int size;
--- 324,334 ----
      state->mark_stack_base += size;
  
+     *mark_stack_base = state->mark_stack_base;
+ 
      return 0;
  }
  
  static int
! mark_restore(SRE_STATE* state, int lo, int hi, int *mark_stack_base)
  {
      int size;
***************
*** 337,341 ****
      size = (hi - lo) + 1;
  
!     state->mark_stack_base -= size;
  
      TRACE(("copy %d:%d from %d\n", lo, hi, state->mark_stack_base));
--- 339,343 ----
      size = (hi - lo) + 1;
  
!     state->mark_stack_base = *mark_stack_base - size;
  
      TRACE(("copy %d:%d from %d\n", lo, hi, state->mark_stack_base));
***************
*** 713,717 ****
      int i, count;
      SRE_REPEAT* rp;
!     int lastmark, lastindex;
      SRE_CODE chr;
  
--- 715,719 ----
      int i, count;
      SRE_REPEAT* rp;
!     int lastmark, lastindex, mark_stack_base;
      SRE_CODE chr;
  
***************
*** 949,953 ****
                      continue;
                  if (state->repeat) {
!                     i = mark_save(state, 0, lastmark);
                      if (i < 0)
                          return i;
--- 951,955 ----
                      continue;
                  if (state->repeat) {
!                     i = mark_save(state, 0, lastmark, &mark_stack_base);
                      if (i < 0)
                          return i;
***************
*** 958,962 ****
                      return i;
                  if (state->repeat) {
!                     i = mark_restore(state, 0, lastmark);
                      if (i < 0)
                          return i;
--- 960,964 ----
                      return i;
                  if (state->repeat) {
!                     i = mark_restore(state, 0, lastmark, &mark_stack_base);
                      if (i < 0)
                          return i;
***************
*** 1158,1162 ****
                     match another item, do so */
                  rp->count = count;
!                 i = mark_save(state, 0, lastmark);
                  if (i < 0)
                      return i;
--- 1160,1164 ----
                     match another item, do so */
                  rp->count = count;
!                 i = mark_save(state, 0, lastmark, &mark_stack_base);
                  if (i < 0)
                      return i;
***************
*** 1165,1169 ****
                  if (i)
                      return i;
!                 i = mark_restore(state, 0, lastmark);
                  LASTMARK_RESTORE();
                  if (i < 0)
--- 1167,1171 ----
                  if (i)
                      return i;
!                 i = mark_restore(state, 0, lastmark, &mark_stack_base);
                  LASTMARK_RESTORE();
                  if (i < 0)