/[pcre]/code/tags/pcre-8.37/pcre_jit_compile.c
ViewVC logotype

Diff of /code/tags/pcre-8.37/pcre_jit_compile.c

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

revision 1275 by zherczeg, Sun Mar 10 05:32:10 2013 UTC revision 1415 by zherczeg, Sun Dec 22 20:47:08 2013 UTC
# Line 168  typedef struct jit_arguments { Line 168  typedef struct jit_arguments {
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169    void *callout_data;    void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171      pcre_uint32 limit_match;
172    int real_offset_count;    int real_offset_count;
173    int offset_count;    int offset_count;
   int call_limit;  
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 182  typedef struct executable_functions { Line 182  typedef struct executable_functions {
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 202  enum frame_types { Line 203  enum frame_types {
203  };  };
204    
205  enum control_types {  enum control_types {
206    type_commit = 0,    type_mark = 0,
207    type_prune = 1,    type_then_trap = 1
   type_skip = 2  
208  };  };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 227  typedef struct backtrack_common { Line 227  typedef struct backtrack_common {
227  typedef struct assert_backtrack {  typedef struct assert_backtrack {
228    backtrack_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int private_data_ptr;    int private_data_ptr;
# Line 248  typedef struct bracket_backtrack { Line 248  typedef struct bracket_backtrack {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_backtrack *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 283  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
# Line 291  typedef struct recurse_backtrack { Line 291  typedef struct recurse_backtrack {
291    BOOL inlined_pattern;    BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294  #define MAX_RANGE_SIZE 6  #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 4
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312    /* The sljit ceneric compiler. */    /* The sljit ceneric compiler. */
# Line 299  typedef struct compiler_common { Line 314  typedef struct compiler_common {
314    /* First byte code. */    /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
316    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
317    int *private_data_ptrs;    sljit_si *private_data_ptrs;
318    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
319    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
320      /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
325    int cbra_ptr;    int cbra_ptr;
326    /* Output vector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
# Line 330  typedef struct compiler_common { Line 349  typedef struct compiler_common {
349    sljit_sw lcc;    sljit_sw lcc;
350    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352    /* \K is in the pattern. */    /* \K is found in the pattern. */
353    BOOL has_set_som;    BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358    /* Needs to know the start position anytime. */    /* Needs to know the start position anytime. */
359    BOOL needs_start_ptr;    BOOL needs_start_ptr;
360    /* Currently in recurse or assert. */    /* Currently in recurse or negative assert. */
361    BOOL local_exit;    BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364    /* Newline control. */    /* Newline control. */
365    int nltype;    int nltype;
366    int newline;    int newline;
# Line 346  typedef struct compiler_common { Line 371  typedef struct compiler_common {
371    sljit_sw ctypes;    sljit_sw ctypes;
372    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
373    /* Named capturing brackets. */    /* Named capturing brackets. */
374    sljit_uw name_table;    pcre_uchar *name_table;
375    sljit_sw name_count;    sljit_sw name_count;
376    sljit_sw name_entry_size;    sljit_sw name_entry_size;
377    
# Line 360  typedef struct compiler_common { Line 385  typedef struct compiler_common {
385    recurse_entry *currententry;    recurse_entry *currententry;
386    jump_list *partialmatch;    jump_list *partialmatch;
387    jump_list *quit;    jump_list *quit;
388      jump_list *positive_assert_quit;
389    jump_list *forced_quit;    jump_list *forced_quit;
390    jump_list *accept;    jump_list *accept;
391    jump_list *calllimit;    jump_list *calllimit;
# Line 438  typedef struct compare_context { Line 464  typedef struct compare_context {
464  #define STACK_TOP     SLJIT_SCRATCH_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Local space layout. */  /* Local space layout. */
# Line 449  typedef struct compare_context { Line 475  typedef struct compare_context {
475  #define POSSESSIVE0      (2 * sizeof(sljit_sw))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_sw))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (4 * sizeof(sljit_sw))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
483  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 509  return cc; Line 535  return cc;
535    
536  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
537   next_opcode   next_opcode
538   get_private_data_length   check_opcode_types
539   set_private_data_ptrs   set_private_data_ptrs
540   get_framesize   get_framesize
541   init_frame   init_frame
542   get_private_data_length_for_copy   get_private_data_copy_length
543   copy_private_data   copy_private_data
544   compile_matchingpath   compile_matchingpath
545   compile_backtrackingpath   compile_backtrackingpath
# Line 559  switch(*cc) Line 585  switch(*cc)
585    case OP_CRMINQUERY:    case OP_CRMINQUERY:
586    case OP_CRRANGE:    case OP_CRRANGE:
587    case OP_CRMINRANGE:    case OP_CRMINRANGE:
588      case OP_CRPOSSTAR:
589      case OP_CRPOSPLUS:
590      case OP_CRPOSQUERY:
591      case OP_CRPOSRANGE:
592    case OP_CLASS:    case OP_CLASS:
593    case OP_NCLASS:    case OP_NCLASS:
594    case OP_REF:    case OP_REF:
595    case OP_REFI:    case OP_REFI:
596      case OP_DNREF:
597      case OP_DNREFI:
598    case OP_RECURSE:    case OP_RECURSE:
599    case OP_CALLOUT:    case OP_CALLOUT:
600    case OP_ALT:    case OP_ALT:
# Line 588  switch(*cc) Line 620  switch(*cc)
620    case OP_SCBRAPOS:    case OP_SCBRAPOS:
621    case OP_SCOND:    case OP_SCOND:
622    case OP_CREF:    case OP_CREF:
623    case OP_NCREF:    case OP_DNCREF:
624    case OP_RREF:    case OP_RREF:
625    case OP_NRREF:    case OP_DNRREF:
626    case OP_DEF:    case OP_DEF:
627    case OP_BRAZERO:    case OP_BRAZERO:
628    case OP_BRAMINZERO:    case OP_BRAMINZERO:
629    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
630    case OP_PRUNE:    case OP_PRUNE:
631    case OP_SKIP:    case OP_SKIP:
632      case OP_THEN:
633    case OP_COMMIT:    case OP_COMMIT:
634    case OP_FAIL:    case OP_FAIL:
635    case OP_ACCEPT:    case OP_ACCEPT:
# Line 696  switch(*cc) Line 729  switch(*cc)
729    
730    case OP_MARK:    case OP_MARK:
731    case OP_PRUNE_ARG:    case OP_PRUNE_ARG:
732      case OP_SKIP_ARG:
733      case OP_THEN_ARG:
734    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
735    
736    default:    default:
737      /* All opcodes are supported now! */
738      SLJIT_ASSERT_STOP();
739    return NULL;    return NULL;
740    }    }
741  }  }
742    
743  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
     case OP_MINSTAR: \  
     case OP_MINPLUS: \  
     case OP_QUERY: \  
     case OP_MINQUERY: \  
     case OP_MINSTARI: \  
     case OP_MINPLUSI: \  
     case OP_QUERYI: \  
     case OP_MINQUERYI: \  
     case OP_NOTMINSTAR: \  
     case OP_NOTMINPLUS: \  
     case OP_NOTQUERY: \  
     case OP_NOTMINQUERY: \  
     case OP_NOTMINSTARI: \  
     case OP_NOTMINPLUSI: \  
     case OP_NOTQUERYI: \  
     case OP_NOTMINQUERYI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2A \  
     case OP_STAR: \  
     case OP_PLUS: \  
     case OP_STARI: \  
     case OP_PLUSI: \  
     case OP_NOTSTAR: \  
     case OP_NOTPLUS: \  
     case OP_NOTSTARI: \  
     case OP_NOTPLUSI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2B \  
     case OP_UPTO: \  
     case OP_MINUPTO: \  
     case OP_UPTOI: \  
     case OP_MINUPTOI: \  
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \  
     case OP_TYPEMINSTAR: \  
     case OP_TYPEMINPLUS: \  
     case OP_TYPEQUERY: \  
     case OP_TYPEMINQUERY:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \  
     case OP_TYPESTAR: \  
     case OP_TYPEPLUS:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \  
     case OP_TYPEUPTO: \  
     case OP_TYPEMINUPTO:  
   
 static int get_class_iterator_size(pcre_uchar *cc)  
 {  
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
744  {  {
745  int private_data_length = 0;  int count;
746  pcre_uchar *alternative;  pcre_uchar *slot;
 pcre_uchar *name;  
 pcre_uchar *end = NULL;  
 int space, size, i;  
 pcre_uint32 bracketlen;  
747    
748  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
749  while (cc < ccend)  while (cc < ccend)
750    {    {
   space = 0;  
   size = 0;  
   bracketlen = 0;  
751    switch(*cc)    switch(*cc)
752      {      {
753      case OP_SET_SOM:      case OP_SET_SOM:
# Line 808  while (cc < ccend) Line 761  while (cc < ccend)
761      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
762      break;      break;
763    
     case OP_ASSERT:  
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
764      case OP_CBRAPOS:      case OP_CBRAPOS:
765      case OP_SCBRAPOS:      case OP_SCBRAPOS:
     private_data_length += sizeof(sljit_sw);  
766      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
767      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
768      break;      break;
769    
770      case OP_COND:      case OP_COND:
# Line 833  while (cc < ccend) Line 772  while (cc < ccend)
772      /* Only AUTO_CALLOUT can insert this opcode. We do      /* Only AUTO_CALLOUT can insert this opcode. We do
773         not intend to support this case. */         not intend to support this case. */
774      if (cc[1 + LINK_SIZE] == OP_CALLOUT)      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
775        return -1;        return FALSE;
776        cc += 1 + LINK_SIZE;
     if (*cc == OP_COND)  
       {  
       /* Might be a hidden SCOND. */  
       alternative = cc + GET(cc, 1);  
       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
         private_data_length += sizeof(sljit_sw);  
       }  
     else  
       private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
777      break;      break;
778    
779      case OP_CREF:      case OP_CREF:
780      i = GET2(cc, 1);      common->optimized_cbracket[GET2(cc, 1)] = 0;
     common->optimized_cbracket[i] = 0;  
781      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
782      break;      break;
783    
784      case OP_NCREF:      case OP_DNREF:
785      bracketlen = GET2(cc, 1);      case OP_DNREFI:
786      name = (pcre_uchar *)common->name_table;      case OP_DNCREF:
787      alternative = name;      count = GET2(cc, 1 + IMM2_SIZE);
788      for (i = 0; i < common->name_count; i++)      slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
789        while (count-- > 0)
790        {        {
791        if (GET2(name, 0) == bracketlen) break;        common->optimized_cbracket[GET2(slot, 0)] = 0;
792        name += common->name_entry_size;        slot += common->name_entry_size;
793        }        }
794      SLJIT_ASSERT(i != common->name_count);      cc += 1 + 2 * IMM2_SIZE;
   
     for (i = 0; i < common->name_count; i++)  
       {  
       if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)  
         common->optimized_cbracket[GET2(alternative, 0)] = 0;  
       alternative += common->name_entry_size;  
       }  
     bracketlen = 0;  
     cc += 1 + IMM2_SIZE;  
795      break;      break;
796    
     case OP_BRA:  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRA:  
     case OP_SCBRA:  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_1  
     space = 1;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2A  
     space = 2;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2B  
     space = 2;  
     size = -(2 + IMM2_SIZE);  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_1  
     space = 1;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  
     if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  
       space = 2;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  
     if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)  
       space = 2;  
     size = 1 + IMM2_SIZE;  
     break;  
   
     case OP_CLASS:  
     case OP_NCLASS:  
     size += 1 + 32 / sizeof(pcre_uchar);  
     space = get_class_iterator_size(cc + size);  
     break;  
   
 #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  
     case OP_XCLASS:  
     size = GET(cc, 1);  
     space = get_class_iterator_size(cc + size);  
     break;  
 #endif  
   
797      case OP_RECURSE:      case OP_RECURSE:
798      /* Set its value only once. */      /* Set its value only once. */
799      if (common->recursive_head_ptr == 0)      if (common->recursive_head_ptr == 0)
# Line 947  while (cc < ccend) Line 813  while (cc < ccend)
813      cc += 2 + 2 * LINK_SIZE;      cc += 2 + 2 * LINK_SIZE;
814      break;      break;
815    
816        case OP_THEN_ARG:
817        common->has_then = TRUE;
818        common->control_head_ptr = 1;
819        /* Fall through. */
820    
821      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
822      common->needs_start_ptr = TRUE;      common->needs_start_ptr = TRUE;
     common->control_head_ptr = 1;  
823      /* Fall through. */      /* Fall through. */
824    
825      case OP_MARK:      case OP_MARK:
# Line 961  while (cc < ccend) Line 831  while (cc < ccend)
831      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
832      break;      break;
833    
834        case OP_THEN:
835        common->has_then = TRUE;
836        common->control_head_ptr = 1;
837        /* Fall through. */
838    
839      case OP_PRUNE:      case OP_PRUNE:
840      case OP_SKIP:      case OP_SKIP:
841      common->needs_start_ptr = TRUE;      common->needs_start_ptr = TRUE;
842      /* Fall through. */      cc += 1;
843        break;
844    
845      case OP_COMMIT:      case OP_SKIP_ARG:
846      common->control_head_ptr = 1;      common->control_head_ptr = 1;
847      cc += 1;      common->has_skip_arg = TRUE;
848        cc += 1 + 2 + cc[1];
849      break;      break;
850    
851      default:      default:
852      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
853      if (cc == NULL)      if (cc == NULL)
854        return -1;        return FALSE;
855      break;      break;
856      }      }
857      }
858    return TRUE;
859    }
860    
861    if (space > 0 && cc >= end)  static int get_class_iterator_size(pcre_uchar *cc)
862      private_data_length += sizeof(sljit_sw) * space;  {
863    switch(*cc)
864      {
865      case OP_CRSTAR:
866      case OP_CRPLUS:
867      return 2;
868    
869    if (size != 0)    case OP_CRMINSTAR:
870      case OP_CRMINPLUS:
871      case OP_CRQUERY:
872      case OP_CRMINQUERY:
873      return 1;
874    
875      case OP_CRRANGE:
876      case OP_CRMINRANGE:
877      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
878        return 0;
879      return 2;
880    
881      default:
882      return 0;
883      }
884    }
885    
886    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
887    {
888    pcre_uchar *end = bracketend(begin);
889    pcre_uchar *next;
890    pcre_uchar *next_end;
891    pcre_uchar *max_end;
892    pcre_uchar type;
893    sljit_sw length = end - begin;
894    int min, max, i;
895    
896    /* Detect fixed iterations first. */
897    if (end[-(1 + LINK_SIZE)] != OP_KET)
898      return FALSE;
899    
900    /* Already detected repeat. */
901    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
902      return TRUE;
903    
904    next = end;
905    min = 1;
906    while (1)
907      {
908      if (*next != *begin)
909        break;
910      next_end = bracketend(next);
911      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
912        break;
913      next = next_end;
914      min++;
915      }
916    
917    if (min == 2)
918      return FALSE;
919    
920    max = 0;
921    max_end = next;
922    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
923      {
924      type = *next;
925      while (1)
926      {      {
927      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
928        {        break;
929        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
930  #ifdef SUPPORT_UTF      if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
931        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
932  #endif      next = next_end;
933        }      max++;
     else  
       cc += size;  
934      }      }
935    
936    if (bracketlen != 0)    if (next[0] == type && next[1] == *begin && max >= 1)
937      {      {
938      if (cc >= end)      next_end = bracketend(next + 1);
939        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
940        {        {
941        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
942        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
943          end = NULL;            break;
944    
945          if (i == max)
946            {
947            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
948            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
949            /* +2 the original and the last. */
950            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
951            if (min == 1)
952              return TRUE;
953            min--;
954            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
955            }
956        }        }
     cc += bracketlen;  
957      }      }
958    }    }
959  return private_data_length;  
960    if (min >= 3)
961      {
962      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
963      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
964      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
965      return TRUE;
966      }
967    
968    return FALSE;
969  }  }
970    
971  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
972        case OP_MINSTAR: \
973        case OP_MINPLUS: \
974        case OP_QUERY: \
975        case OP_MINQUERY: \
976        case OP_MINSTARI: \
977        case OP_MINPLUSI: \
978        case OP_QUERYI: \
979        case OP_MINQUERYI: \
980        case OP_NOTMINSTAR: \
981        case OP_NOTMINPLUS: \
982        case OP_NOTQUERY: \
983        case OP_NOTMINQUERY: \
984        case OP_NOTMINSTARI: \
985        case OP_NOTMINPLUSI: \
986        case OP_NOTQUERYI: \
987        case OP_NOTMINQUERYI:
988    
989    #define CASE_ITERATOR_PRIVATE_DATA_2A \
990        case OP_STAR: \
991        case OP_PLUS: \
992        case OP_STARI: \
993        case OP_PLUSI: \
994        case OP_NOTSTAR: \
995        case OP_NOTPLUS: \
996        case OP_NOTSTARI: \
997        case OP_NOTPLUSI:
998    
999    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1000        case OP_UPTO: \
1001        case OP_MINUPTO: \
1002        case OP_UPTOI: \
1003        case OP_MINUPTOI: \
1004        case OP_NOTUPTO: \
1005        case OP_NOTMINUPTO: \
1006        case OP_NOTUPTOI: \
1007        case OP_NOTMINUPTOI:
1008    
1009    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1010        case OP_TYPEMINSTAR: \
1011        case OP_TYPEMINPLUS: \
1012        case OP_TYPEQUERY: \
1013        case OP_TYPEMINQUERY:
1014    
1015    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1016        case OP_TYPESTAR: \
1017        case OP_TYPEPLUS:
1018    
1019    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1020        case OP_TYPEUPTO: \
1021        case OP_TYPEMINUPTO:
1022    
1023    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1024  {  {
1025  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1026  pcre_uchar *alternative;  pcre_uchar *alternative;
1027  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1028    int private_data_ptr = *private_data_start;
1029  int space, size, bracketlen;  int space, size, bracketlen;
1030    
1031  while (cc < ccend)  while (cc < ccend)
# Line 1020  while (cc < ccend) Line 1033  while (cc < ccend)
1033    space = 0;    space = 0;
1034    size = 0;    size = 0;
1035    bracketlen = 0;    bracketlen = 0;
1036      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1037        return;
1038    
1039      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1040        if (detect_repeat(common, cc))
1041          {
1042          /* These brackets are converted to repeats, so no global
1043          based single character repeat is allowed. */
1044          if (cc >= end)
1045            end = bracketend(cc);
1046          }
1047    
1048    switch(*cc)    switch(*cc)
1049      {      {
1050        case OP_KET:
1051        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1052          {
1053          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1054          private_data_ptr += sizeof(sljit_sw);
1055          cc += common->private_data_ptrs[cc + 1 - common->start];
1056          }
1057        cc += 1 + LINK_SIZE;
1058        break;
1059    
1060      case OP_ASSERT:      case OP_ASSERT:
1061      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1062      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1115  while (cc < ccend) Line 1150  while (cc < ccend)
1150      break;      break;
1151      }      }
1152    
1153      /* Character iterators, which are not inside a repeated bracket,
1154         gets a private slot instead of allocating it on the stack. */
1155    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1156      {      {
1157      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
# Line 1145  while (cc < ccend) Line 1182  while (cc < ccend)
1182      cc += bracketlen;      cc += bracketlen;
1183      }      }
1184    }    }
1185    *private_data_start = private_data_ptr;
1186  }  }
1187    
1188  /* Returns with a frame_types (always < 0) if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1189  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1190  {  {
 pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);  
1191  int length = 0;  int length = 0;
1192  int possessive = 0;  int possessive = 0;
1193  BOOL stack_restore = FALSE;  BOOL stack_restore = FALSE;
# Line 1159  BOOL setmark_found = recursive; Line 1196  BOOL setmark_found = recursive;
1196  /* The last capture is a local variable even for recursions. */  /* The last capture is a local variable even for recursions. */
1197  BOOL capture_last_found = FALSE;  BOOL capture_last_found = FALSE;
1198    
1199  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1200    SLJIT_ASSERT(common->control_head_ptr != 0);
1201    *needs_control_head = TRUE;
1202    #else
1203    *needs_control_head = FALSE;
1204    #endif
1205    
1206    if (ccend == NULL)
1207    {    {
1208    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1209    /* This is correct regardless of common->capture_last_ptr. */    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1210    capture_last_found = TRUE;      {
1211        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1212        /* This is correct regardless of common->capture_last_ptr. */
1213        capture_last_found = TRUE;
1214        }
1215      cc = next_opcode(common, cc);
1216    }    }
1217    
 cc = next_opcode(common, cc);  
1218  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1219  while (cc < ccend)  while (cc < ccend)
1220    switch(*cc)    switch(*cc)
# Line 1184  while (cc < ccend) Line 1232  while (cc < ccend)
1232    
1233      case OP_MARK:      case OP_MARK:
1234      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
1235        case OP_THEN_ARG:
1236      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1237      stack_restore = TRUE;      stack_restore = TRUE;
1238      if (!setmark_found)      if (!setmark_found)
# Line 1191  while (cc < ccend) Line 1240  while (cc < ccend)
1240        length += 2;        length += 2;
1241        setmark_found = TRUE;        setmark_found = TRUE;
1242        }        }
1243        if (common->control_head_ptr != 0)
1244          *needs_control_head = TRUE;
1245      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1246      break;      break;
1247    
# Line 1310  if (length > 0) Line 1361  if (length > 0)
1361  return stack_restore ? no_frame : no_stack;  return stack_restore ? no_frame : no_stack;
1362  }  }
1363    
1364  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, int stackpos, int stacktop, BOOL recursive)
1365  {  {
1366  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);  
1367  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1368  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1369  /* The last capture is a local variable even for recursions. */  /* The last capture is a local variable even for recursions. */
# Line 1325  SLJIT_UNUSED_ARG(stacktop); Line 1375  SLJIT_UNUSED_ARG(stacktop);
1375  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1376    
1377  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1378  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1379    cc = next_opcode(common, cc);    {
1380      ccend = bracketend(cc) - (1 + LINK_SIZE);
1381      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1382        cc = next_opcode(common, cc);
1383      }
1384    
1385  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1386  while (cc < ccend)  while (cc < ccend)
1387    switch(*cc)    switch(*cc)
# Line 1347  while (cc < ccend) Line 1402  while (cc < ccend)
1402    
1403      case OP_MARK:      case OP_MARK:
1404      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
1405        case OP_THEN_ARG:
1406      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1407      if (!setmark_found)      if (!setmark_found)
1408        {        {
# Line 1427  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st Line 1483  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st
1483  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1484  }  }
1485    
1486  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head)
1487  {  {
1488  int private_data_length = common->control_head_ptr ? 3 : 2;  int private_data_length = needs_control_head ? 3 : 2;
1489  int size;  int size;
1490  pcre_uchar *alternative;  pcre_uchar *alternative;
1491  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1438  while (cc < ccend) Line 1494  while (cc < ccend)
1494    size = 0;    size = 0;
1495    switch(*cc)    switch(*cc)
1496      {      {
1497        case OP_KET:
1498        if (PRIVATE_DATA(cc) != 0)
1499          private_data_length++;
1500        cc += 1 + LINK_SIZE;
1501        break;
1502    
1503      case OP_ASSERT:      case OP_ASSERT:
1504      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1505      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1542  return private_data_length; Line 1604  return private_data_length;
1604  }  }
1605    
1606  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1607    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1608  {  {
1609  DEFINE_COMPILER;  DEFINE_COMPILER;
1610  int srcw[2];  int srcw[2];
# Line 1563  stacktop = STACK(stacktop - 1); Line 1625  stacktop = STACK(stacktop - 1);
1625    
1626  if (!save)  if (!save)
1627    {    {
1628    stackptr += (common->control_head_ptr ? 2 : 1) * sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1629    if (stackptr < stacktop)    if (stackptr < stacktop)
1630      {      {
1631      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
# Line 1588  do Line 1650  do
1650      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1651      count = 1;      count = 1;
1652      srcw[0] = common->recursive_head_ptr;      srcw[0] = common->recursive_head_ptr;
1653      if (common->control_head_ptr != 0)      if (needs_control_head)
1654        {        {
1655          SLJIT_ASSERT(common->control_head_ptr != 0);
1656        count = 2;        count = 2;
1657        srcw[1] = common->control_head_ptr;        srcw[1] = common->control_head_ptr;
1658        }        }
# Line 1605  do Line 1668  do
1668    
1669      switch(*cc)      switch(*cc)
1670        {        {
1671          case OP_KET:
1672          if (PRIVATE_DATA(cc) != 0)
1673            {
1674            count = 1;
1675            srcw[0] = PRIVATE_DATA(cc);
1676            }
1677          cc += 1 + LINK_SIZE;
1678          break;
1679    
1680        case OP_ASSERT:        case OP_ASSERT:
1681        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1682        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1851  if (save) Line 1923  if (save)
1923  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1924  }  }
1925    
1926    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1927    {
1928    pcre_uchar *end = bracketend(cc);
1929    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1930    
1931    /* Assert captures then. */
1932    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1933      current_offset = NULL;
1934    /* Conditional block does not. */
1935    if (*cc == OP_COND || *cc == OP_SCOND)
1936      has_alternatives = FALSE;
1937    
1938    cc = next_opcode(common, cc);
1939    if (has_alternatives)
1940      current_offset = common->then_offsets + (cc - common->start);
1941    
1942    while (cc < end)
1943      {
1944      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1945        cc = set_then_offsets(common, cc, current_offset);
1946      else
1947        {
1948        if (*cc == OP_ALT && has_alternatives)
1949          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1950        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1951          *current_offset = 1;
1952        cc = next_opcode(common, cc);
1953        }
1954      }
1955    
1956    return end;
1957    }
1958    
1959  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1960  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1961  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1914  while (list_item) Line 2019  while (list_item)
2019  common->stubs = NULL;  common->stubs = NULL;
2020  }  }
2021    
2022  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2023  {  {
2024  DEFINE_COMPILER;  DEFINE_COMPILER;
2025    
2026  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2027  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2028  }  }
2029    
# Line 1998  else Line 2103  else
2103  OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2104  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2105    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2106  SLJIT_ASSERT(common->control_head_ptr != 0);  if (common->control_head_ptr != 0)
2107  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2108  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2109  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2110  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2111  }  }
2112    
2113  static sljit_sw do_check_control_chain(sljit_sw *current)  static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2114  {  {
2115  sljit_sw return_value = 0;  while (current != NULL)
   
 SLJIT_ASSERT(current != NULL);  
 do  
2116    {    {
2117    switch (current[-2])    switch (current[-2])
2118      {      {
2119      case type_commit:      case type_then_trap:
     /* Commit overwrites all. */  
     return -1;  
   
     case type_prune:  
2120      break;      break;
2121    
2122      case type_skip:      case type_mark:
2123      /* Overwrites prune, but not other skips. */      if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2124      if (return_value == 0)        return current[-4];
       return_value = current[-3];  
2125      break;      break;
2126    
2127      default:      default:
# Line 2033  do Line 2130  do
2130      }      }
2131    current = (sljit_sw*)current[-1];    current = (sljit_sw*)current[-1];
2132    }    }
2133  while (current != NULL);  return -1;
 return return_value;  
2134  }  }
2135    
2136  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
# Line 2106  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJI Line 2202  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJI
2202  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2203    
2204  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2205  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2206  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2207  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2208  #endif  #endif
# Line 2274  return (bit < 256) ? ((0 << 8) | bit) : Line 2370  return (bit < 256) ? ((0 << 8) | bit) :
2370    
2371  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2372  {  {
2373  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2374  DEFINE_COMPILER;  DEFINE_COMPILER;
2375  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2376    
# Line 3110  if (firstline) Line 3206  if (firstline)
3206    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3207  }  }
3208    
3209  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3210    
3211  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3212  {  {
3213  DEFINE_COMPILER;  DEFINE_COMPILER;
3214  struct sljit_label *start;  struct sljit_label *start;
3215  struct sljit_jump *quit;  struct sljit_jump *quit;
3216  struct sljit_jump *found = NULL;  struct sljit_jump *found = NULL;
3217  jump_list *matches = NULL;  jump_list *matches = NULL;
 pcre_uint8 inverted_start_bits[32];  
 int i;  
3218  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3219  struct sljit_jump *jump;  struct sljit_jump *jump;
3220  #endif  #endif
3221    
 for (i = 0; i < 32; ++i)  
   inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);  
   
3222  if (firstline)  if (firstline)
3223    {    {
3224    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 3143  if (common->utf) Line 3234  if (common->utf)
3234    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3235  #endif  #endif
3236    
3237  if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))  if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3238    {    {
3239  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3240    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
# Line 3152  if (!check_class_ranges(common, inverted Line 3243  if (!check_class_ranges(common, inverted
3243  #endif  #endif
3244    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3245    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3246    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3247    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3248    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3249    found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
# Line 3412  sljit_emit_fast_return(compiler, SLJIT_M Line 3503  sljit_emit_fast_return(compiler, SLJIT_M
3503  static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)  static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3504  {  {
3505  DEFINE_COMPILER;  DEFINE_COMPILER;
 struct sljit_jump *jump;  
3506    
3507  if (ranges[0] < 0)  if (ranges[0] < 0 || ranges[0] > 4)
3508    return FALSE;    return FALSE;
3509    
3510    /* No character is accepted. */
3511    if (ranges[0] == 0 && ranges[1] == 0)
3512      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3513    
3514    if (readch)
3515      read_char(common);
3516    
3517  switch(ranges[0])  switch(ranges[0])
3518    {    {
3519      case 0:
3520      /* When ranges[1] != 0, all characters are accepted. */
3521      return TRUE;
3522    
3523    case 1:    case 1:
   if (readch)  
     read_char(common);  
3524    add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));    add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3525    return TRUE;    return TRUE;
3526    
3527    case 2:    case 2:
3528    if (readch)    if (ranges[2] + 1 != ranges[3])
3529      read_char(common);      {
3530    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3531    add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3532        }
3533      else
3534        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3535    return TRUE;    return TRUE;
3536    
3537    case 4:    case 3:
3538    if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])    if (ranges[1] != 0)
3539      {      {
3540      if (readch)      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3541        read_char(common);      if (ranges[2] + 1 != ranges[3])
     if (ranges[1] != 0)  
3542        {        {
3543        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3544        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3545        }        }
3546      else      else
3547          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3548        return TRUE;
3549        }
3550    
3551      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2]));
3552      if (ranges[3] + 1 != ranges[4])
3553        {
3554        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3]);
3555        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3556        }
3557      else
3558        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3]));
3559      return TRUE;
3560    
3561      case 4:
3562      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4])
3563          && (ranges[2] | (ranges[4] - ranges[2])) == ranges[4]
3564          && is_powerof2(ranges[4] - ranges[2]))
3565        {
3566        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3567        if (ranges[4] + 1 != ranges[5])
3568        {        {
3569        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3570        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
       JUMPHERE(jump);  
3571        }        }
3572        else
3573          add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3574      return TRUE;      return TRUE;
3575      }      }
3576    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))  
3577      if (ranges[1] != 0)
3578      {      {
3579      if (readch)      if (ranges[2] + 1 != ranges[3])
3580        read_char(common);        {
3581      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3582      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3583      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));        ranges[4] -= ranges[2];
3584          ranges[5] -= ranges[2];
3585          }
3586        else
3587          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3588    
3589        if (ranges[4] + 1 != ranges[5])
3590          {
3591          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3592          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3593          }
3594        else
3595          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3596      return TRUE;      return TRUE;
3597      }      }
3598    return FALSE;  
3599      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3600      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[2]));
3601      if (ranges[3] + 1 != ranges[4])
3602        {
3603        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]);
3604        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3605        }
3606      else
3607        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3608      return TRUE;
3609    
3610    default:    default:
3611      SLJIT_ASSERT_STOP();
3612    return FALSE;    return FALSE;
3613    }    }
3614  }  }
# Line 3496  if (bit != 0) Line 3643  if (bit != 0)
3643  ranges[0] = length;  ranges[0] = length;
3644  }  }
3645    
3646  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
3647  {  {
3648  int ranges[2 + MAX_RANGE_SIZE];  int ranges[2 + MAX_RANGE_SIZE];
3649  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3650  int i, byte, length = 0;  int i, byte, length = 0;
3651    
3652  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3653  ranges[1] = bit;  ranges[1] = !invert ? bit : (bit ^ 0x1);
3654  /* Can be 0 or 255. */  /* All bits will be zero or one (since bit is zero or one). */
3655  all = -bit;  all = -bit;
3656    
3657  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3925  static void compile_xclass_matchingpath( Line 4072  static void compile_xclass_matchingpath(
4072  {  {
4073  DEFINE_COMPILER;  DEFINE_COMPILER;
4074  jump_list *found = NULL;  jump_list *found = NULL;
4075  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4076  pcre_int32 c, charoffset;  pcre_int32 c, charoffset;
 const pcre_uint32 *other_cases;  
4077  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4078  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4079  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4080    
4081  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4082  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4083  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4084  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4085    const pcre_uint32 *other_cases;
4086  pcre_int32 typeoffset;  pcre_int32 typeoffset;
4087  #endif  #endif
4088    
# Line 3943  pcre_int32 typeoffset; Line 4091  pcre_int32 typeoffset;
4091  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4092  read_char(common);  read_char(common);
4093    
4094  if ((*cc++ & XCL_MAP) != 0)  cc++;
4095    if ((cc[-1] & XCL_HASPROP) == 0)
4096    {    {
4097    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    if ((cc[-1] & XCL_MAP) != 0)
4098  #ifndef COMPILE_PCRE8      {
4099    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4100  #elif defined SUPPORT_UTF  #ifdef SUPPORT_UCP
4101    if (common->utf)      charsaved = TRUE;
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
4102  #endif  #endif
4103        if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, FALSE, backtracks))
4104          {
4105          jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4106    
4107          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4108          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4109          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4110          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4111          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4112          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4113          add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4114    
4115          JUMPHERE(jump);
4116          }
4117        else
4118          add_jump(compiler, &found, CMP(SLJIT_C_LESS_EQUAL, TMP3, 0, SLJIT_IMM, 0xff));
4119    
4120    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4121        cc += 32 / sizeof(pcre_uchar);
4122        }
4123      else
4124        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));
4125      }
4126    else if ((cc[-1] & XCL_MAP) != 0)
4127      {
4128      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4129    #ifdef SUPPORT_UCP
4130      charsaved = TRUE;
4131    #endif
4132      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4133      {      {
4134    #ifdef COMPILE_PCRE8
4135        SLJIT_ASSERT(common->utf);
4136    #endif
4137        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4138    
4139      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4140      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4141      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4142      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4143      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4144      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
     }  
4145    
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
4146      JUMPHERE(jump);      JUMPHERE(jump);
4147  #endif      }
4148    
4149    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
4150    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4151    }    }
4152    
# Line 4030  while (*cc != XCL_END) Line 4204  while (*cc != XCL_END)
4204        case PT_SPACE:        case PT_SPACE:
4205        case PT_PXSPACE:        case PT_PXSPACE:
4206        case PT_WORD:        case PT_WORD:
4207          case PT_PXGRAPH:
4208          case PT_PXPRINT:
4209          case PT_PXPUNCT:
4210        needstype = TRUE;        needstype = TRUE;
4211        needschar = TRUE;        needschar = TRUE;
4212        break;        break;
# Line 4217  while (*cc != XCL_END) Line 4394  while (*cc != XCL_END)
4394    
4395        case PT_SPACE:        case PT_SPACE:
4396        case PT_PXSPACE:        case PT_PXSPACE:
       if (*cc == PT_SPACE)  
         {  
         OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
         jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 11 - charoffset);  
         }  
4397        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4398        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd - 0x9);
4399        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4400        if (*cc == PT_SPACE)  
4401          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4402          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4403    
4404          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4405          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4406    
4407        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4408        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);
# Line 4318  while (*cc != XCL_END) Line 4494  while (*cc != XCL_END)
4494        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4495        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4496        break;        break;
4497    
4498          case PT_PXGRAPH:
4499          /* C and Z groups are the farthest two groups. */
4500          SET_TYPE_OFFSET(ucp_Ll);
4501          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4502          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4503    
4504          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4505    
4506          /* In case of ucp_Cf, we overwrite the result. */
4507          SET_CHAR_OFFSET(0x2066);
4508          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4509          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4510    
4511          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4512          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4513    
4514          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4515          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4516    
4517          JUMPHERE(jump);
4518          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4519          break;
4520    
4521          case PT_PXPRINT:
4522          /* C and Z groups are the farthest two groups. */
4523          SET_TYPE_OFFSET(ucp_Ll);
4524          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4525          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4526    
4527          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4528          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4529    
4530          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4531    
4532          /* In case of ucp_Cf, we overwrite the result. */
4533          SET_CHAR_OFFSET(0x2066);
4534          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4535          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4536    
4537          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4538          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4539    
4540          JUMPHERE(jump);
4541          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4542          break;
4543    
4544          case PT_PXPUNCT:
4545          SET_TYPE_OFFSET(ucp_Sc);
4546          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4547          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4548    
4549          SET_CHAR_OFFSET(0);
4550          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4551          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4552    
4553          SET_TYPE_OFFSET(ucp_Pc);
4554          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4555          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4556          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4557          break;
4558        }        }
4559      cc += 2;      cc += 2;
4560      }      }
# Line 4464  switch(type) Line 4701  switch(type)
4701  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4702    case OP_NOTPROP:    case OP_NOTPROP:
4703    case OP_PROP:    case OP_PROP:
4704    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
4705    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
4706    propdata[2] = cc[0];    propdata[2] = cc[0];
4707    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4823  switch(type) Line 5060  switch(type)
5060    case OP_NCLASS:    case OP_NCLASS:
5061    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5062    read_char(common);    read_char(common);
5063    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, backtracks))    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))
5064      return cc + 32 / sizeof(pcre_uchar);      return cc + 32 / sizeof(pcre_uchar);
5065    
5066  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
# Line 4956  if (context.length > 0) Line 5193  if (context.length > 0)
5193  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5194  }  }
5195    
 static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)  
 {  
 DEFINE_COMPILER;  
 int offset = GET2(cc, 1) << 1;  
   
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
 if (!common->jscript_compat)  
   {  
   if (backtracks == NULL)  
     {  
     /* OVECTOR(1) contains the "string begin - 1" constant. */  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  
     OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  
     return JUMP(SLJIT_C_NOT_ZERO);  
     }  
   add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));  
   }  
 return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
 }  
   
5196  /* Forward definitions. */  /* Forward definitions. */
5197  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5198  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
# Line 5010  static void compile_backtrackingpath(com Line 5225  static void compile_backtrackingpath(com
5225    
5226  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5227    
5228  static pcre_uchar *compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)  static void compile_dnref_search(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
5229    {
5230    /* The OVECTOR offset goes to TMP2. */
5231    DEFINE_COMPILER;
5232    int count = GET2(cc, 1 + IMM2_SIZE);
5233    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5234    unsigned int offset;
5235    jump_list *found = NULL;
5236    
5237    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5238    
5239    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5240    
5241    count--;
5242    while (count-- > 0)
5243      {
5244      offset = GET2(slot, 0) << 1;
5245      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5246      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5247      slot += common->name_entry_size;
5248      }
5249    
5250    offset = GET2(slot, 0) << 1;
5251    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5252    if (backtracks != NULL && !common->jscript_compat)
5253      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5254    
5255    set_jumps(found, LABEL());
5256    }
5257    
5258    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5259  {  {
5260  DEFINE_COMPILER;  DEFINE_COMPILER;
5261  int offset = GET2(cc, 1) << 1;  BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5262    int offset = 0;
5263  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5264  struct sljit_jump *partial;  struct sljit_jump *partial;
5265  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5266    
5267  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5268  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5269  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5270    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5271      /* OVECTOR(1) contains the "string begin - 1" constant. */
5272      if (withchecks && !common->jscript_compat)
5273        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5274      }
5275    else
5276      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5277    
5278  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5279  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5280    {    {
5281    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);
5282    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5283        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5284      else
5285        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5286    
5287    if (withchecks)    if (withchecks)
5288      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5289    
# Line 5052  if (common->utf && *cc == OP_REFI) Line 5308  if (common->utf && *cc == OP_REFI)
5308  else  else
5309  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5310    {    {
5311    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5312        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5313      else
5314        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5315    
5316    if (withchecks)    if (withchecks)
5317      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5318    
# Line 5089  if (jump != NULL) Line 5349  if (jump != NULL)
5349    else    else
5350      JUMPHERE(jump);      JUMPHERE(jump);
5351    }    }
 return cc + 1 + IMM2_SIZE;  
5352  }  }
5353    
5354  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5355  {  {
5356  DEFINE_COMPILER;  DEFINE_COMPILER;
5357    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5358  backtrack_common *backtrack;  backtrack_common *backtrack;
5359  pcre_uchar type;  pcre_uchar type;
5360    int offset = 0;
5361  struct sljit_label *label;  struct sljit_label *label;
5362  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5363  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 5106  BOOL minimize; Line 5367  BOOL minimize;
5367    
5368  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5369    
5370    if (ref)
5371      offset = GET2(cc, 1) << 1;
5372    else
5373      cc += IMM2_SIZE;
5374  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5375    
5376    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5377  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5378  switch(type)  switch(type)
5379    {    {
# Line 5144  if (!minimize) Line 5411  if (!minimize)
5411    if (min == 0)    if (min == 0)
5412      {      {
5413      allocate_stack(common, 2);      allocate_stack(common, 2);
5414        if (ref)
5415          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5416      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5417      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5418      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5419      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5420      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5421        is zero the invalid case is basically the same as an empty case. */
5422        if (ref)
5423          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5424        else
5425          {
5426          compile_dnref_search(common, ccbegin, NULL);
5427          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5428          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5429          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5430          }
5431      /* Restore if not zero length. */      /* Restore if not zero length. */
5432      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5433      }      }
5434    else    else
5435      {      {
5436      allocate_stack(common, 1);      allocate_stack(common, 1);
5437        if (ref)
5438          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5439      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5440      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5441          {
5442          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5443          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5444          }
5445        else
5446          {
5447          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5448          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5449          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5450          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5451          }
5452      }      }
5453    
5454    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5455      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5456    
5457    label = LABEL();    label = LABEL();
5458      if (!ref)
5459        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5460    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5461    
5462    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 5193  if (!minimize) Line 5487  if (!minimize)
5487    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5488    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5489    
5490    decrease_call_count(common);    count_match(common);
5491    return cc;    return cc;
5492    }    }
5493    
5494  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5495    if (ref)
5496      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5497  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5498  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5499    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5500    
5501  if (min == 0)  if (min == 0)
5502    {    {
5503    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5504      is zero the invalid case is basically the same as an empty case. */
5505      if (ref)
5506        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5507      else
5508        {
5509        compile_dnref_search(common, ccbegin, NULL);
5510        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5511        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5512        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5513        }
5514      /* Length is non-zero, we can match real repeats. */
5515    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5516    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5517    }    }
5518  else  else
5519    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5520      if (ref)
5521        {
5522        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5523        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5524        }
5525      else
5526        {
5527        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5528        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5529        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5530        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5531        }
5532      }
5533    
5534  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5535  if (max > 0)  if (max > 0)
5536    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));
5537    
5538    if (!ref)
5539      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5540  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5541  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5542    
# Line 5232  if (jump != NULL) Line 5554  if (jump != NULL)
5554    JUMPHERE(jump);    JUMPHERE(jump);
5555  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5556    
5557  decrease_call_count(common);  count_match(common);
5558  return cc;  return cc;
5559  }  }
5560    
# Line 5242  DEFINE_COMPILER; Line 5564  DEFINE_COMPILER;
5564  backtrack_common *backtrack;  backtrack_common *backtrack;
5565  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5566  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5567  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5568  pcre_uchar *start_cc;  pcre_uchar *start_cc;
5569    BOOL needs_control_head;
5570    
5571  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5572    
5573  /* Inlining simple patterns. */  /* Inlining simple patterns. */
5574  if (get_framesize(common, common->start + start, TRUE) == no_stack)  if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5575    {    {
5576    start_cc = common->start + start;    start_cc = common->start + start;
5577    compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);    compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
# Line 5408  static pcre_uchar *compile_assert_matchi Line 5731  static pcre_uchar *compile_assert_matchi
5731  DEFINE_COMPILER;  DEFINE_COMPILER;
5732  int framesize;  int framesize;
5733  int extrasize;  int extrasize;
5734  BOOL needs_control_head = common->control_head_ptr != 0;  BOOL needs_control_head;
5735  int private_data_ptr;  int private_data_ptr;
5736  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5737  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5418  jump_list *tmp = NULL; Line 5741  jump_list *tmp = NULL;
5741  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5742  jump_list **found;  jump_list **found;
5743  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5744    BOOL save_local_exit = common->local_exit;
5745    BOOL save_positive_assert = common->positive_assert;
5746    then_trap_backtrack *save_then_trap = common->then_trap;
5747  struct sljit_label *save_quit_label = common->quit_label;  struct sljit_label *save_quit_label = common->quit_label;
5748  struct sljit_label *save_accept_label = common->accept_label;  struct sljit_label *save_accept_label = common->accept_label;
5749  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5750    jump_list *save_positive_assert_quit = common->positive_assert_quit;
5751  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
 BOOL save_local_exit = common->local_exit;  
5752  struct sljit_jump *jump;  struct sljit_jump *jump;
5753  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5754    
5755    /* Assert captures then. */
5756    common->then_trap = NULL;
5757    
5758  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5759    {    {
5760    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5434  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5763  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5763    }    }
5764  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5765  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5766  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5767  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5768  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5769  opcode = *cc;  opcode = *cc;
# Line 5454  if (bra == OP_BRAMINZERO) Line 5783  if (bra == OP_BRAMINZERO)
5783  if (framesize < 0)  if (framesize < 0)
5784    {    {
5785    extrasize = needs_control_head ? 2 : 1;    extrasize = needs_control_head ? 2 : 1;
5786    if (framesize != no_stack)    if (framesize == no_frame)
5787      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5788    allocate_stack(common, extrasize);    allocate_stack(common, extrasize);
5789    if (needs_control_head)    if (needs_control_head)
# Line 5484  else Line 5813  else
5813      }      }
5814    else    else
5815      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5816    init_frame(common, ccbegin, framesize + extrasize - 1, extrasize, FALSE);    init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5817      }
5818    
5819    memset(&altbacktrack, 0, sizeof(backtrack_common));
5820    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5821      {
5822      /* Negative assert is stronger than positive assert. */
5823      common->local_exit = TRUE;
5824      common->quit_label = NULL;
5825      common->quit = NULL;
5826      common->positive_assert = FALSE;
5827    }    }
5828    else
5829      common->positive_assert = TRUE;
5830    common->positive_assert_quit = NULL;
5831    
 memset(&altbacktrack, 0, sizeof(backtrack_common));  
 common->local_exit = TRUE;  
 common->quit_label = NULL;  
 common->quit = NULL;  
5832  while (1)  while (1)
5833    {    {
5834    common->accept_label = NULL;    common->accept_label = NULL;
# Line 5505  while (1) Line 5843  while (1)
5843    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5844    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5845      {      {
5846      common->local_exit = save_local_exit;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5847      common->quit_label = save_quit_label;        {
5848          common->local_exit = save_local_exit;
5849          common->quit_label = save_quit_label;
5850          common->quit = save_quit;
5851          }
5852        common->positive_assert = save_positive_assert;
5853        common->then_trap = save_then_trap;
5854      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
5855      common->quit = save_quit;      common->positive_assert_quit = save_positive_assert_quit;
5856      common->accept = save_accept;      common->accept = save_accept;
5857      return NULL;      return NULL;
5858      }      }
# Line 5519  while (1) Line 5863  while (1)
5863    /* Reset stack. */    /* Reset stack. */
5864    if (framesize < 0)    if (framesize < 0)
5865      {      {
5866      if (framesize != no_stack)      if (framesize == no_frame)
5867        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5868      else      else
5869        free_stack(common, extrasize);        free_stack(common, extrasize);
# Line 5573  while (1) Line 5917  while (1)
5917    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5918    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5919      {      {
5920      common->local_exit = save_local_exit;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5921      common->quit_label = save_quit_label;        {
5922          common->local_exit = save_local_exit;
5923          common->quit_label = save_quit_label;
5924          common->quit = save_quit;
5925          }
5926        common->positive_assert = save_positive_assert;
5927        common->then_trap = save_then_trap;
5928      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
5929      common->quit = save_quit;      common->positive_assert_quit = save_positive_assert_quit;
5930      common->accept = save_accept;      common->accept = save_accept;
5931      return NULL;      return NULL;
5932      }      }
# Line 5589  while (1) Line 5939  while (1)
5939    cc += GET(cc, 1);    cc += GET(cc, 1);
5940    }    }
5941    
5942    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5943      {
5944      SLJIT_ASSERT(common->positive_assert_quit == NULL);
5945      /* Makes the check less complicated below. */
5946      common->positive_assert_quit = common->quit;
5947      }
5948    
5949  /* None of them matched. */  /* None of them matched. */
5950  if (common->quit != NULL)  if (common->positive_assert_quit != NULL)
5951    {    {
5952    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5953    set_jumps(common->quit, LABEL());    set_jumps(common->positive_assert_quit, LABEL());
5954    SLJIT_ASSERT(framesize != no_stack);    SLJIT_ASSERT(framesize != no_stack);
5955    if (framesize < 0)    if (framesize < 0)
5956      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
# Line 5753  else Line 6110  else
6110      }      }
6111    }    }
6112    
6113  common->local_exit = save_local_exit;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6114  common->quit_label = save_quit_label;    {
6115      common->local_exit = save_local_exit;
6116      common->quit_label = save_quit_label;
6117      common->quit = save_quit;
6118      }
6119    common->positive_assert = save_positive_assert;
6120    common->then_trap = save_then_trap;
6121  common->accept_label = save_accept_label;  common->accept_label = save_accept_label;
6122  common->quit = save_quit;  common->positive_assert_quit = save_positive_assert_quit;
6123  common->accept = save_accept;  common->accept = save_accept;
6124  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6125  }  }
6126    
6127  static sljit_sw SLJIT_CALL do_searchovector(sljit_uw refno, sljit_sw* locals, pcre_uchar *name_table)  static SLJIT_INLINE void match_once_common(compiler_common *common, pcre_uchar ket, int framesize, int private_data_ptr, BOOL has_alternatives, BOOL needs_control_head)
6128  {  {
6129  int condition = FALSE;  DEFINE_COMPILER;
6130  pcre_uchar *slotA = name_table;  int stacksize;
 pcre_uchar *slotB;  
 sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];  
 sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];  
 sljit_sw no_capture;  
 int i;  
   
 locals += refno & 0xff;  
 refno >>= 8;  
 no_capture = locals[1];  
6131    
6132  for (i = 0; i < name_count; i++)  if (framesize < 0)
6133    {    {
6134    if (GET2(slotA, 0) == refno) break;    if (framesize == no_frame)
6135    slotA += name_entry_size;      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6136    }    else
6137        {
6138        stacksize = needs_control_head ? 1 : 0;
6139        if (ket != OP_KET || has_alternatives)
6140          stacksize++;
6141        free_stack(common, stacksize);
6142        }
6143    
6144  if (i < name_count)    if (needs_control_head)
6145    {      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (ket != OP_KET || has_alternatives) ? sizeof(sljit_sw) : 0);
   /* Found a name for the number - there can be only one; duplicate names  
   for different numbers are allowed, but not vice versa. First scan down  
   for duplicates. */  
6146    
6147    slotB = slotA;    /* TMP2 which is set here used by OP_KETRMAX below. */
6148    while (slotB > name_table)    if (ket == OP_KETRMAX)
6149        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
6150      else if (ket == OP_KETRMIN)
6151      {      {
6152      slotB -= name_entry_size;      /* Move the STR_PTR to the private_data_ptr. */
6153      if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
       {  
       condition = locals[GET2(slotB, 0) << 1] != no_capture;  
       if (condition) break;  
       }  
     else break;  
6154      }      }
6155      }
6156    else
6157      {
6158      stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
6159      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
6160      if (needs_control_head)
6161        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
6162    
6163    /* Scan up for duplicates */    if (ket == OP_KETRMAX)
   if (!condition)  
6164      {      {
6165      slotB = slotA;      /* TMP2 which is set here used by OP_KETRMAX below. */
6166      for (i++; i < name_count; i++)      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
       {  
       slotB += name_entry_size;  
       if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
         {  
         condition = locals[GET2(slotB, 0) << 1] != no_capture;  
         if (condition) break;  
         }  
       else break;  
       }  
6167      }      }
6168    }    }
6169  return condition;  if (needs_control_head)
6170      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
6171  }  }
6172    
6173  static sljit_sw SLJIT_CALL do_searchgroups(sljit_uw recno, sljit_uw* locals, pcre_uchar *name_table)  static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr)
6174  {  {
6175  int condition = FALSE;  DEFINE_COMPILER;
 pcre_uchar *slotA = name_table;  
 pcre_uchar *slotB;  
 sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_sw)];  
 sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];  
 sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_sw)];  
 sljit_uw i;  
6176    
6177  for (i = 0; i < name_count; i++)  if (common->capture_last_ptr != 0)
6178    {    {
6179    if (GET2(slotA, 0) == recno) break;    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6180    slotA += name_entry_size;    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6181      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6182      stacksize++;
6183    }    }
6184    if (common->optimized_cbracket[offset >> 1] == 0)
 if (i < name_count)  
6185    {    {
6186    /* Found a name for the number - there can be only one; duplicate    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6187    names for different numbers are allowed, but not vice versa. First    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6188    scan down for duplicates. */    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6189      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6190    slotB = slotA;    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6191    while (slotB > name_table)    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6192      {    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6193      slotB -= name_entry_size;    stacksize += 2;
     if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
       {  
       condition = GET2(slotB, 0) == group_num;  
       if (condition) break;  
       }  
     else break;  
     }  
   
   /* Scan up for duplicates */  
   if (!condition)  
     {  
     slotB = slotA;  
     for (i++; i < name_count; i++)  
       {  
       slotB += name_entry_size;  
       if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
         {  
         condition = GET2(slotB, 0) == group_num;  
         if (condition) break;  
         }  
       else break;  
       }  
     }  
6194    }    }
6195  return condition;  return stacksize;
6196  }  }
6197    
6198  /*  /*
# Line 5932  backtrack_common *backtrack; Line 6256  backtrack_common *backtrack;
6256  pcre_uchar opcode;  pcre_uchar opcode;
6257  int private_data_ptr = 0;  int private_data_ptr = 0;
6258  int offset = 0;  int offset = 0;
6259  int stacksize;  int i, stacksize;
6260    int repeat_ptr = 0, repeat_length = 0;
6261    int repeat_type = 0, repeat_count = 0;
6262  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6263  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6264    pcre_uchar *slot;
6265  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6266  pcre_uchar ket;  pcre_uchar ket;
6267  assert_backtrack *assert;  assert_backtrack *assert;
6268  BOOL has_alternatives;  BOOL has_alternatives;
6269    BOOL needs_control_head = FALSE;
6270  struct sljit_jump *jump;  struct sljit_jump *jump;
6271  struct sljit_jump *skip;  struct sljit_jump *skip;
6272  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmax_label = NULL;
6273  struct sljit_jump *braminzerojump = NULL;  struct sljit_jump *braminzero = NULL;
6274    
6275  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);
6276    
# Line 5955  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 6283  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
6283    
6284  opcode = *cc;  opcode = *cc;
6285  ccbegin = cc;  ccbegin = cc;
6286  matchingpath = ccbegin + 1 + LINK_SIZE;  matchingpath = bracketend(cc) - 1 - LINK_SIZE;
6287    ket = *matchingpath;
6288    if (ket == OP_KET && PRIVATE_DATA(matchingpath) != 0)
6289      {
6290      repeat_ptr = PRIVATE_DATA(matchingpath);
6291      repeat_length = PRIVATE_DATA(matchingpath + 1);
6292      repeat_type = PRIVATE_DATA(matchingpath + 2);
6293      repeat_count = PRIVATE_DATA(matchingpath + 3);
6294      SLJIT_ASSERT(repeat_length != 0 && repeat_type != 0 && repeat_count != 0);
6295      if (repeat_type == OP_UPTO)
6296        ket = OP_KETRMAX;
6297      if (repeat_type == OP_MINUPTO)
6298        ket = OP_KETRMIN;
6299      }
6300    
6301  if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)  if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)
6302    {    {
6303    /* Drop this bracket_backtrack. */    /* Drop this bracket_backtrack. */
6304    parent->top = backtrack->prev;    parent->top = backtrack->prev;
6305    return bracketend(cc);    return matchingpath + 1 + LINK_SIZE + repeat_length;
6306    }    }
6307    
6308  ket = *(bracketend(cc) - 1 - LINK_SIZE);  matchingpath = ccbegin + 1 + LINK_SIZE;
6309  SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);  SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);
6310  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX)));  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX)));
6311  cc += GET(cc, 1);  cc += GET(cc, 1);
6312    
6313  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6314  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND))
6315    {    has_alternatives = (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF) ? FALSE : TRUE;
   has_alternatives = (*matchingpath == OP_RREF) ? FALSE : TRUE;  
   if (*matchingpath == OP_NRREF)  
     {  
     stacksize = GET2(matchingpath, 1);  
     if (common->currententry == NULL || stacksize == RREF_ANY)  
       has_alternatives = FALSE;  
     else if (common->currententry->start == 0)  
       has_alternatives = stacksize != 0;  
     else  
       has_alternatives = stacksize != (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);  
     }  
   }  
6316    
6317  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
6318    opcode = OP_SCOND;    opcode = OP_SCOND;
# Line 6014  else if (opcode == OP_ONCE || opcode == Line 6343  else if (opcode == OP_ONCE || opcode ==
6343    SLJIT_ASSERT(private_data_ptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
6344    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
6345    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
6346      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE);      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, NULL, FALSE, &needs_control_head);
6347    }    }
6348    
6349  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
6350  stacksize = 0;  stacksize = 0;
6351  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6352    stacksize++;    stacksize++;
6353  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6354    stacksize++;    stacksize++;
# Line 6028  if (stacksize > 0) Line 6357  if (stacksize > 0)
6357    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6358    
6359  stacksize = 0;  stacksize = 0;
6360  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6361    {    {
6362    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6363    stacksize++;    stacksize++;
# Line 6044  if (bra == OP_BRAMINZERO) Line 6373  if (bra == OP_BRAMINZERO)
6373    if (ket != OP_KETRMIN)    if (ket != OP_KETRMIN)
6374      {      {
6375      free_stack(common, 1);      free_stack(common, 1);
6376      braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);      braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
6377      }      }
6378    else    else
6379      {      {
# Line 6059  if (bra == OP_BRAMINZERO) Line 6388  if (bra == OP_BRAMINZERO)
6388        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6389          {          {
6390          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */
6391          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6392          }          }
6393        else        else
6394          {          {
6395          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
6396          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6397          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));
6398          }          }
6399        JUMPHERE(skip);        JUMPHERE(skip);
6400        }        }
# Line 6078  if (bra == OP_BRAMINZERO) Line 6407  if (bra == OP_BRAMINZERO)
6407      }      }
6408    }    }
6409    
6410    if (repeat_type != 0)
6411      {
6412      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, repeat_count);
6413      if (repeat_type == OP_EXACT)
6414        rmax_label = LABEL();
6415      }
6416    
6417  if (ket == OP_KETRMIN)  if (ket == OP_KETRMIN)
6418    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();
6419    
6420  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
6421    {    {
6422    rmaxlabel = LABEL();    rmax_label = LABEL();
6423    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA)    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA && repeat_type == 0)
6424      BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmaxlabel;      BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmax_label;
6425    }    }
6426    
6427  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
6428  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6429    {    {
6430      stacksize = 0;
6431      if (needs_control_head)
6432        {
6433        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6434        stacksize++;
6435        }
6436    
6437    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6438      {      {
6439      /* Neither capturing brackets nor recursions are not found in the block. */      /* Neither capturing brackets nor recursions are found in the block. */
6440      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
6441        {        {
6442        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        stacksize += 2;
6443        allocate_stack(common, 2);        if (!needs_control_head)
6444        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);  
       OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));  
6445        }        }
6446      else if (ket == OP_KETRMAX || has_alternatives)      else
6447        {        {
6448        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6449        allocate_stack(common, 1);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6450        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        if (ket == OP_KETRMAX || has_alternatives)
6451            stacksize++;
6452        }        }
6453      else  
6454        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      if (stacksize > 0)
6455          allocate_stack(common, stacksize);
6456    
6457        stacksize = 0;
6458        if (needs_control_head)
6459          {
6460          stacksize++;
6461          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6462          }
6463    
6464        if (ket == OP_KETRMIN)
6465          {
6466          if (needs_control_head)
6467            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6468          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6469          if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6470            OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, needs_control_head ? (2 * sizeof(sljit_sw)) : sizeof(sljit_sw));
6471          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6472          }
6473        else if (ket == OP_KETRMAX || has_alternatives)
6474          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6475      }      }
6476    else    else
6477      {      {
6478      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)      if (ket != OP_KET || has_alternatives)
6479          stacksize++;
6480    
6481        stacksize += BACKTRACK_AS(bracket_backtrack)->u.framesize + 1;
6482        allocate_stack(common, stacksize);
6483    
6484        if (needs_control_head)
6485          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6486    
6487        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6488        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6489    
6490        stacksize = needs_control_head ? 1 : 0;
6491        if (ket != OP_KET || has_alternatives)
6492        {        {
6493        allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 2);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
       OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize + 1));  
       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  
6494        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6495        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);        stacksize++;
6496        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1, 2, FALSE);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6497        }        }
6498      else      else
6499        {        {
       allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1);  
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
       OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize));  
6500        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6501        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
       init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize, 1, FALSE);  
6502        }        }
6503        init_frame(common, ccbegin, NULL, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);
6504      }      }
6505    }    }
6506  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
# Line 6180  if (opcode == OP_COND || opcode == OP_SC Line 6549  if (opcode == OP_COND || opcode == OP_SC
6549        CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(matchingpath, 1) << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));        CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(matchingpath, 1) << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
6550      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
6551      }      }
6552    else if (*matchingpath == OP_NCREF)    else if (*matchingpath == OP_DNCREF)
6553      {      {
6554      SLJIT_ASSERT(has_alternatives);      SLJIT_ASSERT(has_alternatives);
     stacksize = GET2(matchingpath, 1);  
     jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(stacksize << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  
   
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);  
     OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_sw)));  
     GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);  
     OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);  
     sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));  
     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);  
     add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));  
6555    
6556      JUMPHERE(jump);      i = GET2(matchingpath, 1 + IMM2_SIZE);
6557      matchingpath += 1 + IMM2_SIZE;      slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6558        OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
6559        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
6560        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6561        slot += common->name_entry_size;
6562        i--;
6563        while (i-- > 0)
6564          {
6565          OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6566          OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);
6567          slot += common->name_entry_size;
6568          }
6569        OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
6570        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), JUMP(SLJIT_C_ZERO));
6571        matchingpath += 1 + 2 * IMM2_SIZE;
6572      }      }
6573    else if (*matchingpath == OP_RREF || *matchingpath == OP_NRREF)    else if (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF)
6574      {      {
6575      /* Never has other case. */      /* Never has other case. */
6576      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;
6577        SLJIT_ASSERT(!has_alternatives);
6578    
6579      stacksize = GET2(matchingpath, 1);      if (*matchingpath == OP_RREF)
     if (common->currententry == NULL)  
       stacksize = 0;  
     else if (stacksize == RREF_ANY)  
       stacksize = 1;  
     else if (common->currententry->start == 0)  
       stacksize = stacksize == 0;  
     else  
       stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);  
   
     if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)  
6580        {        {
6581        SLJIT_ASSERT(!has_alternatives);        stacksize = GET2(matchingpath, 1);
6582          if (common->currententry == NULL)
6583            stacksize = 0;
6584          else if (stacksize == RREF_ANY)
6585            stacksize = 1;
6586          else if (common->currententry->start == 0)
6587            stacksize = stacksize == 0;
6588          else
6589            stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6590    
6591        if (stacksize != 0)        if (stacksize != 0)
6592          matchingpath += 1 + IMM2_SIZE;          matchingpath += 1 + IMM2_SIZE;
6593          }
6594        else
6595          {
6596          if (common->currententry == NULL || common->currententry->start == 0)
6597            stacksize = 0;
6598        else        else
6599          {          {
6600            stacksize = GET2(matchingpath, 1 + IMM2_SIZE);
6601            slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6602            i = (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6603            while (stacksize > 0)
6604              {
6605              if ((int)GET2(slot, 0) == i)
6606                break;
6607              slot += common->name_entry_size;
6608              stacksize--;
6609              }
6610            }
6611    
6612          if (stacksize != 0)
6613            matchingpath += 1 + 2 * IMM2_SIZE;
6614          }
6615    
6616          /* The stacksize == 0 is a common "else" case. */
6617          if (stacksize == 0)
6618            {
6619          if (*cc == OP_ALT)          if (*cc == OP_ALT)
6620            {            {
6621            matchingpath = cc + 1 + LINK_SIZE;            matchingpath = cc + 1 + LINK_SIZE;
# Line 6229  if (opcode == OP_COND || opcode == OP_SC Line 6624  if (opcode == OP_COND || opcode == OP_SC
6624          else          else
6625            matchingpath = cc;            matchingpath = cc;
6626          }          }
       }  
     else  
       {  
       SLJIT_ASSERT(has_alternatives);  
   
       stacksize = GET2(matchingpath, 1);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, GET2(common->start, common->currententry->start + 1 + LINK_SIZE));  
       OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, stacksize);  
       GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);  
       OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);  
       sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchgroups));  
       OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);  
       add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));  
       matchingpath += 1 + IMM2_SIZE;  
       }  
6627      }      }
6628    else    else
6629      {      {
# Line 6267  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 6644  if (SLJIT_UNLIKELY(sljit_get_compiler_er
6644    return NULL;    return NULL;
6645    
6646  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6647    {    match_once_common(common, ket, BACKTRACK_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
   if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)  
     {  
     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     /* TMP2 which is set here used by OP_KETRMAX below. */  
     if (ket == OP_KETRMAX)  
       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);  
     else if (ket == OP_KETRMIN)  
       {  
       /* Move the STR_PTR to the private_data_ptr. */  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);  
       }  
     }  
   else  
     {  
     stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;  
     OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize) * sizeof(sljit_sw));  
     if (ket == OP_KETRMAX)  
       {  
       /* TMP2 which is set here used by OP_KETRMAX below. */  
       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  
       }  
     }  
   }  
6648    
6649  stacksize = 0;  stacksize = 0;
6650    if (repeat_type == OP_MINUPTO)
6651      {
6652      /* We need to preserve the counter. TMP2 will be used below. */
6653      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);
6654      stacksize++;
6655      }
6656  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6657    stacksize++;    stacksize++;
6658  if (offset != 0)  if (offset != 0)
# Line 6309  if (stacksize > 0) Line 6669  if (stacksize > 0)
6669    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6670    
6671  stacksize = 0;  stacksize = 0;
6672    if (repeat_type == OP_MINUPTO)
6673      {
6674      /* TMP2 was set above. */
6675      OP2(SLJIT_SUB, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0, SLJIT_IMM, 1);
6676      stacksize++;
6677      }
6678    
6679  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6680    {    {
6681    if (ket != OP_KET)    if (ket != OP_KET)
# Line 6319  if (ket != OP_KET || bra != OP_BRA) Line 6686  if (ket != OP_KET || bra != OP_BRA)
6686    }    }
6687    
6688  if (offset != 0)  if (offset != 0)
6689    {    stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
   if (common->capture_last_ptr != 0)  
     {  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0);  
     stacksize++;  
     }  
   if (common->optimized_cbracket[offset >> 1] == 0)  
     {  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);  
     stacksize += 2;  
     }  
   }  
6690    
6691  if (has_alternatives)  if (has_alternatives)
6692    {    {
# Line 6357  if (offset != 0 && common->optimized_cbr Line 6705  if (offset != 0 && common->optimized_cbr
6705    
6706  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
6707    {    {
6708    if (opcode == OP_ONCE || opcode >= OP_SBRA)    if (repeat_type != 0)
6709        {
6710        if (has_alternatives)
6711          BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();
6712        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
6713        JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);
6714        /* Drop STR_PTR for greedy plus quantifier. */
6715        if (opcode != OP_ONCE)
6716          free_stack(common, 1);
6717        }
6718      else if (opcode == OP_ONCE || opcode >= OP_SBRA)
6719      {      {
6720      if (has_alternatives)      if (has_alternatives)
6721        BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();        BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();
6722      /* Checking zero-length iteration. */      /* Checking zero-length iteration. */
6723      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
6724        {        {
6725        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0, rmaxlabel);        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0, rmax_label);
6726        /* Drop STR_PTR for greedy plus quantifier. */        /* Drop STR_PTR for greedy plus quantifier. */
6727        if (bra != OP_BRAZERO)        if (bra != OP_BRAZERO)
6728          free_stack(common, 1);          free_stack(common, 1);
6729        }        }
6730      else      else
6731        /* TMP2 must contain the starting STR_PTR. */        /* TMP2 must contain the starting STR_PTR. */
6732        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, rmaxlabel);        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, rmax_label);
6733      }      }
6734    else    else
6735      JUMPTO(SLJIT_JUMP, rmaxlabel);      JUMPTO(SLJIT_JUMP, rmax_label);
6736    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();
6737    }    }
6738    
6739    if (repeat_type == OP_EXACT)
6740      {
6741      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
6742      JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);
6743      }
6744    else if (repeat_type == OP_UPTO)
6745      {
6746      /* We need to preserve the counter. */
6747      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);
6748      allocate_stack(common, 1);
6749      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6750      }
6751    
6752  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6753    BACKTRACK_AS(bracket_backtrack)->zero_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->zero_matchingpath = LABEL();
6754    
# Line 6385  if (bra == OP_BRAMINZERO) Line 6756  if (bra == OP_BRAMINZERO)
6756    {    {
6757    /* This is a backtrack path! (From the viewpoint of OP_BRAMINZERO) */    /* This is a backtrack path! (From the viewpoint of OP_BRAMINZERO) */
6758    JUMPTO(SLJIT_JUMP, ((braminzero_backtrack *)parent)->matchingpath);    JUMPTO(SLJIT_JUMP, ((braminzero_backtrack *)parent)->matchingpath);
6759    if (braminzerojump != NULL)    if (braminzero != NULL)
6760      {      {
6761      JUMPHERE(braminzerojump);      JUMPHERE(braminzero);
6762      /* We need to release the end pointer to perform the      /* We need to release the end pointer to perform the
6763      backtrack for the zero-length iteration. When      backtrack for the zero-length iteration. When
6764      framesize is < 0, OP_ONCE will do the release itself. */      framesize is < 0, OP_ONCE will do the release itself. */
# Line 6403  if (bra == OP_BRAMINZERO) Line 6774  if (bra == OP_BRAMINZERO)
6774    }    }
6775    
6776  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)
6777    decrease_call_count(common);    count_match(common);
6778    
6779  /* Skip the other alternatives. */  /* Skip the other alternatives. */
6780  while (*cc == OP_ALT)  while (*cc == OP_ALT)
6781    cc += GET(cc, 1);    cc += GET(cc, 1);
6782  cc += 1 + LINK_SIZE;  cc += 1 + LINK_SIZE;
6783  return cc;  
6784    /* Temporarily encoding the needs_control_head in framesize. */
6785    if (opcode == OP_ONCE)
6786      BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);
6787    return cc + repeat_length;
6788  }  }
6789    
6790  static pcre_uchar *compile_bracketpos_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)  static pcre_uchar *compile_bracketpos_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
# Line 6419  backtrack_common *backtrack; Line 6794  backtrack_common *backtrack;
6794  pcre_uchar opcode;  pcre_uchar opcode;
6795  int private_data_ptr;  int private_data_ptr;
6796  int cbraprivptr = 0;  int cbraprivptr = 0;
6797    BOOL needs_control_head;
6798  int framesize;  int framesize;
6799  int stacksize;  int stacksize;
6800  int offset = 0;  int offset = 0;
6801  BOOL zero = FALSE;  BOOL zero = FALSE;
6802  pcre_uchar *ccbegin = NULL;  pcre_uchar *ccbegin = NULL;
6803  int stack;  int stack; /* Also contains the offset of control head. */
6804  struct sljit_label *loop = NULL;  struct sljit_label *loop = NULL;
6805  struct jump_list *emptymatch = NULL;  struct jump_list *emptymatch = NULL;
6806    
# Line 6462  switch(opcode) Line 6838  switch(opcode)
6838    break;    break;
6839    }    }
6840    
6841  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
6842  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6843  if (framesize < 0)  if (framesize < 0)
6844    {    {
# Line 6475  if (framesize < 0) Line 6851  if (framesize < 0)
6851    else    else
6852      stacksize = 1;      stacksize = 1;
6853    
6854      if (needs_control_head)
6855        stacksize++;
6856    if (!zero)    if (!zero)
6857      stacksize++;      stacksize++;
6858    
# Line 6483  if (framesize < 0) Line 6861  if (framesize < 0)
6861    if (framesize == no_frame)    if (framesize == no_frame)
6862      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6863    
6864      stack = 0;
6865    if (offset != 0)    if (offset != 0)
6866      {      {
6867        stack = 2;
6868      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6869      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6870      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6871      if (common->capture_last_ptr != 0)      if (common->capture_last_ptr != 0)
6872        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6873      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6874        if (needs_control_head)
6875          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6876      if (common->capture_last_ptr != 0)      if (common->capture_last_ptr != 0)
6877          {
6878        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6879          stack = 3;
6880          }
6881      }      }
6882    else    else
6883        {
6884        if (needs_control_head)
6885          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6886      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6887        stack = 1;
6888        }
6889    
6890      if (needs_control_head)
6891        stack++;
6892    if (!zero)    if (!zero)
6893      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize - 1), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), SLJIT_IMM, 1);
6894      if (needs_control_head)
6895        {
6896        stack--;
6897        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6898        }
6899    }    }
6900  else  else
6901    {    {
6902    stacksize = framesize + 1;    stacksize = framesize + 1;
6903    if (!zero)    if (!zero)
6904      stacksize++;      stacksize++;
6905    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (needs_control_head)
6906        stacksize++;
6907      if (offset == 0)
6908      stacksize++;      stacksize++;
6909    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
6910    
6911    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6912    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6913    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));    if (needs_control_head)
6914    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6915      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));
6916    
6917    stack = 0;    stack = 0;
6918    if (!zero)    if (!zero)
6919      {      {
6920      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);
6921        stack = 1;
6922        }
6923      if (needs_control_head)
6924        {
6925        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6926      stack++;      stack++;
6927      }      }
6928    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (offset == 0)
6929      {      {
6930      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);
6931      stack++;      stack++;
6932      }      }
6933    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);
6934    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, NULL, stacksize - 1, stacksize - framesize, FALSE);
6935      stack -= 1 + (offset == 0);
6936    }    }
6937    
6938  if (offset != 0)  if (offset != 0)
# Line 6602  while (*cc != OP_KETRPOS) Line 7008  while (*cc != OP_KETRPOS)
7008          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
7009        }        }
7010      }      }
7011    
7012      if (needs_control_head)
7013        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(stack));
7014    
7015    JUMPTO(SLJIT_JUMP, loop);    JUMPTO(SLJIT_JUMP, loop);
7016    flush_stubs(common);    flush_stubs(common);
7017    
# Line 6638  while (*cc != OP_KETRPOS) Line 7048  while (*cc != OP_KETRPOS)
7048    ccbegin = cc + 1 + LINK_SIZE;    ccbegin = cc + 1 + LINK_SIZE;
7049    }    }
7050    
7051    /* We don't have to restore the control head in case of a failed match. */
7052    
7053  backtrack->topbacktracks = NULL;  backtrack->topbacktracks = NULL;
7054  if (!zero)  if (!zero)
7055    {    {
# Line 6649  if (!zero) Line 7061  if (!zero)
7061    
7062  /* None of them matched. */  /* None of them matched. */
7063  set_jumps(emptymatch, LABEL());  set_jumps(emptymatch, LABEL());
7064  decrease_call_count(common);  count_match(common);
7065  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
7066  }  }
7067    
7068  static SLJIT_INLINE pcre_uchar *get_iterator_parameters(compiler_common *common, pcre_uchar *cc, pcre_uchar *opcode, pcre_uchar *type, int *arg1, int *arg2, pcre_uchar **end)  static SLJIT_INLINE pcre_uchar *get_iterator_parameters(compiler_common *common, pcre_uchar *cc, pcre_uchar *opcode, pcre_uchar *type, int *max, int *min, pcre_uchar **end)
7069  {  {
7070  int class_len;  int class_len;
7071    
# Line 6689  else if (*opcode >= OP_TYPESTAR && *opco Line 7101  else if (*opcode >= OP_TYPESTAR && *opco
7101    }    }
7102  else  else
7103    {    {
7104    SLJIT_ASSERT(*opcode >= OP_CLASS || *opcode <= OP_XCLASS);    SLJIT_ASSERT(*opcode == OP_CLASS || *opcode == OP_NCLASS || *opcode == OP_XCLASS);
7105    *type = *opcode;    *type = *opcode;
7106    cc++;    cc++;
7107    class_len = (*type < OP_XCLASS) ? (int)(1 + (32 / sizeof(pcre_uchar))) : GET(cc, 0);    class_len = (*type < OP_XCLASS) ? (int)(1 + (32 / sizeof(pcre_uchar))) : GET(cc, 0);
# Line 6700  else Line 7112  else
7112      if (end != NULL)      if (end != NULL)
7113        *end = cc + class_len;        *end = cc + class_len;
7114      }      }
7115      else if (*opcode >= OP_CRPOSSTAR && *opcode <= OP_CRPOSQUERY)
7116        {
7117        *opcode -= OP_CRPOSSTAR - OP_POSSTAR;
7118        if (end != NULL)
7119          *end = cc + class_len;
7120        }
7121    else    else
7122      {      {
7123      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE);      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE || *opcode == OP_CRPOSRANGE);
7124      *arg1 = GET2(cc, (class_len + IMM2_SIZE));      *max = GET2(cc, (class_len + IMM2_SIZE));
7125      *arg2 = GET2(cc, class_len);      *min = GET2(cc, class_len);
7126    
7127      if (*arg2 == 0)      if (*min == 0)
7128        {        {
7129        SLJIT_ASSERT(*arg1 != 0);        SLJIT_ASSERT(*max != 0);
7130        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : OP_MINUPTO;        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : (*opcode == OP_CRMINRANGE ? OP_MINUPTO : OP_POSUPTO);
7131        }        }
7132      if (*arg1 == *arg2)      if (*max == *min)
7133        *opcode = OP_EXACT;        *opcode = OP_EXACT;
7134    
7135      if (end != NULL)      if (end != NULL)
# Line 6722  else Line 7140  else
7140    
7141  if (*opcode == OP_UPTO || *opcode == OP_MINUPTO || *opcode == OP_EXACT || *opcode == OP_POSUPTO)  if (*opcode == OP_UPTO || *opcode == OP_MINUPTO || *opcode == OP_EXACT || *opcode == OP_POSUPTO)
7142    {    {
7143    *arg1 = GET2(cc, 0);    *max = GET2(cc, 0);
7144    cc += IMM2_SIZE;    cc += IMM2_SIZE;
7145    }    }
7146    
# Line 6751  DEFINE_COMPILER; Line 7169  DEFINE_COMPILER;
7169  backtrack_common *backtrack;  backtrack_common *backtrack;
7170  pcre_uchar opcode;  pcre_uchar opcode;
7171  pcre_uchar type;  pcre_uchar type;
7172  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7173  pcre_uchar* end;  pcre_uchar* end;
7174  jump_list *nomatch = NULL;  jump_list *nomatch = NULL;
7175  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 6764  int tmp_base, tmp_offset; Line 7182  int tmp_base, tmp_offset;
7182    
7183  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
7184    
7185  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, &end);
7186    
7187  switch(type)  switch(type)
7188    {    {
# Line 6835  switch(opcode) Line 7253  switch(opcode)
7253        {        {
7254        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
7255        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7256        if (opcode == OP_CRRANGE && arg2 > 0)        if (opcode == OP_CRRANGE && min > 0)
7257          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2, label);          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
7258        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && arg1 > 0))        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && max > 0))
7259          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, arg1);          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);
7260        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);
7261        }        }
7262    
# Line 6865  switch(opcode) Line 7283  switch(opcode)
7283      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
7284      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7285        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
7286      else if (opcode == OP_CRRANGE && arg1 == 0)      else if (opcode == OP_CRRANGE && max == 0)
7287        {        {
7288        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);
7289        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
# Line 6875  switch(opcode) Line 7293  switch(opcode)
7293        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7294        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7295        OP1(SLJIT_MOV, base, offset1, TMP1, 0);        OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7296        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 1, label);        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, max + 1, label);
7297        }        }
7298      set_jumps(nomatch, LABEL());      set_jumps(nomatch, LABEL());
7299      if (opcode == OP_CRRANGE)      if (opcode == OP_CRRANGE)
7300        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_LESS, base, offset1, SLJIT_IMM, arg2 + 1));        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_LESS, base, offset1, SLJIT_IMM, min + 1));
7301      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7302      }      }
7303    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
# Line 6917  switch(opcode) Line 7335  switch(opcode)
7335    break;    break;
7336    
7337    case OP_EXACT:    case OP_EXACT:
7338    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, arg1);    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, max);
7339    label = LABEL();    label = LABEL();
7340    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7341    OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);
# Line 6930  switch(opcode) Line 7348  switch(opcode)
7348    if (opcode == OP_POSPLUS)    if (opcode == OP_POSPLUS)
7349      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7350    if (opcode == OP_POSUPTO)    if (opcode == OP_POSUPTO)
7351      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, arg1);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max);
7352    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7353    label = LABEL();    label = LABEL();
7354    compile_char1_matchingpath(common, type, cc, &nomatch);    compile_char1_matchingpath(common, type, cc, &nomatch);
# Line 6946  switch(opcode) Line 7364  switch(opcode)
7364    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7365    break;    break;
7366    
7367    case OP_POSQUERY:    case OP_POSQUERY:
7368    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7369    compile_char1_matchingpath(common, type, cc, &nomatch);    compile_char1_matchingpath(common, type, cc, &nomatch);
7370    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7371    set_jumps(nomatch, LABEL());    set_jumps(nomatch, LABEL());
7372    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7373    break;    break;
7374    
7375      case OP_CRPOSRANGE:
7376      /* Combination of OP_EXACT and OP_POSSTAR or OP_POSUPTO */
7377      OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, min);
7378      label = LABEL();
7379      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7380      OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);
7381      JUMPTO(SLJIT_C_NOT_ZERO, label);
7382    
7383      if (max != 0)
7384        {
7385        SLJIT_ASSERT(max - min > 0);
7386        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max - min);
7387        }
7388      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7389      label = LABEL();
7390      compile_char1_matchingpath(common, type, cc, &nomatch);
7391      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7392      if (max == 0)
7393        JUMPTO(SLJIT_JUMP, label);
7394      else
7395        {
7396        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, 1);
7397        JUMPTO(SLJIT_C_NOT_ZERO, label);
7398        }
7399      set_jumps(nomatch, LABEL());
7400      OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7401      break;
7402    
7403    default:    default:
7404    SLJIT_ASSERT_STOP();    SLJIT_ASSERT_STOP();
7405    break;    break;
7406    }    }
7407    
7408  decrease_call_count(common);  count_match(common);
7409  return end;  return end;
7410  }  }
7411    
# Line 7026  if (!optimized_cbracket) Line 7472  if (!optimized_cbracket)
7472  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
7473  }  }
7474    
7475    static SLJIT_INLINE pcre_uchar *compile_control_verb_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
7476    {
7477    DEFINE_COMPILER;
7478    backtrack_common *backtrack;
7479    pcre_uchar opcode = *cc;
7480    pcre_uchar *ccend = cc + 1;
7481    
7482    if (opcode == OP_PRUNE_ARG || opcode == OP_SKIP_ARG || opcode == OP_THEN_ARG)
7483      ccend += 2 + cc[1];
7484    
7485    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
7486    
7487    if (opcode == OP_SKIP)
7488      {
7489      allocate_stack(common, 1);
7490      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
7491      return ccend;
7492      }
7493    
7494    if (opcode == OP_PRUNE_ARG || opcode == OP_THEN_ARG)
7495      {
7496      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7497      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7498      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7499      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7500      }
7501    
7502    return ccend;
7503    }
7504    
7505    static pcre_uchar then_trap_opcode[1] = { OP_THEN_TRAP };
7506    
7507    static SLJIT_INLINE void compile_then_trap_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
7508    {
7509    DEFINE_COMPILER;
7510    backtrack_common *backtrack;
7511    BOOL needs_control_head;
7512    int size;
7513    
7514    PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7515    common->then_trap = BACKTRACK_AS(then_trap_backtrack);
7516    BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7517    BACKTRACK_AS(then_trap_backtrack)->start = (sljit_sw)(cc - common->start);
7518    BACKTRACK_AS(then_trap_backtrack)->framesize = get_framesize(common, cc, ccend, FALSE, &needs_control_head);
7519    
7520    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7521    size = 3 + (size < 0 ? 0 : size);
7522    
7523    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7524    allocate_stack(common, size);
7525    if (size > 3)
7526      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0, SLJIT_IMM, (size - 3) * sizeof(sljit_sw));
7527    else
7528      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7529    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 1), SLJIT_IMM, BACKTRACK_AS(then_trap_backtrack)->start);
7530    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 2), SLJIT_IMM, type_then_trap);
7531    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 3), TMP2, 0);
7532    
7533    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7534    if (size >= 0)
7535      init_frame(common, cc, ccend, size - 1, 0, FALSE);
7536    }
7537    
7538  static void compile_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)  static void compile_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
7539  {  {
7540  DEFINE_COMPILER;  DEFINE_COMPILER;
7541  backtrack_common *backtrack;  backtrack_common *backtrack;
7542    BOOL has_then_trap = FALSE;
7543    then_trap_backtrack *save_then_trap = NULL;
7544    
7545    SLJIT_ASSERT(*ccend == OP_END || (*ccend >= OP_ALT && *ccend <= OP_KETRPOS));
7546    
7547    if (common->has_then && common->then_offsets[cc - common->start] != 0)
7548      {
7549      SLJIT_ASSERT(*ccend != OP_END && common->control_head_ptr != 0);
7550      has_then_trap = TRUE;
7551      save_then_trap = common->then_trap;
7552      /* Tail item on backtrack. */
7553      compile_then_trap_matchingpath(common, cc, ccend, parent);
7554      }
7555    
7556  while (cc < ccend)  while (cc < ccend)
7557    {    {
# Line 7155  while (cc < ccend) Line 7677  while (cc < ccend)
7677    
7678      case OP_CLASS:      case OP_CLASS:
7679      case OP_NCLASS:      case OP_NCLASS:
7680      if (cc[1 + (32 / sizeof(pcre_uchar))] >= OP_CRSTAR && cc[1 + (32 / sizeof(pcre_uchar))] <= OP_CRMINRANGE)      if (cc[1 + (32 / sizeof(pcre_uchar))] >= OP_CRSTAR && cc[1 + (32 / sizeof(pcre_uchar))] <= OP_CRPOSRANGE)
7681        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7682      else      else
7683        cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);        cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
# Line 7163  while (cc < ccend) Line 7685  while (cc < ccend)
7685    
7686  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
7687      case OP_XCLASS:      case OP_XCLASS:
7688      if (*(cc + GET(cc, 1)) >= OP_CRSTAR && *(cc + GET(cc, 1)) <= OP_CRMINRANGE)      if (*(cc + GET(cc, 1)) >= OP_CRSTAR && *(cc + GET(cc, 1)) <= OP_CRPOSRANGE)
7689        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7690      else      else
7691        cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);        cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
# Line 7172  while (cc < ccend) Line 7694  while (cc < ccend)
7694    
7695      case OP_REF:      case OP_REF:
7696      case OP_REFI:      case OP_REFI:
7697      if (cc[1 + IMM2_SIZE] >= OP_CRSTAR && cc[1 + IMM2_SIZE] <= OP_CRMINRANGE)      if (cc[1 + IMM2_SIZE] >= OP_CRSTAR && cc[1 + IMM2_SIZE] <= OP_CRPOSRANGE)
7698        cc = compile_ref_iterator_matchingpath(common, cc, parent);        cc = compile_ref_iterator_matchingpath(common, cc, parent);
7699      else      else
7700        cc = compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);        {
7701          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7702          cc += 1 + IMM2_SIZE;
7703          }
7704        break;
7705    
7706        case OP_DNREF:
7707        case OP_DNREFI:
7708        if (cc[1 + 2 * IMM2_SIZE] >= OP_CRSTAR && cc[1 + 2 * IMM2_SIZE] <= OP_CRPOSRANGE)
7709          cc = compile_ref_iterator_matchingpath(common, cc, parent);
7710        else
7711          {
7712          compile_dnref_search(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
7713          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7714          cc += 1 + 2 * IMM2_SIZE;
7715          }
7716      break;      break;
7717    
7718      case OP_RECURSE:      case OP_RECURSE:
# Line 7210  while (cc < ccend) Line 7747  while (cc < ccend)
7747        }        }
7748      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();
7749      if (cc[1] > OP_ASSERTBACK_NOT)      if (cc[1] > OP_ASSERTBACK_NOT)
7750        decrease_call_count(common);        count_match(common);
7751      break;      break;
7752    
7753      case OP_ONCE:      case OP_ONCE:
# Line 7246  while (cc < ccend) Line 7783  while (cc < ccend)
7783      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
7784      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
7785      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
7786      allocate_stack(common, 1);      allocate_stack(common, common->has_skip_arg ? 5 : 1);
7787      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7788      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0), TMP2, 0);
7789      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7790      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7791      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7792        if (common->has_skip_arg)
7793          {
7794          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7795          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7796          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_mark);
7797          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), SLJIT_IMM, (sljit_sw)(cc + 2));
7798          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0);
7799          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
7800          }
7801      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
7802      break;      break;
7803    
     case OP_PRUNE_ARG:  
     OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);  
     /* Fall through. */  
   
7804      case OP_PRUNE:      case OP_PRUNE:
7805      case OP_COMMIT:      case OP_PRUNE_ARG:
     PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);  
     SLJIT_ASSERT(common->control_head_ptr != 0);  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);  
     allocate_stack(common, 2);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, *cc == OP_COMMIT ? type_commit : type_prune);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);  
     cc += (*cc == OP_PRUNE_ARG) ? (1 + 2 + cc[1]) : 1;  
     break;  
   
7806      case OP_SKIP:      case OP_SKIP:
7807      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      case OP_SKIP_ARG:
7808      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);      case OP_THEN:
7809      allocate_stack(common, 3);      case OP_THEN_ARG:
7810      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);      case OP_COMMIT:
7811      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_skip);      cc = compile_control_verb_matchingpath(common, cc, parent);
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), STR_PTR, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);  
     cc += 1;  
7812      break;      break;
7813    
7814      case OP_FAIL:      case OP_FAIL:
# Line 7306  while (cc < ccend) Line 7832  while (cc < ccend)
7832    if (cc == NULL)    if (cc == NULL)
7833      return;      return;
7834    }    }
7835    
7836    if (has_then_trap)
7837      {
7838      /* Head item on backtrack. */
7839      PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7840      BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7841      BACKTRACK_AS(then_trap_backtrack)->then_trap = common->then_trap;
7842      common->then_trap = save_then_trap;
7843      }
7844  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
7845  }  }
7846    
# Line 7330  DEFINE_COMPILER; Line 7865  DEFINE_COMPILER;
7865  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7866  pcre_uchar opcode;  pcre_uchar opcode;
7867  pcre_uchar type;  pcre_uchar type;
7868  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7869  struct sljit_label *label = NULL;  struct sljit_label *label = NULL;
7870  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
7871  jump_list *jumplist = NULL;  jump_list *jumplist = NULL;
# Line 7339  int base = (private_data_ptr == 0) ? SLJ Line 7874  int base = (private_data_ptr == 0) ? SLJ
7874  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
7875  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);
7876    
7877  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, NULL);
7878    
7879  switch(opcode)  switch(opcode)
7880    {    {
# Line 7358  switch(opcode) Line 7893  switch(opcode)
7893    else    else
7894      {      {
7895      if (opcode == OP_UPTO)      if (opcode == OP_UPTO)
7896        arg2 = 0;        min = 0;
7897      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7898        {        {
7899        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
# Line 7368  switch(opcode) Line 7903  switch(opcode)
7903        {        {
7904        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7905        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7906        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, arg2 + 1);        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, min + 1);
7907        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);
7908        }        }
7909      skip_char_back(common);      skip_char_back(common);
# Line 7413  switch(opcode) Line 7948  switch(opcode)
7948    OP1(SLJIT_MOV, base, offset1, TMP1, 0);    OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7949    
7950    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
7951      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2 + 1, label);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min + 1, label);
7952    
7953    if (opcode == OP_CRMINRANGE && arg1 == 0)    if (opcode == OP_CRMINRANGE && max == 0)
7954      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);
7955    else    else
7956      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 2, CURRENT_AS(iterator_backtrack)->matchingpath);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, max + 2, CURRENT_AS(iterator_backtrack)->matchingpath);
7957    
7958    set_jumps(jumplist, LABEL());    set_jumps(jumplist, LABEL());
7959    if (private_data_ptr == 0)    if (private_data_ptr == 0)
# Line 7453  switch(opcode) Line 7988  switch(opcode)
7988    
7989    case OP_EXACT:    case OP_EXACT:
7990    case OP_POSPLUS:    case OP_POSPLUS:
7991      case OP_CRPOSRANGE:
7992    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7993    break;    break;
7994    
# Line 7467  switch(opcode) Line 8003  switch(opcode)
8003    }    }
8004  }  }
8005    
8006  static void compile_ref_iterator_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_ref_iterator_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8007  {  {
8008  DEFINE_COMPILER;  DEFINE_COMPILER;
8009  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8010    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
8011  pcre_uchar type;  pcre_uchar type;
8012    
8013  type = cc[1 + IMM2_SIZE];  type = cc[ref ? 1 + IMM2_SIZE : 1 + 2 * IMM2_SIZE];
8014    
8015  if ((type & 0x1) == 0)  if ((type & 0x1) == 0)
8016    {    {
8017      /* Maximize case. */
8018    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
8019    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8020    free_stack(common, 1);    free_stack(common, 1);
# Line 7486  if ((type & 0x1) == 0) Line 8025  if ((type & 0x1) == 0)
8025  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8026  CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_backtrack)->matchingpath);  CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_backtrack)->matchingpath);
8027  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
8028  free_stack(common, 2);  free_stack(common, ref ? 2 : 3);
8029  }  }
8030    
8031  static void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8032  {  {
8033  DEFINE_COMPILER;  DEFINE_COMPILER;
8034    
# Line 7585  if (bra == OP_BRAZERO) Line 8124  if (bra == OP_BRAZERO)
8124  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8125  {  {
8126  DEFINE_COMPILER;  DEFINE_COMPILER;
8127  int opcode;  int opcode, stacksize, count;
8128  int offset = 0;  int offset = 0;
8129  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;
8130  int stacksize;  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;
 int count;  
8131  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8132  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
8133  pcre_uchar *ccprev;  pcre_uchar *ccprev;
# Line 7599  pcre_uchar bra = OP_BRA; Line 8137  pcre_uchar bra = OP_BRA;
8137  pcre_uchar ket;  pcre_uchar ket;
8138  assert_backtrack *assert;  assert_backtrack *assert;
8139  BOOL has_alternatives;  BOOL has_alternatives;
8140    BOOL needs_control_head = FALSE;
8141  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
8142  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
8143  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
8144  struct sljit_label *rminlabel = NULL;  struct sljit_label *rmin_label = NULL;
8145    struct sljit_label *exact_label = NULL;
8146    
8147  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
8148    {    {
# Line 7611  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 8151  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
8151    }    }
8152    
8153  opcode = *cc;  opcode = *cc;
8154    ccbegin = bracketend(cc) - 1 - LINK_SIZE;
8155    ket = *ccbegin;
8156    if (ket == OP_KET && PRIVATE_DATA(ccbegin) != 0)
8157      {
8158      repeat_ptr = PRIVATE_DATA(ccbegin);
8159      repeat_type = PRIVATE_DATA(ccbegin + 2);
8160      repeat_count = PRIVATE_DATA(ccbegin + 3);
8161      SLJIT_ASSERT(repeat_type != 0 && repeat_count != 0);
8162      if (repeat_type == OP_UPTO)
8163        ket = OP_KETRMAX;
8164      if (repeat_type == OP_MINUPTO)
8165        ket = OP_KETRMIN;
8166      }
8167  ccbegin = cc;  ccbegin = cc;
 ket = *(bracketend(ccbegin) - 1 - LINK_SIZE);  
8168  cc += GET(cc, 1);  cc += GET(cc, 1);
8169  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
8170  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))
# Line 7624  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 8176  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
8176  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
8177    opcode = OP_ONCE;    opcode = OP_ONCE;
8178    
8179    /* Decoding the needs_control_head in framesize. */
8180    if (opcode == OP_ONCE)
8181      {
8182      needs_control_head = (CURRENT_AS(bracket_backtrack)->u.framesize & 0x1) != 0;
8183      CURRENT_AS(bracket_backtrack)->u.framesize >>= 1;
8184      }
8185    
8186    if (ket != OP_KET && repeat_type != 0)
8187      {
8188      /* TMP1 is used in OP_KETRMIN below. */
8189      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8190      free_stack(common, 1);
8191      if (repeat_type == OP_UPTO)
8192        OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0, SLJIT_IMM, 1);
8193      else
8194        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0);
8195      }
8196    
8197  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
8198    {    {
8199    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
# Line 7638  else if (ket == OP_KETRMIN) Line 8208  else if (ket == OP_KETRMIN)
8208    if (bra != OP_BRAMINZERO)    if (bra != OP_BRAMINZERO)
8209      {      {
8210      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8211      if (opcode >= OP_SBRA || opcode == OP_ONCE)      if (repeat_type != 0)
8212          {
8213          /* TMP1 was set a few lines above. */
8214          CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8215          /* Drop STR_PTR for non-greedy plus quantifier. */
8216          if (opcode != OP_ONCE)
8217            free_stack(common, 1);
8218          }
8219        else if (opcode >= OP_SBRA || opcode == OP_ONCE)
8220        {        {
8221        /* Checking zero-length iteration. */        /* Checking zero-length iteration. */
8222        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize < 0)
# Line 7648  else if (ket == OP_KETRMIN) Line 8226  else if (ket == OP_KETRMIN)
8226          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
8227          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (CURRENT_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw), CURRENT_AS(bracket_backtrack)->recursive_matchingpath);          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (CURRENT_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw), CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8228          }          }
8229          /* Drop STR_PTR for non-greedy plus quantifier. */
8230        if (opcode != OP_ONCE)        if (opcode != OP_ONCE)
8231          free_stack(common, 1);          free_stack(common, 1);
8232        }        }
8233      else      else
8234        JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);        JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8235      }      }
8236    rminlabel = LABEL();    rmin_label = LABEL();
8237      if (repeat_type != 0)
8238        OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
8239    }    }
8240  else if (bra == OP_BRAZERO)  else if (bra == OP_BRAZERO)
8241    {    {
# Line 7662  else if (bra == OP_BRAZERO) Line 8243  else if (bra == OP_BRAZERO)
8243    free_stack(common, 1);    free_stack(common, 1);
8244    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);
8245    }    }
8246    else if (repeat_type == OP_EXACT)
8247      {
8248      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
8249      exact_label = LABEL();
8250      }
8251    
8252  if (offset != 0)  if (offset != 0)
8253    {    {
# Line 7781  if (has_alternatives) Line 8367  if (has_alternatives)
8367      current->top = NULL;      current->top = NULL;
8368      current->topbacktracks = NULL;      current->topbacktracks = NULL;
8369      current->nextbacktracks = NULL;      current->nextbacktracks = NULL;
8370        /* Conditional blocks always have an additional alternative, even if it is empty. */
8371      if (*cc == OP_ALT)      if (*cc == OP_ALT)
8372        {        {
8373        ccprev = cc + 1 + LINK_SIZE;        ccprev = cc + 1 + LINK_SIZE;
8374        cc += GET(cc, 1);        cc += GET(cc, 1);
8375        if (opcode != OP_COND && opcode != OP_SCOND)        if (opcode != OP_COND && opcode != OP_SCOND)
8376          {          {
8377          if (private_data_ptr != 0 && opcode != OP_ONCE)          if (opcode != OP_ONCE)
8378            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);            {
8379              if (private_data_ptr != 0)
8380                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
8381              else
8382                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8383              }
8384          else          else
8385            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(needs_control_head ? 1 : 0));
8386          }          }
8387        compile_matchingpath(common, ccprev, cc, current);        compile_matchingpath(common, ccprev, cc, current);
8388        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
8389          return;          return;
8390        }        }
8391    
8392      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is successfully matched. */
8393      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8394      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8395        {        match_once_common(common, ket, CURRENT_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
       if (CURRENT_AS(bracket_backtrack)->u.framesize < 0)  
         {  
         OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
         /* TMP2 which is set here used by OP_KETRMAX below. */  
         if (ket == OP_KETRMAX)  
           OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);  
         else if (ket == OP_KETRMIN)  
           {  
           /* Move the STR_PTR to the private_data_ptr. */  
           OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);  
           }  
         }  
       else  
         {  
         OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (CURRENT_AS(bracket_backtrack)->u.framesize + 2) * sizeof(sljit_sw));  
         if (ket == OP_KETRMAX)  
           {  
           /* TMP2 which is set here used by OP_KETRMAX below. */  
           OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  
           }  
         }  
       }  
8396    
8397      stacksize = 0;      stacksize = 0;
8398        if (repeat_type == OP_MINUPTO)
8399          {
8400          /* We need to preserve the counter. TMP2 will be used below. */
8401          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);
8402          stacksize++;
8403          }
8404      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
8405        stacksize++;        stacksize++;
8406      if (offset != 0)      if (offset != 0)
# Line 7837  if (has_alternatives) Line 8413  if (has_alternatives)
8413      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8414        stacksize++;        stacksize++;
8415    
8416      if (stacksize > 0) {      if (stacksize > 0)
8417        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)        allocate_stack(common, stacksize);
         allocate_stack(common, stacksize);  
       else  
         {  
         /* We know we have place at least for one item on the top of the stack. */  
         SLJIT_ASSERT(stacksize == 1);  
         OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));  
         }  
     }  
8418    
8419      stacksize = 0;      stacksize = 0;
8420        if (repeat_type == OP_MINUPTO)
8421          {
8422          /* TMP2 was set above. */
8423          OP2(SLJIT_SUB, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0, SLJIT_IMM, 1);
8424          stacksize++;
8425          }
8426    
8427      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
8428        {        {
8429        if (ket != OP_KET)        if (ket != OP_KET)
# Line 7859  if (has_alternatives) Line 8434  if (has_alternatives)
8434        }        }
8435    
8436      if (offset != 0)      if (offset != 0)
8437        {        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
       if (common->capture_last_ptr != 0)  
         {  
         OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);  
         OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);  
         OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);  
         stacksize++;  
         }  
       if (common->optimized_cbracket[offset >> 1] == 0)  
         {  
         OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
         OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
         OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);  
         OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
         OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);  
         OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);  
         OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);  
         stacksize += 2;  
         }  
       }  
8438    
8439      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8440        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);
# Line 7951  else if (opcode == OP_SBRA || opcode == Line 8507  else if (opcode == OP_SBRA || opcode ==
8507  else if (opcode == OP_ONCE)  else if (opcode == OP_ONCE)
8508    {    {
8509    cc = ccbegin + GET(ccbegin, 1);    cc = ccbegin + GET(ccbegin, 1);
8510      stacksize = needs_control_head ? 1 : 0;
8511    
8512    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
8513      {      {
8514      /* Reset head and drop saved frame. */      /* Reset head and drop saved frame. */
8515      stacksize = (ket == OP_KETRMAX || ket == OP_KETRMIN || *cc == OP_ALT) ? 2 : 1;      stacksize += CURRENT_AS(bracket_backtrack)->u.framesize + ((ket != OP_KET || *cc == OP_ALT) ? 2 : 1);
     free_stack(common, CURRENT_AS(bracket_backtrack)->u.framesize + stacksize);  
8516      }      }
8517    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))
8518      {      {
8519      /* The STR_PTR must be released. */      /* The STR_PTR must be released. */
8520      free_stack(common, 1);      stacksize++;
8521      }      }
8522      free_stack(common, stacksize);
8523    
8524    JUMPHERE(once);    JUMPHERE(once);
8525    /* Restore previous private_data_ptr */    /* Restore previous private_data_ptr */
# Line 7976  else if (opcode == OP_ONCE) Line 8534  else if (opcode == OP_ONCE)
8534      }      }
8535    }    }
8536    
8537  if (ket == OP_KETRMAX)  if (repeat_type == OP_EXACT)
8538      {
8539      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
8540      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0);
8541      CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, repeat_count, exact_label);
8542      }
8543    else if (ket == OP_KETRMAX)
8544    {    {
8545    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8546    if (bra != OP_BRAZERO)    if (bra != OP_BRAZERO)
8547      free_stack(common, 1);      free_stack(common, 1);
8548    
8549    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8550    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
8551      {      {
# Line 7999  else if (ket == OP_KETRMIN) Line 8564  else if (ket == OP_KETRMIN)
8564    affect badly the free_stack(2) above. */    affect badly the free_stack(2) above. */
8565    if (opcode != OP_ONCE)    if (opcode != OP_ONCE)
8566      free_stack(common, 1);      free_stack(common, 1);
8567    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, rminlabel);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, rmin_label);
8568    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
8569      free_stack(common, bra == OP_BRAMINZERO ? 2 : 1);      free_stack(common, bra == OP_BRAMINZERO ? 2 : 1);
8570    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
# Line 8013  else if (bra == OP_BRAZERO) Line 8578  else if (bra == OP_BRAZERO)
8578    }    }
8579  }  }
8580    
8581  static void compile_bracketpos_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_bracketpos_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8582  {  {
8583  DEFINE_COMPILER;  DEFINE_COMPILER;
8584  int offset;  int offset;
# Line 8052  if (current->topbacktracks) Line 8617  if (current->topbacktracks)
8617  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_sw));
8618  }  }
8619    
8620  static void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8621  {  {
8622  assert_backtrack backtrack;  assert_backtrack backtrack;
8623    
# Line 8076  else Line 8641  else
8641  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);
8642  }  }
8643    
8644    static SLJIT_INLINE void compile_control_verb_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8645    {
8646    DEFINE_COMPILER;
8647    pcre_uchar opcode = *current->cc;
8648    struct sljit_label *loop;
8649    struct sljit_jump *jump;
8650    
8651    if (opcode == OP_THEN || opcode == OP_THEN_ARG)
8652      {
8653      if (common->then_trap != NULL)
8654        {
8655        SLJIT_ASSERT(common->control_head_ptr != 0);
8656    
8657        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8658        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, type_then_trap);
8659        OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, common->then_trap->start);
8660        jump = JUMP(SLJIT_JUMP);
8661    
8662        loop = LABEL();
8663        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), -(int)sizeof(sljit_sw));
8664        JUMPHERE(jump);
8665        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), -(int)(2 * sizeof(sljit_sw)), TMP1, 0, loop);
8666        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), -(int)(3 * sizeof(sljit_sw)), TMP2, 0, loop);
8667        add_jump(compiler, &common->then_trap->quit, JUMP(SLJIT_JUMP));
8668        return;
8669        }
8670      else if (common->positive_assert)
8671        {
8672        add_jump(compiler, &common->positive_assert_quit, JUMP(SLJIT_JUMP));
8673        return;
8674        }
8675      }
8676    
8677    if (common->local_exit)
8678      {
8679      if (common->quit_label == NULL)
8680        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8681      else
8682        JUMPTO(SLJIT_JUMP, common->quit_label);
8683      return;
8684      }
8685    
8686    if (opcode == OP_SKIP_ARG)
8687      {
8688      SLJIT_ASSERT(common->control_head_ptr != 0);
8689      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8690      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
8691      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, (sljit_sw)(current->cc + 2));
8692      sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_search_mark));
8693      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
8694    
8695      OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
8696      add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));
8697      return;
8698      }
8699    
8700    if (opcode == OP_SKIP)
8701      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8702    else
8703      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_IMM, 0);
8704    add_jump(compiler, &common->reset_match, JUMP(SLJIT_JUMP));
8705    }
8706    
8707    static SLJIT_INLINE void compile_then_trap_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8708    {
8709    DEFINE_COMPILER;
8710    struct sljit_jump *jump;
8711    int size;
8712    
8713    if (CURRENT_AS(then_trap_backtrack)->then_trap)
8714      {
8715      common->then_trap = CURRENT_AS(then_trap_backtrack)->then_trap;
8716      return;
8717      }
8718    
8719    size = CURRENT_AS(then_trap_backtrack)->framesize;
8720    size = 3 + (size < 0 ? 0 : size);
8721    
8722    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(size - 3));
8723    free_stack(common, size);
8724    jump = JUMP(SLJIT_JUMP);
8725    
8726    set_jumps(CURRENT_AS(then_trap_backtrack)->quit, LABEL());
8727    /* STACK_TOP is set by THEN. */
8728    if (CURRENT_AS(then_trap_backtrack)->framesize >= 0)
8729      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
8730    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8731    free_stack(common, 3);
8732    
8733    JUMPHERE(jump);
8734    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
8735    }
8736    
8737  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8738  {  {
8739  DEFINE_COMPILER;  DEFINE_COMPILER;
8740    then_trap_backtrack *save_then_trap = common->then_trap;
8741    
8742  while (current)  while (current)
8743    {    {
# Line 8167  while (current) Line 8826  while (current)
8826    
8827      case OP_REF:      case OP_REF:
8828      case OP_REFI:      case OP_REFI:
8829        case OP_DNREF:
8830        case OP_DNREFI:
8831      compile_ref_iterator_backtrackingpath(common, current);      compile_ref_iterator_backtrackingpath(common, current);
8832      break;      break;
8833    
# Line 8212  while (current) Line 8873  while (current)
8873      break;      break;
8874    
8875      case OP_MARK:      case OP_MARK:
8876      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0));
8877      free_stack(common, 1);      if (common->has_skip_arg)
8878          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8879        free_stack(common, common->has_skip_arg ? 5 : 1);
8880      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP1, 0);
8881        if (common->has_skip_arg)
8882          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP2, 0);
8883      break;      break;
8884    
8885        case OP_THEN:
8886        case OP_THEN_ARG:
8887      case OP_PRUNE:      case OP_PRUNE:
8888      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
8889      case OP_SKIP:      case OP_SKIP:
8890      if (!common->local_exit)      case OP_SKIP_ARG:
8891        {      compile_control_verb_backtrackingpath(common, current);
       SLJIT_ASSERT(common->control_head_ptr != 0);  
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);  
       sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_check_control_chain));  
       OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
   
       OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);  
       add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));  
   
       OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);  
       }  
   
     /* Commit or in recurse or accept. */  
     if (common->quit_label == NULL)  
       add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));  
     else  
       JUMPTO(SLJIT_JUMP, common->quit_label);  
8892      break;      break;
8893    
8894      case OP_COMMIT:      case OP_COMMIT:
# Line 8257  while (current) Line 8907  while (current)
8907      set_jumps(current->topbacktracks, LABEL());      set_jumps(current->topbacktracks, LABEL());
8908      break;      break;
8909    
8910        case OP_THEN_TRAP:
8911        /* A virtual opcode for then traps. */
8912        compile_then_trap_backtrackingpath(common, current);
8913        break;
8914    
8915      default:      default:
8916      SLJIT_ASSERT_STOP();      SLJIT_ASSERT_STOP();
8917      break;      break;
8918      }      }
8919    current = current->prev;    current = current->prev;
8920    }    }
8921    common->then_trap = save_then_trap;
8922  }  }
8923    
8924  static SLJIT_INLINE void compile_recurse(compiler_common *common)  static SLJIT_INLINE void compile_recurse(compiler_common *common)
# Line 8271  DEFINE_COMPILER; Line 8927  DEFINE_COMPILER;
8927  pcre_uchar *cc = common->start + common->currententry->start;  pcre_uchar *cc = common->start + common->currententry->start;
8928  pcre_uchar *ccbegin = cc + 1 + LINK_SIZE + (*cc == OP_BRA ? 0 : IMM2_SIZE);  pcre_uchar *ccbegin = cc + 1 + LINK_SIZE + (*cc == OP_BRA ? 0 : IMM2_SIZE);
8929  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
8930  int private_data_size = get_private_data_length_for_copy(common, ccbegin, ccend);  BOOL needs_control_head;
8931  int framesize = get_framesize(common, cc, TRUE);  int framesize = get_framesize(common, cc, NULL, TRUE, &needs_control_head);
8932    int private_data_size = get_private_data_copy_length(common, ccbegin, ccend, needs_control_head);
8933  int alternativesize;  int alternativesize;
8934  BOOL needs_frame;  BOOL needs_frame;
8935  backtrack_common altbacktrack;  backtrack_common altbacktrack;
8936  struct sljit_jump *jump;  struct sljit_jump *jump;
8937    
8938    /* Recurse captures then. */
8939    common->then_trap = NULL;
8940    
8941  SLJIT_ASSERT(*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_CBRAPOS || *cc == OP_SCBRA || *cc == OP_SCBRAPOS);  SLJIT_ASSERT(*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_CBRAPOS || *cc == OP_SCBRA || *cc == OP_SCBRAPOS);
8942  needs_frame = framesize >= 0;  needs_frame = framesize >= 0;
8943  if (!needs_frame)  if (!needs_frame)
# Line 8291  set_jumps(common->currententry->calls, c Line 8951  set_jumps(common->currententry->calls, c
8951  sljit_emit_fast_enter(compiler, TMP2, 0);  sljit_emit_fast_enter(compiler, TMP2, 0);
8952  allocate_stack(common, private_data_size + framesize + alternativesize);  allocate_stack(common, private_data_size + framesize + alternativesize);
8953  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(private_data_size + framesize + alternativesize - 1), TMP2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(private_data_size + framesize + alternativesize - 1), TMP2, 0);
8954  copy_private_data(common, ccbegin, ccend, TRUE, private_data_size + framesize + alternativesize, framesize + alternativesize);  copy_private_data(common, ccbegin, ccend, TRUE, private_data_size + framesize + alternativesize, framesize + alternativesize, needs_control_head);
8955  if (common->control_head_ptr != 0)  if (needs_control_head)
8956    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
8957  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, STACK_TOP, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, STACK_TOP, 0);
8958  if (needs_frame)  if (needs_frame)
8959    init_frame(common, cc, framesize + alternativesize - 1, alternativesize, TRUE);    init_frame(common, cc, NULL, framesize + alternativesize - 1, alternativesize, TRUE);
8960    
8961  if (alternativesize > 0)  if (alternativesize > 0)
8962    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
# Line 8366  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1); Line 9026  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1);
9026  JUMPHERE(jump);  JUMPHERE(jump);
9027  if (common->quit != NULL)  if (common->quit != NULL)
9028    set_jumps(common->quit, LABEL());    set_jumps(common->quit, LABEL());
9029  copy_private_data(common, ccbegin, ccend, FALSE, private_data_size + framesize + alternativesize, framesize + alternativesize);  copy_private_data(common, ccbegin, ccend, FALSE, private_data_size + framesize + alternativesize, framesize + alternativesize, needs_control_head);
9030  free_stack(common, private_data_size + framesize + alternativesize);  free_stack(common, private_data_size + framesize + alternativesize);
9031  if (common->control_head_ptr != 0)  if (needs_control_head)
9032    {    {
9033    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 2 * sizeof(sljit_sw));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 2 * sizeof(sljit_sw));
9034    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));
# Line 8462  else Line 9122  else
9122  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9123  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9124  common->digits[0] = -2;  common->digits[0] = -2;
9125  common->name_table = (sljit_sw)((pcre_uchar *)re + re->name_table_offset);  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
9126  common->name_count = re->name_count;  common->name_count = re->name_count;
9127  common->name_entry_size = re->name_entry_size;  common->name_entry_size = re->name_entry_size;
9128  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
# Line 8476  common->use_ucp = (re->options & PCRE_UC Line 9136  common->use_ucp = (re->options & PCRE_UC
9136  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(rootbacktrack.cc);
9137    
9138  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9139  common->ovector_start = CALL_LIMIT + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
9140  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);
9141  if (!common->optimized_cbracket)  if (!common->optimized_cbracket)
9142    return;    return;
# Line 8491  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA Line 9151  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA
9151  common->capture_last_ptr = common->ovector_start;  common->capture_last_ptr = common->ovector_start;
9152  common->ovector_start += sizeof(sljit_sw);  common->ovector_start += sizeof(sljit_sw);
9153  #endif  #endif
9154  private_data_size = get_private_data_length(common, rootbacktrack.cc, ccend);  if (!check_opcode_types(common, rootbacktrack.cc, ccend))
 if (private_data_size < 0)  
9155    {    {
9156    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9157    return;    return;
# Line 8554  if (common->capture_last_ptr != 0) Line 9213  if (common->capture_last_ptr != 0)
9213