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

Diff of /code/trunk/pcre_exec.c

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

revision 882 by ph10, Sun Jan 15 18:45:27 2012 UTC revision 901 by ph10, Sat Jan 21 15:47:59 2012 UTC
# Line 332  argument of match(), which never changes Line 332  argument of match(), which never changes
332    {\    {\
333    heapframe *oldframe = frame;\    heapframe *oldframe = frame;\
334    frame = oldframe->Xprevframe;\    frame = oldframe->Xprevframe;\
335    (PUBL(stack_free))(oldframe);\    if (oldframe != &frame_zero) (PUBL(stack_free))(oldframe);\
336    if (frame != NULL)\    if (frame != NULL)\
337      {\      {\
338      rrc = ra;\      rrc = ra;\
# Line 485  BOOL caseless; Line 485  BOOL caseless;
485  int condcode;  int condcode;
486    
487  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
488  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame". We set up the top-level
489  heap storage. Set up the top-level frame here; others are obtained from the  frame on the stack here; subsequent instantiations are obtained from the heap
490  heap whenever RMATCH() does a "recursion". See the macro definitions above. */  whenever RMATCH() does a "recursion". See the macro definitions above. Putting
491    the top-level on the stack rather than malloc-ing them all gives a performance
492    boost in many cases where there is not much "recursion". */
493    
494  #ifdef NO_RECURSE  #ifdef NO_RECURSE
495  heapframe *frame = (heapframe *)(PUBL(stack_malloc))(sizeof(heapframe));  heapframe frame_zero;
496  if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);  heapframe *frame = &frame_zero;
497  frame->Xprevframe = NULL;            /* Marks the top level */  frame->Xprevframe = NULL;            /* Marks the top level */
498    
499  /* Copy in the original argument variables */  /* Copy in the original argument variables */
# Line 613  int save_offset1, save_offset2, save_off Line 615  int save_offset1, save_offset2, save_off
615  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
616    
617  eptrblock newptrb;  eptrblock newptrb;
618    
619    /* There is a special fudge for calling match() in a way that causes it to
620    measure the size of its basic stack frame when the stack is being used for
621    recursion. The second argument (ecode) being NULL triggers this behaviour. It
622    cannot normally ever be NULL. The return is the negated value of the frame
623    size. */
624    
625    if (ecode == NULL)
626      {
627      if (rdepth == 0)
628        return match((PCRE_PUCHAR)&rdepth, NULL, NULL, 0, NULL, NULL, 1);
629      else
630        {
631        int len = (char *)&rdepth - (char *)eptr;
632        return (len > 0)? -len : len;
633        }
634      }
635  #endif     /* NO_RECURSE */  #endif     /* NO_RECURSE */
636    
637  /* To save space on the stack and in the heap frame, I have doubled up on some  /* To save space on the stack and in the heap frame, I have doubled up on some
# Line 1530  for (;;) Line 1549  for (;;)
1549    
1550      case OP_ASSERT:      case OP_ASSERT:
1551      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1552        save_mark = md->mark;
1553      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1554        {        {
1555        condassert = TRUE;        condassert = TRUE;
# Line 1551  for (;;) Line 1571  for (;;)
1571    
1572        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1573        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1574          md->mark = save_mark;
1575        }        }
1576      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1577    
# Line 1574  for (;;) Line 1595  for (;;)
1595    
1596      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1597      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1598        save_mark = md->mark;
1599      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1600        {        {
1601        condassert = TRUE;        condassert = TRUE;
# Line 1584  for (;;) Line 1606  for (;;)
1606      do      do
1607        {        {
1608        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);
1609          md->mark = save_mark;
1610        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);
1611        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1612          {          {
# Line 3715  for (;;) Line 3738  for (;;)
3738              if (fc == d || foc == d) break;              if (fc == d || foc == d) break;
3739              eptr += len;              eptr += len;
3740              }              }
3741          if (possessive) continue;            if (possessive) continue;
3742          for(;;)            for(;;)
3743              {              {
3744              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);
3745              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
# Line 6184  PCRE_PUCHAR req_char_ptr = start_match - Line 6207  PCRE_PUCHAR req_char_ptr = start_match -
6207  const pcre_study_data *study;  const pcre_study_data *study;
6208  const REAL_PCRE *re = (const REAL_PCRE *)argument_re;  const REAL_PCRE *re = (const REAL_PCRE *)argument_re;
6209    
6210    /* Check for the special magic call that measures the size of the stack used
6211    per recursive call of match(). */
6212    
6213    if (re == NULL && extra_data == NULL && subject == NULL && length == -999 &&
6214        start_offset == -999)
6215    #ifdef NO_RECURSE
6216      return -sizeof(heapframe);
6217    #else
6218      return match(NULL, NULL, NULL, 0, NULL, NULL, 0);
6219    #endif
6220    
6221  /* Plausibility checks */  /* Plausibility checks */
6222    
6223  if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;  if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;
6224  if (re == NULL || subject == NULL ||  if (re == NULL || subject == NULL || (offsets == NULL && offsetcount > 0))
6225     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;    return PCRE_ERROR_NULL;
6226  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
6227  if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;  if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
6228    
6229    /* Check that the first field in the block is the magic number. If it is not,
6230    return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to
6231    REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which
6232    means that the pattern is likely compiled with different endianness. */
6233    
6234    if (re->magic_number != MAGIC_NUMBER)
6235      return re->magic_number == REVERSED_MAGIC_NUMBER?
6236        PCRE_ERROR_BADENDIANNESS:PCRE_ERROR_BADMAGIC;
6237    if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
6238    
6239  /* These two settings are used in the code for checking a UTF-8 string that  /* These two settings are used in the code for checking a UTF-8 string that
6240  follows immediately afterwards. Other values in the md block are used only  follows immediately afterwards. Other values in the md block are used only
6241  during "normal" pcre_exec() processing, not when the JIT support is in use,  during "normal" pcre_exec() processing, not when the JIT support is in use,
# Line 6291  in other programs later. */ Line 6335  in other programs later. */
6335    
6336  if (tables == NULL) tables = PRIV(default_tables);  if (tables == NULL) tables = PRIV(default_tables);
6337    
 /* Check that the first field in the block is the magic number. If it is not,  
 return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to  
 REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which  
 means that the pattern is likely compiled with different endianness. */  
   
 if (re->magic_number != MAGIC_NUMBER)  
   return re->magic_number == REVERSED_MAGIC_NUMBER?  
     PCRE_ERROR_BADENDIANNESS:PCRE_ERROR_BADMAGIC;  
 if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;  
   
6338  /* Set up other data */  /* Set up other data */
6339    
6340  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;

Legend:
Removed from v.882  
changed lines
  Added in v.901

  ViewVC Help
Powered by ViewVC 1.1.5