[Python-checkins] CVS: python/dist/src/Modules _sre.c,2.38,2.39
Fredrik Lundh
python-dev@python.org
Sun, 27 Aug 2000 13:59:49 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv12637/Modules
Modified Files:
_sre.c
Log Message:
don't mistake memory errors (including reaching the recursion limit)
with success. also, check return values from the mark functions.
this addresses (but doesn't really solve) bug #112693, and low-memory
problems reported by jack jansen.
Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.38
retrieving revision 2.39
diff -C2 -r2.38 -r2.39
*** _sre.c 2000/08/18 05:09:50 2.38
--- _sre.c 2000/08/27 20:59:47 2.39
***************
*** 17,20 ****
--- 17,21 ----
* 00-08-07 fl use PyOS_CheckStack() if available
* 00-08-08 fl changed findall to return empty strings instead of None
+ * 00-08-27 fl properly propagate memory errors
*
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
***************
*** 59,75 ****
/* optional features */
! /* prevent run-away recursion (bad patterns on long strings)
! Require a smaller recursion limit for a number of 64-bit platforms
! to prevent stack overflow:
! Win64 - MS_WIN64, Linux64 - __LP64__, Monterey (64-bit AIX) - _LP64
! XXX Or maybe this should be defined for all SIZEOF_VOIDP>4 platforms?
! */
#if !defined(USE_STACKCHECK)
! # if defined(MS_WIN64) || defined(__LP64__) || defined(_LP64)
! # define USE_RECURSION_LIMIT 7500
! # else
! # define USE_RECURSION_LIMIT 10000
! # endif
#endif
/* enables fast searching */
--- 60,75 ----
/* optional features */
! /* 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
! #else
! #define USE_RECURSION_LIMIT 10000
#endif
+ #endif
/* enables fast searching */
***************
*** 535,538 ****
--- 535,539 ----
}
+ #if 0 /* not used in this release */
LOCAL(int)
SRE_INFO(SRE_STATE* state, SRE_CODE* pattern)
***************
*** 560,563 ****
--- 561,565 ----
return pattern[0];
}
+ #endif
LOCAL(int)
***************
*** 876,880 ****
i = SRE_MATCH(state, pattern + pattern[0], level + 1);
if (i)
! return 1;
ptr--;
count--;
--- 878,882 ----
i = SRE_MATCH(state, pattern + pattern[0], level + 1);
if (i)
! return i;
ptr--;
count--;
***************
*** 888,892 ****
i = SRE_MATCH(state, pattern + pattern[0], level + 1);
if (i)
! return 1;
ptr--;
count--;
--- 890,894 ----
i = SRE_MATCH(state, pattern + pattern[0], level + 1);
if (i)
! return i;
ptr--;
count--;
***************
*** 957,966 ****
rp->count = count;
lastmark = state->lastmark;
! mark_save(state, 0, lastmark);
/* RECURSIVE */
i = SRE_MATCH(state, rp->pattern + 3, level + 1);
if (i)
return i;
- mark_restore(state, 0, lastmark);
rp->count = count - 1;
state->ptr = ptr;
--- 959,972 ----
rp->count = count;
lastmark = state->lastmark;
! i = mark_save(state, 0, lastmark);
! if (i < 0)
! return i;
/* RECURSIVE */
i = SRE_MATCH(state, rp->pattern + 3, level + 1);
if (i)
+ return i;
+ i = mark_restore(state, 0, lastmark);
+ if (i < 0)
return i;
rp->count = count - 1;
state->ptr = ptr;
***************
*** 1699,1706 ****
}
! status = PyList_Append(list, item);
! Py_DECREF(item);
! if (status < 0)
goto error;
if (state.ptr == state.start)
--- 1705,1712 ----
}
! if (PyList_Append(list, item) < 0) {
! Py_DECREF(item);
goto error;
+ }
if (state.ptr == state.start)