@@ -450,20 +450,23 @@ do { \
450
450
451
451
#define MARK_PUSH (lastmark ) \
452
452
do if (lastmark >= 0) { \
453
- i = lastmark; /* ctx->lastmark may change if reallocated */ \
454
- DATA_STACK_PUSH (state , state -> mark , ( i + 1 ) * sizeof ( void * ) ); \
453
+ size_t _marks_size = ( lastmark+1) * sizeof(void*); \
454
+ DATA_STACK_PUSH(state, state->mark, _marks_size ); \
455
455
} while (0)
456
456
#define MARK_POP (lastmark ) \
457
457
do if (lastmark >= 0) { \
458
- DATA_STACK_POP(state, state->mark, (lastmark+1)*sizeof(void*), 1); \
458
+ size_t _marks_size = (lastmark+1) * sizeof(void*); \
459
+ DATA_STACK_POP(state, state->mark, _marks_size, 1); \
459
460
} while (0)
460
461
#define MARK_POP_KEEP (lastmark ) \
461
462
do if (lastmark >= 0) { \
462
- DATA_STACK_POP(state, state->mark, (lastmark+1)*sizeof(void*), 0); \
463
+ size_t _marks_size = (lastmark+1) * sizeof(void*); \
464
+ DATA_STACK_POP(state, state->mark, _marks_size, 0); \
463
465
} while (0)
464
466
#define MARK_POP_DISCARD (lastmark ) \
465
467
do if (lastmark >= 0) { \
466
- DATA_STACK_POP_DISCARD(state, (lastmark+1)*sizeof(void*)); \
468
+ size_t _marks_size = (lastmark+1) * sizeof(void*); \
469
+ DATA_STACK_POP_DISCARD(state, _marks_size); \
467
470
} while (0)
468
471
469
472
#define JUMP_NONE 0
@@ -488,10 +491,10 @@ do { \
488
491
ctx->pattern = pattern; \
489
492
ctx->ptr = ptr; \
490
493
DATA_ALLOC(SRE(match_context), nextctx); \
491
- nextctx->last_ctx_pos = ctx_pos; \
492
- nextctx->jump = jumpvalue; \
493
494
nextctx->pattern = nextpattern; \
494
495
nextctx->toplevel = toplevel_; \
496
+ nextctx->jump = jumpvalue; \
497
+ nextctx->last_ctx_pos = ctx_pos; \
495
498
pattern = nextpattern; \
496
499
ctx_pos = alloc_pos; \
497
500
ctx = nextctx; \
@@ -507,18 +510,18 @@ do { \
507
510
DO_JUMPX(jumpvalue, jumplabel, nextpattern, 0)
508
511
509
512
typedef struct {
510
- Py_ssize_t last_ctx_pos ;
511
- Py_ssize_t jump ;
512
- const SRE_CHAR * ptr ;
513
- const SRE_CODE * pattern ;
514
513
Py_ssize_t count ;
515
- Py_ssize_t lastmark ;
516
- Py_ssize_t lastindex ;
517
514
union {
518
515
SRE_CODE chr ;
519
516
SRE_REPEAT * rep ;
520
517
} u ;
518
+ int lastmark ;
519
+ int lastindex ;
520
+ const SRE_CODE * pattern ;
521
+ const SRE_CHAR * ptr ;
521
522
int toplevel ;
523
+ int jump ;
524
+ Py_ssize_t last_ctx_pos ;
522
525
} SRE (match_context );
523
526
524
527
#define MAYBE_CHECK_SIGNALS \
@@ -558,8 +561,8 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
558
561
{
559
562
const SRE_CHAR * end = (const SRE_CHAR * )state -> end ;
560
563
Py_ssize_t alloc_pos , ctx_pos = -1 ;
561
- Py_ssize_t i , ret = 0 ;
562
- Py_ssize_t jump ;
564
+ Py_ssize_t ret = 0 ;
565
+ int jump ;
563
566
unsigned int sigcount = 0 ;
564
567
565
568
SRE (match_context )* ctx ;
@@ -607,20 +610,22 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
607
610
/* <MARK> <gid> */
608
611
TRACE (("|%p|%p|MARK %d\n" , pattern ,
609
612
ptr , pattern [0 ]));
610
- i = pattern [0 ];
611
- if (i & 1 )
612
- state -> lastindex = i /2 + 1 ;
613
- if (i > state -> lastmark ) {
614
- /* state->lastmark is the highest valid index in the
615
- state->mark array. If it is increased by more than 1,
616
- the intervening marks must be set to NULL to signal
617
- that these marks have not been encountered. */
618
- Py_ssize_t j = state -> lastmark + 1 ;
619
- while (j < i )
620
- state -> mark [j ++ ] = NULL ;
621
- state -> lastmark = i ;
613
+ {
614
+ int i = pattern [0 ];
615
+ if (i & 1 )
616
+ state -> lastindex = i /2 + 1 ;
617
+ if (i > state -> lastmark ) {
618
+ /* state->lastmark is the highest valid index in the
619
+ state->mark array. If it is increased by more than 1,
620
+ the intervening marks must be set to NULL to signal
621
+ that these marks have not been encountered. */
622
+ int j = state -> lastmark + 1 ;
623
+ while (j < i )
624
+ state -> mark [j ++ ] = NULL ;
625
+ state -> lastmark = i ;
626
+ }
627
+ state -> mark [i ] = ptr ;
622
628
}
623
- state -> mark [i ] = ptr ;
624
629
pattern ++ ;
625
630
DISPATCH ;
626
631
@@ -1373,9 +1378,8 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1373
1378
/* match backreference */
1374
1379
TRACE (("|%p|%p|GROUPREF %d\n" , pattern ,
1375
1380
ptr , pattern [0 ]));
1376
- i = pattern [0 ];
1377
1381
{
1378
- Py_ssize_t groupref = i + i ;
1382
+ int groupref = pattern [ 0 ] * 2 ;
1379
1383
if (groupref >= state -> lastmark ) {
1380
1384
RETURN_FAILURE ;
1381
1385
} else {
@@ -1398,9 +1402,8 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1398
1402
/* match backreference */
1399
1403
TRACE (("|%p|%p|GROUPREF_IGNORE %d\n" , pattern ,
1400
1404
ptr , pattern [0 ]));
1401
- i = pattern [0 ];
1402
1405
{
1403
- Py_ssize_t groupref = i + i ;
1406
+ int groupref = pattern [ 0 ] * 2 ;
1404
1407
if (groupref >= state -> lastmark ) {
1405
1408
RETURN_FAILURE ;
1406
1409
} else {
@@ -1424,9 +1427,8 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1424
1427
/* match backreference */
1425
1428
TRACE (("|%p|%p|GROUPREF_UNI_IGNORE %d\n" , pattern ,
1426
1429
ptr , pattern [0 ]));
1427
- i = pattern [0 ];
1428
1430
{
1429
- Py_ssize_t groupref = i + i ;
1431
+ int groupref = pattern [ 0 ] * 2 ;
1430
1432
if (groupref >= state -> lastmark ) {
1431
1433
RETURN_FAILURE ;
1432
1434
} else {
@@ -1450,9 +1452,8 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1450
1452
/* match backreference */
1451
1453
TRACE (("|%p|%p|GROUPREF_LOC_IGNORE %d\n" , pattern ,
1452
1454
ptr , pattern [0 ]));
1453
- i = pattern [0 ];
1454
1455
{
1455
- Py_ssize_t groupref = i + i ;
1456
+ int groupref = pattern [ 0 ] * 2 ;
1456
1457
if (groupref >= state -> lastmark ) {
1457
1458
RETURN_FAILURE ;
1458
1459
} else {
@@ -1476,9 +1477,8 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1476
1477
TRACE (("|%p|%p|GROUPREF_EXISTS %d\n" , pattern ,
1477
1478
ptr , pattern [0 ]));
1478
1479
/* <GROUPREF_EXISTS> <group> <skip> codeyes <JUMP> codeno ... */
1479
- i = pattern [0 ];
1480
1480
{
1481
- Py_ssize_t groupref = i + i ;
1481
+ int groupref = pattern [ 0 ] * 2 ;
1482
1482
if (groupref >= state -> lastmark ) {
1483
1483
pattern += pattern [1 ];
1484
1484
DISPATCH ;
0 commit comments