[Python-checkins] python/dist/src/Modules _sre.c,2.99.8.1,2.99.8.2

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Fri Nov 21 22:46:32 EST 2003


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

Modified Files:
      Tag: release23-maint
	_sre.c 
Log Message:
Indented and repaired the maze of #ifdefs setting USE_RECURSION_LIMIT.
Indented because it was incomprehensible.  "Repaired" means someone
checked in a change that screwed up the multiple nesting levels, causing
USE_RECURSION_LIMIT to stop getting defined on all non-LP64 boxes other
than FreeBSD.  Tried to repair that in a more-robust way.  That error
in turn caused a bogus change to get checked in to test_re.py, which I
repaired earlier.

This needs fresh testing on all non-Win32 platforms (Win32 never used
USE_RECURSION_LIMIT, and still doesn't).  Running the standard test_re.py
is an adequate test.


Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.99.8.1
retrieving revision 2.99.8.2
diff -C2 -d -r2.99.8.1 -r2.99.8.2
*** _sre.c	20 Oct 2003 20:59:45 -0000	2.99.8.1
--- _sre.c	22 Nov 2003 03:46:30 -0000	2.99.8.2
***************
*** 66,99 ****
  /* prevent run-away recursion (bad patterns on long strings) */
  
! #if !defined(USE_STACKCHECK)
! #if defined(MS_WIN64) || defined(__LP64__) || defined(_LP64)
! /* require smaller recursion limit for a number of 64-bit platforms:
!    Win64 (MS_WIN64), Linux64 (__LP64__), Monterey (64-bit AIX) (_LP64) */
! /* FIXME: maybe the limit should be 40000 / sizeof(void*) ? */
! #define USE_RECURSION_LIMIT 7500
  
! #elif defined(__FreeBSD__)
! /* FreeBSD/amd64 and /sparc64 require even smaller limits */
! #if defined(__amd64__)
! #define USE_RECURSION_LIMIT 6000
! #elif defined(__sparc64__)
! #define USE_RECURSION_LIMIT 3000
! #elif defined(__GNUC__) && defined(WITH_THREAD)
! /* the pthreads library on FreeBSD has a fixed 1MB stack size for the
!  * initial (or "primary") thread, which is insufficient for the default
!  * recursion limit.  gcc 3.x at the default optimisation
!  * level (-O3) uses stack space more aggressively than gcc 2.95.
!  */
! #if (__GNUC__ > 2)
! #define USE_RECURSION_LIMIT 6500
! #else
! #define USE_RECURSION_LIMIT 7500
! #endif
  
! #else
! #define USE_RECURSION_LIMIT 10000
! #endif
! #endif
! #endif
  
  /* enables fast searching */
--- 66,102 ----
  /* prevent run-away recursion (bad patterns on long strings) */
  
! #ifndef USE_STACKCHECK
!     #if defined(MS_WIN64) || defined(__LP64__) || defined(_LP64)
!         /* require smaller recursion limit for a number of 64-bit platforms:
!          * Win64 (MS_WIN64), Linux64 (__LP64__), Monterey (64-bit AIX) (_LP64)
!          */
!         /* FIXME: maybe the limit should be 40000 / sizeof(void*) ? */
!         #define USE_RECURSION_LIMIT 7500
  
!     #elif defined(__FreeBSD__)
!         /* FreeBSD/amd64 and /sparc64 require even smaller limits */
!         #if defined(__amd64__)
!             #define USE_RECURSION_LIMIT 6000
!         #elif defined(__sparc64__)
!             #define USE_RECURSION_LIMIT 3000
!         #elif defined(__GNUC__) && defined(WITH_THREAD)
!             /* the pthreads library on FreeBSD has a fixed 1MB stack size for
!              * the initial (or "primary") thread, which is insufficient for
!              * the default recursion limit.  gcc 3.x at the default
!              * optimisation level (-O3) uses stack space more aggressively
!              * than gcc 2.95.
!              */
!             #if (__GNUC__ > 2)
!                 #define USE_RECURSION_LIMIT 6500
!             #else
!                 #define USE_RECURSION_LIMIT 7500
!             #endif
!         #endif
!     #endif 	/* special cases for USE_RECURSION_LIMIT */
  
!     #ifndef USE_RECURSION_LIMIT		/* default if not overriden above */
!         #define USE_RECURSION_LIMIT 10000
!     #endif
! #endif	/* !USE_STACKCHECK */
  
  /* enables fast searching */
***************
*** 210,214 ****
  }
  
! #endif
  
  LOCAL(int)
--- 213,217 ----
  }
  
! #endif	/* HAVE_UNICODE */
  
  LOCAL(int)
***************
*** 526,530 ****
                      return ok;
                  set += 16;
!             } 
              else {
                  /* <CHARSET> <bitmap> (32 bits per code word) */
--- 529,533 ----
                      return ok;
                  set += 16;
!             }
              else {
                  /* <CHARSET> <bitmap> (32 bits per code word) */
***************
*** 554,558 ****
                      block = -1;
                  set += 64;
!                 if (block >=0 && 
                      (set[block*8 + ((ch & 255)>>5)] & (1 << (ch & 31))))
                      return ok;
--- 557,561 ----
                      block = -1;
                  set += 64;
!                 if (block >=0 &&
                      (set[block*8 + ((ch & 255)>>5)] & (1 << (ch & 31))))
                      return ok;
***************
*** 637,641 ****
              ptr++;
          break;
!                 
      case SRE_OP_NOT_LITERAL_IGNORE:
          /* repeated non-literal */
--- 640,644 ----
              ptr++;
          break;
! 
      case SRE_OP_NOT_LITERAL_IGNORE:
          /* repeated non-literal */
***************
*** 720,724 ****
   *   outside 'for' loop: must be protected when breaking, since the next
   *   OP could potentially depend on lastmark;
!  *   
   * - Recursive SRE_MATCH() returned false, and will be called again
   *   inside a local for/while loop: must be protected between each
--- 723,727 ----
   *   outside 'for' loop: must be protected when breaking, since the next
   *   OP could potentially depend on lastmark;
!  *
   * - Recursive SRE_MATCH() returned false, and will be called again
   *   inside a local for/while loop: must be protected between each
***************
*** 1108,1112 ****
                      return count;   /* exception */
                  if (count < (int) pattern[1])
!                     return 0;       /* did not match minimum number of times */ 
                  ptr += count;       /* advance past minimum matches of repeat */
              }
--- 1111,1115 ----
                      return count;   /* exception */
                  if (count < (int) pattern[1])
!                     return 0;       /* did not match minimum number of times */
                  ptr += count;       /* advance past minimum matches of repeat */
              }
***************
*** 1358,1362 ****
                      break;
                  }
!                 
              }
              ptr++;
--- 1361,1365 ----
                      break;
                  }
! 
              }
              ptr++;
***************
*** 1413,1417 ****
      return status;
  }
!     
  LOCAL(int)
  SRE_LITERAL_TEMPLATE(SRE_CHAR* ptr, int len)
--- 1416,1420 ----
      return status;
  }
! 
  LOCAL(int)
  SRE_LITERAL_TEMPLATE(SRE_CHAR* ptr, int len)
***************
*** 1535,1539 ****
         characters), and a character size.  return NULL if the object
         is not a string (or not compatible) */
!     
      PyBufferProcs *buffer;
      int size, bytes, charsize;
--- 1538,1542 ----
         characters), and a character size.  return NULL if the object
         is not a string (or not compatible) */
! 
      PyBufferProcs *buffer;
      int size, bytes, charsize;
***************
*** 2011,2015 ****
  
          PyObject* item;
!         
          state_reset(&state);
  
--- 2014,2018 ----
  
          PyObject* item;
! 
          state_reset(&state);
  
***************
*** 2030,2034 ****
              goto error;
          }
!         
          /* don't bother to build a match object */
          switch (self->groups) {
--- 2033,2037 ----
              goto error;
          }
! 
          /* don't bother to build a match object */
          switch (self->groups) {
***************
*** 2079,2083 ****
      state_fini(&state);
      return NULL;
!     
  }
  
--- 2082,2086 ----
      state_fini(&state);
      return NULL;
! 
  }
  
***************
*** 2157,2161 ****
              goto error;
          }
!         
          if (state.start == state.ptr) {
              if (last == state.end)
--- 2160,2164 ----
              goto error;
          }
! 
          if (state.start == state.ptr) {
              if (last == state.end)
***************
*** 2213,2217 ****
      state_fini(&state);
      return NULL;
!     
  }
  
--- 2216,2220 ----
      state_fini(&state);
      return NULL;
! 
  }
  
***************
*** 2304,2308 ****
              goto error;
          }
!         
          b = STATE_OFFSET(&state, state.start);
          e = STATE_OFFSET(&state, state.ptr);
--- 2307,2311 ----
              goto error;
          }
! 
          b = STATE_OFFSET(&state, state.start);
          e = STATE_OFFSET(&state, state.ptr);
***************
*** 2350,2354 ****
                  goto error;
          }
!         
          i = e;
          n = n + 1;
--- 2353,2357 ----
                  goto error;
          }
! 
          i = e;
          n = n + 1;
***************
*** 2394,2398 ****
      Py_DECREF(filter);
      return NULL;
!     
  }
  
--- 2397,2401 ----
      Py_DECREF(filter);
      return NULL;
! 
  }
  
***************
*** 2434,2438 ****
      if (args != Py_None && !PyArg_ParseTuple(args, ":__copy__"))
          return NULL;
!     
      copy = PyObject_NEW_VAR(PatternObject, &Pattern_Type, self->codesize);
      if (!copy)
--- 2437,2441 ----
      if (args != Py_None && !PyArg_ParseTuple(args, ":__copy__"))
          return NULL;
! 
      copy = PyObject_NEW_VAR(PatternObject, &Pattern_Type, self->codesize);
      if (!copy)
***************
*** 2460,2464 ****
  #ifdef USE_BUILTIN_COPY
      PatternObject* copy;
!     
      PyObject* memo;
      if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo))
--- 2463,2467 ----
  #ifdef USE_BUILTIN_COPY
      PatternObject* copy;
! 
      PyObject* memo;
      if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo))
***************
*** 2498,2502 ****
  };
  
! static PyObject*  
  pattern_getattr(PatternObject* self, char* name)
  {
--- 2501,2505 ----
  };
  
! static PyObject*
  pattern_getattr(PatternObject* self, char* name)
  {
***************
*** 2859,2863 ****
      MatchObject* copy;
      int slots, offset;
!     
      if (args != Py_None && !PyArg_ParseTuple(args, ":__copy__"))
          return NULL;
--- 2862,2866 ----
      MatchObject* copy;
      int slots, offset;
! 
      if (args != Py_None && !PyArg_ParseTuple(args, ":__copy__"))
          return NULL;
***************
*** 2892,2896 ****
  #ifdef USE_BUILTIN_COPY
      MatchObject* copy;
!     
      PyObject* memo;
      if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo))
--- 2895,2899 ----
  #ifdef USE_BUILTIN_COPY
      MatchObject* copy;
! 
      PyObject* memo;
      if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo))
***************
*** 2927,2931 ****
  };
  
! static PyObject*  
  match_getattr(MatchObject* self, char* name)
  {
--- 2930,2934 ----
  };
  
! static PyObject*
  match_getattr(MatchObject* self, char* name)
  {
***************
*** 3085,3089 ****
  };
  
! static PyObject*  
  scanner_getattr(ScannerObject* self, char* name)
  {
--- 3088,3092 ----
  };
  
! static PyObject*
  scanner_getattr(ScannerObject* self, char* name)
  {
***************
*** 3122,3126 ****
  };
  
! #if PY_VERSION_HEX < 0x02030000 
  DL_EXPORT(void) init_sre(void)
  #else
--- 3125,3129 ----
  };
  
! #if PY_VERSION_HEX < 0x02030000
  DL_EXPORT(void) init_sre(void)
  #else





More information about the Python-checkins mailing list