[Python-checkins] python/dist/src/Modules _sre.c,2.102,2.103

niemeyer at users.sourceforge.net niemeyer at users.sourceforge.net
Sat Dec 13 15:32:21 EST 2003


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv22912/Modules
Modified Files:
	_sre.c 
Log Message:
Cleaning up recursive pieces left in the reorganization.
Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.102
retrieving revision 2.103
diff -C2 -d -r2.102 -r2.103
*** _sre.c	18 Oct 2003 20:54:44 -0000	2.102
--- _sre.c	13 Dec 2003 20:32:08 -0000	2.103
***************
*** 65,99 ****
 /* 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
- 
- #if defined(__GNUC__) && defined(WITH_THREAD) && defined(__FreeBSD__)
- /* 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 usage of recursive scheme */
- #undef USE_RECURSION
- 
 /* enables fast searching */
 #define USE_FAST_SEARCH
--- 65,68 ----
***************
*** 537,544 ****
 }
 
! LOCAL(int) SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level);
 
 LOCAL(int)
! SRE_COUNT(SRE_STATE* state, SRE_CODE* pattern, int maxcount, int level)
 {
 SRE_CODE chr;
--- 506,513 ----
 }
 
! LOCAL(int) SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern);
 
 LOCAL(int)
! SRE_COUNT(SRE_STATE* state, SRE_CODE* pattern, int maxcount)
 {
 SRE_CODE chr;
***************
*** 610,614 ****
 TRACE(("|%p|%p|COUNT SUBPATTERN\n", pattern, ptr));
 while ((SRE_CHAR*) state->ptr < end) {
! i = SRE_MATCH(state, pattern, level);
 if (i < 0)
 return i;
--- 579,583 ----
 TRACE(("|%p|%p|COUNT SUBPATTERN\n", pattern, ptr));
 while ((SRE_CHAR*) state->ptr < end) {
! i = SRE_MATCH(state, pattern);
 if (i < 0)
 return i;
***************
*** 828,832 ****
 error, 0 for failure, and 1 for success */
 LOCAL(int)
! SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
 {
 SRE_CHAR* end = state->end;
--- 797,801 ----
 error, 0 for failure, and 1 for success */
 LOCAL(int)
! SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
 {
 SRE_CHAR* end = state->end;
***************
*** 838,852 ****
 SRE_MATCH_CONTEXT* nextctx;
 
! TRACE(("|%p|%p|ENTER %d\n", pattern, state->ptr, level));
! 
! #if defined(USE_STACKCHECK)
! if (level % 10 == 0 && PyOS_CheckStack())
! return SRE_ERROR_RECURSION_LIMIT;
! #endif
! 
! #if defined(USE_RECURSION_LIMIT)
! if (level > USE_RECURSION_LIMIT)
! return SRE_ERROR_RECURSION_LIMIT;
! #endif
 
 DATA_ALLOC(SRE_MATCH_CONTEXT, ctx);
--- 807,811 ----
 SRE_MATCH_CONTEXT* nextctx;
 
! TRACE(("|%p|%p|ENTER\n", pattern, state->ptr));
 
 DATA_ALLOC(SRE_MATCH_CONTEXT, ctx);
***************
*** 1030,1038 ****
 continue;
 state->ptr = ctx->ptr;
- #ifdef USE_RECURSION
- ret = SRE_MATCH(state, ctx->pattern+1, level+1);
- #else
 DO_JUMP(JUMP_BRANCH, jump_branch, ctx->pattern+1);
- #endif
 if (ret) {
 if (ctx->u.rep)
--- 989,993 ----
***************
*** 1067,1072 ****
 state->ptr = ctx->ptr;
 
! ctx->count = SRE_COUNT(state, ctx->pattern+3, ctx->pattern[2],
! level+1);
 RETURN_ON_ERROR(ctx->count);
 
--- 1022,1026 ----
 state->ptr = ctx->ptr;
 
! ctx->count = SRE_COUNT(state, ctx->pattern+3, ctx->pattern[2]);
 RETURN_ON_ERROR(ctx->count);
 
***************
*** 1102,1112 ****
 break;
 state->ptr = ctx->ptr;
- #ifdef USE_RECURSION
- ret = SRE_MATCH(state, ctx->pattern+ctx->pattern[0],
- level+1);
- #else
 DO_JUMP(JUMP_REPEAT_ONE_1, jump_repeat_one_1,
 ctx->pattern+ctx->pattern[0]);
- #endif
 if (ret) {
 RETURN_ON_ERROR(ret);
--- 1056,1061 ----
***************
*** 1124,1134 ****
 while (ctx->count >= (int) ctx->pattern[1]) {
 state->ptr = ctx->ptr;
- #ifdef USE_RECURSION
- ret = SRE_MATCH(state, ctx->pattern+ctx->pattern[0],
- level+1);
- #else
 DO_JUMP(JUMP_REPEAT_ONE_2, jump_repeat_one_2,
 ctx->pattern+ctx->pattern[0]);
- #endif
 if (ret) {
 RETURN_ON_ERROR(ret);
--- 1073,1078 ----
***************
*** 1165,1169 ****
 /* count using pattern min as the maximum */
 ctx->count = SRE_COUNT(state, ctx->pattern+3,
! ctx->pattern[1], level+1);
 RETURN_ON_ERROR(ctx->count);
 if (ctx->count < (int) ctx->pattern[1])
--- 1109,1113 ----
 /* count using pattern min as the maximum */
 ctx->count = SRE_COUNT(state, ctx->pattern+3,
! ctx->pattern[1]);
 RETURN_ON_ERROR(ctx->count);
 if (ctx->count < (int) ctx->pattern[1])
***************
*** 1185,1195 ****
 || ctx->count <= (int)ctx->pattern[2]) {
 state->ptr = ctx->ptr;
- #ifdef USE_RECURSION
- ret = SRE_MATCH(state, ctx->pattern+ctx->pattern[0],
- level+1);
- #else
 DO_JUMP(JUMP_MIN_REPEAT_ONE,jump_min_repeat_one,
 ctx->pattern+ctx->pattern[0]);
- #endif
 if (ret) {
 RETURN_ON_ERROR(ret);
--- 1129,1134 ----
***************
*** 1197,1201 ****
 }
 state->ptr = ctx->ptr;
! ret = SRE_COUNT(state, ctx->pattern+3, 1, level+1);
 RETURN_ON_ERROR(ret);
 if (ret == 0)
--- 1136,1140 ----
 }
 state->ptr = ctx->ptr;
! ret = SRE_COUNT(state, ctx->pattern+3, 1);
 RETURN_ON_ERROR(ret);
 if (ret == 0)
***************
*** 1225,1233 ****
 
 state->ptr = ctx->ptr;
- #ifdef USE_RECURSION
- ret = SRE_MATCH(state, ctx->pattern+ctx->pattern[0], level+1);
- #else
 DO_JUMP(JUMP_REPEAT, jump_repeat, ctx->pattern+ctx->pattern[0]);
- #endif
 state->repeat = ctx->u.rep->prev;
 free(ctx->u.rep);
--- 1164,1168 ----
***************
*** 1260,1270 ****
 /* not enough matches */
 ctx->u.rep->count = ctx->count;
- #ifdef USE_RECURSION
- /* RECURSIVE */
- ret = SRE_MATCH(state, ctx->u.rep->pattern+3, level+1);
- #else
 DO_JUMP(JUMP_MAX_UNTIL_1, jump_max_until_1,
 ctx->u.rep->pattern+3);
- #endif
 if (ret) {
 RETURN_ON_ERROR(ret);
--- 1195,1200 ----
***************
*** 1287,1297 ****
 DATA_PUSH(&ctx->u.rep->last_ptr);
 ctx->u.rep->last_ptr = state->ptr;
- #ifdef USE_RECURSION
- /* RECURSIVE */
- ret = SRE_MATCH(state, ctx->u.rep->pattern+3, level+1);
- #else
 DO_JUMP(JUMP_MAX_UNTIL_2, jump_max_until_2,
 ctx->u.rep->pattern+3);
- #endif
 DATA_POP(&ctx->u.rep->last_ptr);
 if (ret) {
--- 1217,1222 ----
***************
*** 1309,1317 ****
 tail matches */
 state->repeat = ctx->u.rep->prev;
- #ifdef USE_RECURSION
- ret = SRE_MATCH(state, ctx->pattern, level+1);
- #else
 DO_JUMP(JUMP_MAX_UNTIL_3, jump_max_until_3, ctx->pattern);
- #endif
 RETURN_ON_SUCCESS(ret);
 state->repeat = ctx->u.rep;
--- 1234,1238 ----
***************
*** 1337,1347 ****
 /* not enough matches */
 ctx->u.rep->count = ctx->count;
- #ifdef USE_RECURSION
- /* RECURSIVE */
- ret = SRE_MATCH(state, ctx->u.rep->pattern+3, level+1);
- #else
 DO_JUMP(JUMP_MIN_UNTIL_1, jump_min_until_1,
 ctx->u.rep->pattern+3);
- #endif
 if (ret) {
 RETURN_ON_ERROR(ret);
--- 1258,1263 ----
***************
*** 1357,1365 ****
 /* see if the tail matches */
 state->repeat = ctx->u.rep->prev;
- #ifdef USE_RECURSION
- ret = SRE_MATCH(state, ctx->pattern, level+1);
- #else
 DO_JUMP(JUMP_MIN_UNTIL_2, jump_min_until_2, ctx->pattern);
- #endif
 if (ret) {
 RETURN_ON_ERROR(ret);
--- 1273,1277 ----
***************
*** 1377,1387 ****
 
 ctx->u.rep->count = ctx->count;
- #ifdef USE_RECURSION
- /* RECURSIVE */
- ret = SRE_MATCH(state, ctx->u.rep->pattern+3, level+1);
- #else
 DO_JUMP(JUMP_MIN_UNTIL_3,jump_min_until_3,
 ctx->u.rep->pattern+3);
- #endif
 if (ret) {
 RETURN_ON_ERROR(ret);
--- 1289,1294 ----
***************
*** 1471,1479 ****
 if (state->ptr < state->beginning)
 RETURN_FAILURE;
- #ifdef USE_RECURSION
- ret = SRE_MATCH(state, ctx->pattern+2, level+1);
- #else
 DO_JUMP(JUMP_ASSERT, jump_assert, ctx->pattern+2);
- #endif
 RETURN_ON_FAILURE(ret);
 ctx->pattern += ctx->pattern[0];
--- 1378,1382 ----
***************
*** 1487,1495 ****
 state->ptr = ctx->ptr - ctx->pattern[1];
 if (state->ptr >= state->beginning) {
- #ifdef USE_RECURSION
- ret = SRE_MATCH(state, ctx->pattern+2, level+1);
- #else
 DO_JUMP(JUMP_ASSERT_NOT, jump_assert_not, ctx->pattern+2);
- #endif
 if (ret) {
 RETURN_ON_ERROR(ret);
--- 1390,1394 ----
***************
*** 1520,1524 ****
 DATA_LOOKUP_AT(SRE_MATCH_CONTEXT, ctx, ctx_pos);
 
- #ifndef USE_RECURSION
 switch (jump) {
 case JUMP_MAX_UNTIL_2:
--- 1419,1422 ----
***************
*** 1565,1569 ****
 break;
 }
- #endif
 
 return ret; /* should never get here */
--- 1463,1466 ----
***************
*** 1636,1640 ****
 if (flags & SRE_INFO_LITERAL)
 return 1; /* we got all of it */
! status = SRE_MATCH(state, pattern + 2*prefix_skip, 1);
 if (status != 0)
 return status;
--- 1533,1537 ----
 if (flags & SRE_INFO_LITERAL)
 return 1; /* we got all of it */
! status = SRE_MATCH(state, pattern + 2*prefix_skip);
 if (status != 0)
 return status;
***************
*** 1667,1671 ****
 if (flags & SRE_INFO_LITERAL)
 return 1; /* we got all of it */
! status = SRE_MATCH(state, pattern + 2, 1);
 if (status != 0)
 break;
--- 1564,1568 ----
 if (flags & SRE_INFO_LITERAL)
 return 1; /* we got all of it */
! status = SRE_MATCH(state, pattern + 2);
 if (status != 0)
 break;
***************
*** 1682,1686 ****
 state->start = ptr;
 state->ptr = ptr;
! status = SRE_MATCH(state, pattern, 1);
 if (status != 0)
 break;
--- 1579,1583 ----
 state->start = ptr;
 state->ptr = ptr;
! status = SRE_MATCH(state, pattern);
 if (status != 0)
 break;
***************
*** 1692,1696 ****
 TRACE(("|%p|%p|SEARCH\n", pattern, ptr));
 state->start = state->ptr = ptr++;
! status = SRE_MATCH(state, pattern, 1);
 if (status != 0)
 break;
--- 1589,1593 ----
 TRACE(("|%p|%p|SEARCH\n", pattern, ptr));
 state->start = state->ptr = ptr++;
! status = SRE_MATCH(state, pattern);
 if (status != 0)
 break;
***************
*** 2115,2122 ****
 
 if (state.charsize == 1) {
! status = sre_match(&state, PatternObject_GetCode(self), 1);
 } else {
 #if defined(HAVE_UNICODE)
! status = sre_umatch(&state, PatternObject_GetCode(self), 1);
 #endif
 }
--- 2012,2019 ----
 
 if (state.charsize == 1) {
! status = sre_match(&state, PatternObject_GetCode(self));
 } else {
 #if defined(HAVE_UNICODE)
! status = sre_umatch(&state, PatternObject_GetCode(self));
 #endif
 }
***************
*** 3312,3319 ****
 
 if (state->charsize == 1) {
! status = sre_match(state, PatternObject_GetCode(self->pattern), 1);
 } else {
 #if defined(HAVE_UNICODE)
! status = sre_umatch(state, PatternObject_GetCode(self->pattern), 1);
 #endif
 }
--- 3209,3216 ----
 
 if (state->charsize == 1) {
! status = sre_match(state, PatternObject_GetCode(self->pattern));
 } else {
 #if defined(HAVE_UNICODE)
! status = sre_umatch(state, PatternObject_GetCode(self->pattern));
 #endif
 }


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /