/[pcre]/code/trunk/pcre_dfa_exec.c
ViewVC logotype

Diff of /code/trunk/pcre_dfa_exec.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 637 by ph10, Sun Jul 24 17:44:12 2011 UTC revision 642 by ph10, Thu Jul 28 18:59:40 2011 UTC
# Line 328  Arguments: Line 328  Arguments:
328    workspace         vector of workspace    workspace         vector of workspace
329    wscount           size of same    wscount           size of same
330    rlevel            function call recursion level    rlevel            function call recursion level
   recursing         regex recursive call level  
331    
332  Returns:            > 0 => number of match offset pairs placed in offsets  Returns:            > 0 => number of match offset pairs placed in offsets
333                      = 0 => offsets overflowed; longest matches are present                      = 0 => offsets overflowed; longest matches are present
# Line 392  internal_dfa_exec( Line 391  internal_dfa_exec(
391    int offsetcount,    int offsetcount,
392    int *workspace,    int *workspace,
393    int wscount,    int wscount,
394    int  rlevel,    int  rlevel)
   int  recursing)  
395  {  {
396  stateblock *active_states, *new_states, *temp_states;  stateblock *active_states, *new_states, *temp_states;
397  stateblock *next_active_state, *next_new_state;  stateblock *next_active_state, *next_new_state;
# Line 402  const uschar *ctypes, *lcc, *fcc; Line 400  const uschar *ctypes, *lcc, *fcc;
400  const uschar *ptr;  const uschar *ptr;
401  const uschar *end_code, *first_op;  const uschar *end_code, *first_op;
402    
403    dfa_recursion_info new_recursive;
404    
405  int active_count, new_count, match_count;  int active_count, new_count, match_count;
406    
407  /* Some fields in the md block are frequently referenced, so we load them into  /* Some fields in the md block are frequently referenced, so we load them into
# Line 425  wscount = (wscount - (wscount % (INTS_PE Line 425  wscount = (wscount - (wscount % (INTS_PE
425            (2 * INTS_PER_STATEBLOCK);            (2 * INTS_PER_STATEBLOCK);
426    
427  DPRINTF(("\n%.*s---------------------\n"  DPRINTF(("\n%.*s---------------------\n"
428    "%.*sCall to internal_dfa_exec f=%d r=%d\n",    "%.*sCall to internal_dfa_exec f=%d\n",
429    rlevel*2-2, SP, rlevel*2-2, SP, rlevel, recursing));    rlevel*2-2, SP, rlevel*2-2, SP, rlevel));
430    
431  ctypes = md->tables + ctypes_offset;  ctypes = md->tables + ctypes_offset;
432  lcc = md->tables + lcc_offset;  lcc = md->tables + lcc_offset;
# Line 2521  for (;;) Line 2521  for (;;)
2521            sizeof(local_offsets)/sizeof(int),    /* size of same */            sizeof(local_offsets)/sizeof(int),    /* size of same */
2522            local_workspace,                      /* workspace vector */            local_workspace,                      /* workspace vector */
2523            sizeof(local_workspace)/sizeof(int),  /* size of same */            sizeof(local_workspace)/sizeof(int),  /* size of same */
2524            rlevel,                               /* function recursion level */            rlevel);                              /* function recursion level */
           recursing);                           /* pass on regex recursion */  
2525    
2526          if (rc == PCRE_ERROR_DFA_UITEM) return rc;          if (rc == PCRE_ERROR_DFA_UITEM) return rc;
2527          if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK))          if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK))
# Line 2587  for (;;) Line 2586  for (;;)
2586            {            {
2587            int value = GET2(code, LINK_SIZE+2);            int value = GET2(code, LINK_SIZE+2);
2588            if (value != RREF_ANY) return PCRE_ERROR_DFA_UCOND;            if (value != RREF_ANY) return PCRE_ERROR_DFA_UCOND;
2589            if (recursing > 0)            if (md->recursive != NULL)
2590              { ADD_ACTIVE(state_offset + LINK_SIZE + 4, 0); }              { ADD_ACTIVE(state_offset + LINK_SIZE + 4, 0); }
2591            else { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }            else { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }
2592            }            }
# Line 2611  for (;;) Line 2610  for (;;)
2610              sizeof(local_offsets)/sizeof(int),    /* size of same */              sizeof(local_offsets)/sizeof(int),    /* size of same */
2611              local_workspace,                      /* workspace vector */              local_workspace,                      /* workspace vector */
2612              sizeof(local_workspace)/sizeof(int),  /* size of same */              sizeof(local_workspace)/sizeof(int),  /* size of same */
2613              rlevel,                               /* function recursion level */              rlevel);                              /* function recursion level */
             recursing);                           /* pass on regex recursion */  
2614    
2615            if (rc == PCRE_ERROR_DFA_UITEM) return rc;            if (rc == PCRE_ERROR_DFA_UITEM) return rc;
2616            if ((rc >= 0) ==            if ((rc >= 0) ==
# Line 2627  for (;;) Line 2625  for (;;)
2625        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
2626        case OP_RECURSE:        case OP_RECURSE:
2627          {          {
2628            dfa_recursion_info *ri;
2629          int local_offsets[1000];          int local_offsets[1000];
2630          int local_workspace[1000];          int local_workspace[1000];
2631            const uschar *callpat = start_code + GET(code, 1);
2632            int recno = (callpat == md->start_code)? 0 :
2633              GET2(callpat, 1 + LINK_SIZE);
2634          int rc;          int rc;
2635    
2636          DPRINTF(("%.*sStarting regex recursion %d\n", rlevel*2-2, SP,          DPRINTF(("%.*sStarting regex recursion\n", rlevel*2-2, SP));
2637            recursing + 1));  
2638            /* Check for repeating a recursion without advancing the subject
2639            pointer. This should catch convoluted mutual recursions. (Some simple
2640            cases are caught at compile time.) */
2641    
2642            for (ri = md->recursive; ri != NULL; ri = ri->prevrec)
2643              if (recno == ri->group_num && ptr == ri->subject_position)
2644                return PCRE_ERROR_RECURSELOOP;
2645    
2646            /* Remember this recursion and where we started it so as to
2647            catch infinite loops. */
2648    
2649            new_recursive.group_num = recno;
2650            new_recursive.subject_position = ptr;
2651            new_recursive.prevrec = md->recursive;
2652            md->recursive = &new_recursive;
2653    
2654          rc = internal_dfa_exec(          rc = internal_dfa_exec(
2655            md,                                   /* fixed match data */            md,                                   /* fixed match data */
2656            start_code + GET(code, 1),            /* this subexpression's code */            callpat,                              /* this subexpression's code */
2657            ptr,                                  /* where we currently are */            ptr,                                  /* where we currently are */
2658            (int)(ptr - start_subject),           /* start offset */            (int)(ptr - start_subject),           /* start offset */
2659            local_offsets,                        /* offset vector */            local_offsets,                        /* offset vector */
2660            sizeof(local_offsets)/sizeof(int),    /* size of same */            sizeof(local_offsets)/sizeof(int),    /* size of same */
2661            local_workspace,                      /* workspace vector */            local_workspace,                      /* workspace vector */
2662            sizeof(local_workspace)/sizeof(int),  /* size of same */            sizeof(local_workspace)/sizeof(int),  /* size of same */
2663            rlevel,                               /* function recursion level */            rlevel);                              /* function recursion level */
2664            recursing + 1);                       /* regex recurse level */  
2665            md->recursive = new_recursive.prevrec;  /* Done this recursion */
2666    
2667          DPRINTF(("%.*sReturn from regex recursion %d: rc=%d\n", rlevel*2-2, SP,          DPRINTF(("%.*sReturn from regex recursion: rc=%d\n", rlevel*2-2, SP,
2668            recursing + 1, rc));            rc));
2669    
2670          /* Ran out of internal offsets */          /* Ran out of internal offsets */
2671    
# Line 2714  for (;;) Line 2732  for (;;)
2732              sizeof(local_offsets)/sizeof(int),    /* size of same */              sizeof(local_offsets)/sizeof(int),    /* size of same */
2733              local_workspace,                      /* workspace vector */              local_workspace,                      /* workspace vector */
2734              sizeof(local_workspace)/sizeof(int),  /* size of same */              sizeof(local_workspace)/sizeof(int),  /* size of same */
2735              rlevel,                               /* function recursion level */              rlevel);                              /* function recursion level */
             recursing);                           /* pass on regex recursion */  
2736    
2737            /* Failed to match */            /* Failed to match */
2738    
# Line 2784  for (;;) Line 2801  for (;;)
2801            sizeof(local_offsets)/sizeof(int),    /* size of same */            sizeof(local_offsets)/sizeof(int),    /* size of same */
2802            local_workspace,                      /* workspace vector */            local_workspace,                      /* workspace vector */
2803            sizeof(local_workspace)/sizeof(int),  /* size of same */            sizeof(local_workspace)/sizeof(int),  /* size of same */
2804            rlevel,                               /* function recursion level */            rlevel);                              /* function recursion level */
           recursing);                           /* pass on regex recursion */  
2805    
2806          if (rc >= 0)          if (rc >= 0)
2807            {            {
# Line 3377  for (;;) Line 3393  for (;;)
3393    /* OK, now we can do the business */    /* OK, now we can do the business */
3394    
3395    md->start_used_ptr = current_subject;    md->start_used_ptr = current_subject;
3396      md->recursive = NULL;
3397    
3398    rc = internal_dfa_exec(    rc = internal_dfa_exec(
3399      md,                                /* fixed match data */      md,                                /* fixed match data */
# Line 3387  for (;;) Line 3404  for (;;)
3404      offsetcount,                       /* size of same */      offsetcount,                       /* size of same */
3405      workspace,                         /* workspace vector */      workspace,                         /* workspace vector */
3406      wscount,                           /* size of same */      wscount,                           /* size of same */
3407      0,                                 /* function recurse level */      0);                                /* function recurse level */
     0);                                /* regex recurse level */  
3408    
3409    /* Anything other than "no match" means we are done, always; otherwise, carry    /* Anything other than "no match" means we are done, always; otherwise, carry
3410    on only if not anchored. */    on only if not anchored. */

Legend:
Removed from v.637  
changed lines
  Added in v.642

  ViewVC Help
Powered by ViewVC 1.1.5