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

Diff of /code/trunk/pcre_jit_compile.c

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

revision 1269 by zherczeg, Mon Mar 4 10:47:12 2013 UTC revision 1406 by zherczeg, Sat Nov 30 07:05:00 2013 UTC
# Line 71  system files. */ Line 71  system files. */
71     2 - Enable capture_last_ptr (includes option 1). */     2 - Enable capture_last_ptr (includes option 1). */
72  /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */  /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77  /* Allocate memory for the regex stack on the real machine stack.  /* Allocate memory for the regex stack on the real machine stack.
78  Fast, but limited size. */  Fast, but limited size. */
79  #define MACHINE_STACK_SIZE 32768  #define MACHINE_STACK_SIZE 32768
# Line 165  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 179  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 193  typedef struct stub_list { Line 197  typedef struct stub_list {
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200  enum frame_types { no_frame = -1, no_stack = -2 };  enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
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 215  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 236  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 271  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 279  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 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 6  #define MAX_RANGE_SIZE 6
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* 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 cbraptr;    int cbra_ptr;
326    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
# Line 305  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342    /* Points to the last matched capture block index. */    /* Points to the last matched capture block index. */
343    int capture_last_ptr;    int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
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 found in the pattern. */
353      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. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      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;
367    int bsr_nltype;    int bsr_nltype;
368    /* Dollar endonly. */    /* Dollar endonly. */
369    int endonly;    int endonly;
   BOOL has_set_som;  
370    /* Tables. */    /* Tables. */
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 338  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 349  typedef struct compiler_common { Line 397  typedef struct compiler_common {
397    jump_list *vspace;    jump_list *vspace;
398    jump_list *casefulcmp;    jump_list *casefulcmp;
399    jump_list *caselesscmp;    jump_list *caselesscmp;
400      jump_list *reset_match;
401    BOOL jscript_compat;    BOOL jscript_compat;
402  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
403    BOOL utf;    BOOL utf;
# Line 415  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 426  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->cbraptr + (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 486  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 536  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 565  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:
631      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 670  switch(*cc) Line 728  switch(*cc)
728  #endif  #endif
729    
730    case OP_MARK:    case OP_MARK:
731      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)  
744  {  {
745  switch(*cc)  int count;
746    {  pcre_uchar *slot;
   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)  
 {  
 int private_data_length = 0;  
 pcre_uchar *alternative;  
 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 782  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 807  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;  
     break;  
   
     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);  
795      break;      break;
796    
 #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 921  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:
822        common->needs_start_ptr = TRUE;
823        /* Fall through. */
824    
825      case OP_MARK:      case OP_MARK:
826      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
827        {        {
# Line 930  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:
840        case OP_SKIP:
841        common->needs_start_ptr = TRUE;
842        cc += 1;
843        break;
844    
845        case OP_SKIP_ARG:
846        common->control_head_ptr = 1;
847        common->has_skip_arg = TRUE;
848        cc += 1 + 2 + cc[1];
849        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        next_end = bracketend(next + 2 + LINK_SIZE);
930        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
931          break;
932        next = next_end;
933        max++;
934        }
935    
936      if (next[0] == type && next[1] == *begin && max >= 1)
937        {
938        next_end = bracketend(next + 1);
939        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
940        {        {
941        cc += -size;        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
942  #ifdef SUPPORT_UTF          if (*next_end != OP_KET)
943        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);            break;
944  #endif  
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        }        }
     else  
       cc += size;  
957      }      }
958      }
959    
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    #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    if (bracketlen != 0)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1016      {      case OP_TYPESTAR: \
1017      if (cc >= end)      case OP_TYPEPLUS:
1018        {  
1019        end = bracketend(cc);  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1020        if (end[-1 - LINK_SIZE] == OP_KET)      case OP_TYPEUPTO: \
1021          end = NULL;      case OP_TYPEMINUPTO:
       }  
     cc += bracketlen;  
     }  
   }  
 return private_data_length;  
 }  
1022    
1023  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  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 979  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 1074  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 1104  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 1118  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 1142  while (cc < ccend) Line 1231  while (cc < ccend)
1231      break;      break;
1232    
1233      case OP_MARK:      case OP_MARK:
1234        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 1149  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 1268  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 1283  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 1304  while (cc < ccend) Line 1401  while (cc < ccend)
1401      break;      break;
1402    
1403      case OP_MARK:      case OP_MARK:
1404        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 1384  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 = 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 1395  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 1499  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 1520  stacktop = STACK(stacktop - 1); Line 1625  stacktop = STACK(stacktop - 1);
1625    
1626  if (!save)  if (!save)
1627    {    {
1628    stackptr += 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 1536  if (!save) Line 1641  if (!save)
1641    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1642    }    }
1643    
1644  while (status != end)  do
1645    {    {
1646    count = 0;    count = 0;
1647    switch(status)    switch(status)
# Line 1545  while (status != end) Line 1650  while (status != end)
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 (needs_control_head)
1654          {
1655          SLJIT_ASSERT(common->control_head_ptr != 0);
1656          count = 2;
1657          srcw[1] = common->control_head_ptr;
1658          }
1659      status = loop;      status = loop;
1660      break;      break;
1661    
# Line 1557  while (status != end) Line 1668  while (status != end)
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 1769  while (status != end) Line 1889  while (status != end)
1889        }        }
1890      }      }
1891    }    }
1892    while (status != end);
1893    
1894  if (save)  if (save)
1895    {    {
# Line 1802  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 1865  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 1900  static SLJIT_INLINE void reset_ovector(c Line 2054  static SLJIT_INLINE void reset_ovector(c
2054  DEFINE_COMPILER;  DEFINE_COMPILER;
2055  struct sljit_label *loop;  struct sljit_label *loop;
2056  int i;  int i;
2057    
2058  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2059    SLJIT_ASSERT(length > 1);
2060  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2061  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2062  if (length < 8)  if (length < 8)
2063    {    {
2064    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
2065      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2066    }    }
2067  else  else
2068    {    {
2069    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2070    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2071    loop = LABEL();    loop = LABEL();
2072    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2073    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
# Line 1919  else Line 2075  else
2075    }    }
2076  }  }
2077    
2078    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2079    {
2080    DEFINE_COMPILER;
2081    struct sljit_label *loop;
2082    int i;
2083    
2084    SLJIT_ASSERT(length > 1);
2085    /* OVECTOR(1) contains the "string begin - 1" constant. */
2086    if (length > 2)
2087      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2088    if (length < 8)
2089      {
2090      for (i = 2; i < length; i++)
2091        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2092      }
2093    else
2094      {
2095      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2096      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2097      loop = LABEL();
2098      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2099      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2100      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2101      }
2102    
2103    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2104    if (common->mark_ptr != 0)
2105      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2106    if (common->control_head_ptr != 0)
2107      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));
2109    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));
2111    }
2112    
2113    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2114    {
2115    while (current != NULL)
2116      {
2117      switch (current[-2])
2118        {
2119        case type_then_trap:
2120        break;
2121    
2122        case type_mark:
2123        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2124          return current[-4];
2125        break;
2126    
2127        default:
2128        SLJIT_ASSERT_STOP();
2129        break;
2130        }
2131      current = (sljit_sw*)current[-1];
2132      }
2133    return -1;
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)
2137  {  {
2138  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1975  DEFINE_COMPILER; Line 2189  DEFINE_COMPILER;
2189  struct sljit_jump *jump;  struct sljit_jump *jump;
2190    
2191  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2192  SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2193      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2194    
2195  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2196  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
# Line 1987  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->start_used_ptr + 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 2155  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 3812  const pcre_uint32 *other_cases; Line 4027  const pcre_uint32 *other_cases;
4027  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4028  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4029  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4030    
4031  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4032  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4033  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
# Line 3911  while (*cc != XCL_END) Line 4127  while (*cc != XCL_END)
4127        case PT_SPACE:        case PT_SPACE:
4128        case PT_PXSPACE:        case PT_PXSPACE:
4129        case PT_WORD:        case PT_WORD:
4130          case PT_PXGRAPH:
4131          case PT_PXPRINT:
4132          case PT_PXPUNCT:
4133        needstype = TRUE;        needstype = TRUE;
4134        needschar = TRUE;        needschar = TRUE;
4135        break;        break;
# Line 4098  while (*cc != XCL_END) Line 4317  while (*cc != XCL_END)
4317    
4318        case PT_SPACE:        case PT_SPACE:
4319        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);  
         }  
4320        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4321        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);
4322        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);
4323        if (*cc == PT_SPACE)  
4324          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4325          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4326    
4327          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4328          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4329    
4330        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4331        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 4199  while (*cc != XCL_END) Line 4417  while (*cc != XCL_END)
4417        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);
4418        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4419        break;        break;
4420    
4421          case PT_PXGRAPH:
4422          /* C and Z groups are the farthest two groups. */
4423          SET_TYPE_OFFSET(ucp_Ll);
4424          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4425          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4426    
4427          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4428    
4429          /* In case of ucp_Cf, we overwrite the result. */
4430          SET_CHAR_OFFSET(0x2066);
4431          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4432          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4433    
4434          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4435          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4436    
4437          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4438          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4439    
4440          JUMPHERE(jump);
4441          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4442          break;
4443    
4444          case PT_PXPRINT:
4445          /* C and Z groups are the farthest two groups. */
4446          SET_TYPE_OFFSET(ucp_Ll);
4447          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4448          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4449    
4450          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4451          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4452    
4453          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4454    
4455          /* In case of ucp_Cf, we overwrite the result. */
4456          SET_CHAR_OFFSET(0x2066);
4457          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4458          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4459    
4460          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4461          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4462    
4463          JUMPHERE(jump);
4464          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4465          break;
4466    
4467          case PT_PXPUNCT:
4468          SET_TYPE_OFFSET(ucp_Sc);
4469          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4470          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4471    
4472          SET_CHAR_OFFSET(0);
4473          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4474          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4475    
4476          SET_TYPE_OFFSET(ucp_Pc);
4477          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4478          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4479          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4480          break;
4481        }        }
4482      cc += 2;      cc += 2;
4483      }      }
# Line 4837  if (context.length > 0) Line 5116  if (context.length > 0)
5116  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5117  }  }
5118    
 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));  
 }  
   
5119  /* Forward definitions. */  /* Forward definitions. */
5120  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5121  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
# Line 4891  static void compile_backtrackingpath(com Line 5148  static void compile_backtrackingpath(com
5148    
5149  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5150    
5151  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)
5152    {
5153    /* The OVECTOR offset goes to TMP2. */
5154    DEFINE_COMPILER;
5155    int count = GET2(cc, 1 + IMM2_SIZE);
5156    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5157    unsigned int offset;
5158    jump_list *found = NULL;
5159    
5160    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5161    
5162    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5163    
5164    count--;
5165    while (count-- > 0)
5166      {
5167      offset = GET2(slot, 0) << 1;
5168      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5169      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5170      slot += common->name_entry_size;
5171      }
5172    
5173    offset = GET2(slot, 0) << 1;
5174    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5175    if (backtracks != NULL && !common->jscript_compat)
5176      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5177    
5178    set_jumps(found, LABEL());
5179    }
5180    
5181    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5182  {  {
5183  DEFINE_COMPILER;  DEFINE_COMPILER;
5184  int offset = GET2(cc, 1) << 1;  BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5185    int offset = 0;
5186  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5187  struct sljit_jump *partial;  struct sljit_jump *partial;
5188  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5189    
5190  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5191  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5192  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5193    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));
5194      /* OVECTOR(1) contains the "string begin - 1" constant. */
5195      if (withchecks && !common->jscript_compat)
5196        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5197      }
5198    else
5199      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5200    
5201  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5202  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5203    {    {
5204    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);
5205    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5206        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5207      else
5208        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5209    
5210    if (withchecks)    if (withchecks)
5211      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5212    
# Line 4933  if (common->utf && *cc == OP_REFI) Line 5231  if (common->utf && *cc == OP_REFI)
5231  else  else
5232  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5233    {    {
5234    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5235        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5236      else
5237        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5238    
5239    if (withchecks)    if (withchecks)
5240      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5241    
# Line 4970  if (jump != NULL) Line 5272  if (jump != NULL)
5272    else    else
5273      JUMPHERE(jump);      JUMPHERE(jump);
5274    }    }
 return cc + 1 + IMM2_SIZE;  
5275  }  }
5276    
5277  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)
5278  {  {
5279  DEFINE_COMPILER;  DEFINE_COMPILER;
5280    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5281  backtrack_common *backtrack;  backtrack_common *backtrack;
5282  pcre_uchar type;  pcre_uchar type;
5283    int offset = 0;
5284  struct sljit_label *label;  struct sljit_label *label;
5285  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5286  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 4987  BOOL minimize; Line 5290  BOOL minimize;
5290    
5291  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5292    
5293    if (ref)
5294      offset = GET2(cc, 1) << 1;
5295    else
5296      cc += IMM2_SIZE;
5297  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5298    
5299    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5300  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5301  switch(type)  switch(type)
5302    {    {
# Line 5025  if (!minimize) Line 5334  if (!minimize)
5334    if (min == 0)    if (min == 0)
5335      {      {
5336      allocate_stack(common, 2);      allocate_stack(common, 2);
5337        if (ref)
5338          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5339      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5340      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5341      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5342      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));
5343      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5344        is zero the invalid case is basically the same as an empty case. */
5345        if (ref)
5346          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5347        else
5348          {
5349          compile_dnref_search(common, ccbegin, NULL);
5350          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5351          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5352          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5353          }
5354      /* Restore if not zero length. */      /* Restore if not zero length. */
5355      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));
5356      }      }
5357    else    else
5358      {      {
5359      allocate_stack(common, 1);      allocate_stack(common, 1);
5360        if (ref)
5361          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5362      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5363      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5364          {
5365          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5366          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5367          }
5368        else
5369          {
5370          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5371          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5372          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5373          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5374          }
5375      }      }
5376    
5377    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5378      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5379    
5380    label = LABEL();    label = LABEL();
5381      if (!ref)
5382        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5383    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5384    
5385    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 5074  if (!minimize) Line 5410  if (!minimize)
5410    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5411    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5412    
5413    decrease_call_count(common);    count_match(common);
5414    return cc;    return cc;
5415    }    }
5416    
5417  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5418    if (ref)
5419      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5420  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5421  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5422    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5423    
5424  if (min == 0)  if (min == 0)
5425    {    {
5426    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5427      is zero the invalid case is basically the same as an empty case. */
5428      if (ref)
5429        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5430      else
5431        {
5432        compile_dnref_search(common, ccbegin, NULL);
5433        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5434        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5435        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5436        }
5437      /* Length is non-zero, we can match real repeats. */
5438    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5439    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5440    }    }
5441  else  else
5442    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5443      if (ref)
5444        {
5445        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5446        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5447        }
5448      else
5449        {
5450        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5451        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5452        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5453        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5454        }
5455      }
5456    
5457  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5458  if (max > 0)  if (max > 0)
5459    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));
5460    
5461    if (!ref)
5462      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5463  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5464  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5465    
# Line 5113  if (jump != NULL) Line 5477  if (jump != NULL)
5477    JUMPHERE(jump);    JUMPHERE(jump);
5478  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5479    
5480  decrease_call_count(common);  count_match(common);
5481  return cc;  return cc;
5482  }  }
5483    
# Line 5123  DEFINE_COMPILER; Line 5487  DEFINE_COMPILER;
5487  backtrack_common *backtrack;  backtrack_common *backtrack;
5488  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5489  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5490  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5491  pcre_uchar *start_cc;  pcre_uchar *start_cc;
5492    BOOL needs_control_head;
5493    
5494  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5495    
5496  /* Inlining simple patterns. */  /* Inlining simple patterns. */
5497  if (get_framesize(common, common->start + start, TRUE) == no_stack)  if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5498    {    {
5499    start_cc = common->start + start;    start_cc = common->start + start;
5500    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 5248  allocate_stack(common, CALLOUT_ARG_SIZE Line 5613  allocate_stack(common, CALLOUT_ARG_SIZE
5613  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5614  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5615  SLJIT_ASSERT(common->capture_last_ptr != 0);  SLJIT_ASSERT(common->capture_last_ptr != 0);
5616  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5617  OP1(SLJIT_MOV_UI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5618    
5619  /* These pointer sized fields temporarly stores internal variables. */  /* These pointer sized fields temporarly stores internal variables. */
5620  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
# Line 5258  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CA Line 5623  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CA
5623    
5624  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
5625    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5626  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5627  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5628  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5629    
5630  /* Needed to save important temporary registers. */  /* Needed to save important temporary registers. */
# Line 5288  static pcre_uchar *compile_assert_matchi Line 5653  static pcre_uchar *compile_assert_matchi
5653  {  {
5654  DEFINE_COMPILER;  DEFINE_COMPILER;
5655  int framesize;  int framesize;
5656    int extrasize;
5657    BOOL needs_control_head;
5658  int private_data_ptr;  int private_data_ptr;
5659  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5660  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5297  jump_list *tmp = NULL; Line 5664  jump_list *tmp = NULL;
5664  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5665  jump_list **found;  jump_list **found;
5666  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5667    BOOL save_local_exit = common->local_exit;
5668    BOOL save_positive_assert = common->positive_assert;
5669    then_trap_backtrack *save_then_trap = common->then_trap;
5670  struct sljit_label *save_quit_label = common->quit_label;  struct sljit_label *save_quit_label = common->quit_label;
5671  struct sljit_label *save_accept_label = common->accept_label;  struct sljit_label *save_accept_label = common->accept_label;
5672  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5673    jump_list *save_positive_assert_quit = common->positive_assert_quit;
5674  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5675  struct sljit_jump *jump;  struct sljit_jump *jump;
5676  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5677    
5678    /* Assert captures then. */
5679    common->then_trap = NULL;
5680    
5681  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5682    {    {
5683    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5312  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5686  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5686    }    }
5687  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5688  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5689  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5690  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5691  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5692  opcode = *cc;  opcode = *cc;
# Line 5331  if (bra == OP_BRAMINZERO) Line 5705  if (bra == OP_BRAMINZERO)
5705    
5706  if (framesize < 0)  if (framesize < 0)
5707    {    {
5708    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5709    allocate_stack(common, 1);    if (framesize == no_frame)
5710        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5711      allocate_stack(common, extrasize);
5712      if (needs_control_head)
5713        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5714    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5715      if (needs_control_head)
5716        {
5717        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5718        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5719        }
5720    }    }
5721  else  else
5722    {    {
5723    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5724      allocate_stack(common, framesize + extrasize);
5725    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);
5726    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5727    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);
5728      if (needs_control_head)
5729        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5730    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5731    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5732    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5733        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5734        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5735        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5736        }
5737      else
5738        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5739      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5740    }    }
5741    
5742  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5743  common->quit_label = NULL;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5744  common->quit = NULL;    {
5745      /* Negative assert is stronger than positive assert. */
5746      common->local_exit = TRUE;
5747      common->quit_label = NULL;
5748      common->quit = NULL;
5749      common->positive_assert = FALSE;
5750      }
5751    else
5752      common->positive_assert = TRUE;
5753    common->positive_assert_quit = NULL;
5754    
5755  while (1)  while (1)
5756    {    {
5757    common->accept_label = NULL;    common->accept_label = NULL;
# Line 5363  while (1) Line 5766  while (1)
5766    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5767    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5768      {      {
5769      common->quit_label = save_quit_label;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5770          {
5771          common->local_exit = save_local_exit;
5772          common->quit_label = save_quit_label;
5773          common->quit = save_quit;
5774          }
5775        common->positive_assert = save_positive_assert;
5776        common->then_trap = save_then_trap;
5777      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
5778      common->quit = save_quit;      common->positive_assert_quit = save_positive_assert_quit;
5779      common->accept = save_accept;      common->accept = save_accept;
5780      return NULL;      return NULL;
5781      }      }
# Line 5375  while (1) Line 5785  while (1)
5785    
5786    /* Reset stack. */    /* Reset stack. */
5787    if (framesize < 0)    if (framesize < 0)
5788      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
5789    else {      if (framesize == no_frame)
5790          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5791        else
5792          free_stack(common, extrasize);
5793        if (needs_control_head)
5794          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5795        }
5796      else
5797        {
5798      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5799        {        {
5800        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5801        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
5802          if (needs_control_head)
5803            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5804        }        }
5805      else      else
5806        {        {
5807        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);
5808          if (needs_control_head)
5809            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5810        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5811        }        }
5812    }      }
5813    
5814    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5815      {      {
5816      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
5817      if (conditional)      if (conditional)
5818        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), needs_control_head ? sizeof(sljit_sw) : 0);
5819      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
5820        {        {
5821        if (framesize < 0)        if (framesize < 0)
5822          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
5823        else        else
5824          {          {
5825          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
5826          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + extrasize - 1) * sizeof(sljit_sw));
5827          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5828          }          }
5829        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));
# Line 5418  while (1) Line 5840  while (1)
5840    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5841    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5842      {      {
5843      common->quit_label = save_quit_label;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5844          {
5845          common->local_exit = save_local_exit;
5846          common->quit_label = save_quit_label;
5847          common->quit = save_quit;
5848          }
5849        common->positive_assert = save_positive_assert;
5850        common->then_trap = save_then_trap;
5851      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
5852      common->quit = save_quit;      common->positive_assert_quit = save_positive_assert_quit;
5853      common->accept = save_accept;      common->accept = save_accept;
5854      return NULL;      return NULL;
5855      }      }
# Line 5432  while (1) Line 5861  while (1)
5861    ccbegin = cc;    ccbegin = cc;
5862    cc += GET(cc, 1);    cc += GET(cc, 1);
5863    }    }
5864    
5865    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5866      {
5867      SLJIT_ASSERT(common->positive_assert_quit == NULL);
5868      /* Makes the check less complicated below. */
5869      common->positive_assert_quit = common->quit;
5870      }
5871    
5872  /* None of them matched. */  /* None of them matched. */
5873  if (common->quit != NULL)  if (common->positive_assert_quit != NULL)
5874    set_jumps(common->quit, LABEL());    {
5875      jump = JUMP(SLJIT_JUMP);
5876      set_jumps(common->positive_assert_quit, LABEL());
5877      SLJIT_ASSERT(framesize != no_stack);
5878      if (framesize < 0)
5879        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
5880      else
5881        {
5882        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5883        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5884        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5885        }
5886      JUMPHERE(jump);
5887      }
5888    
5889    if (needs_control_head)
5890      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
5891    
5892  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
5893    {    {
# Line 5446  if (opcode == OP_ASSERT || opcode == OP_ Line 5899  if (opcode == OP_ASSERT || opcode == OP_
5899      {      {
5900      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5901      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5902          {
5903          if (extrasize == 2)
5904            free_stack(common, 1);
5905        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5906          }
5907      else      else
5908        free_stack(common, 1);        free_stack(common, extrasize);
5909      }      }
5910    else    else
5911      {      {
5912      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5913      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5914      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5915        {        {
5916        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5917        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5918        }        }
5919      else      else
5920        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5921      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5922      }      }
5923    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5472  if (opcode == OP_ASSERT || opcode == OP_ Line 5929  if (opcode == OP_ASSERT || opcode == OP_
5929    if (framesize < 0)    if (framesize < 0)
5930      {      {
5931      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
5932      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
5933      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5934      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5935          {
5936        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));
5937          if (extrasize == 2)
5938            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5939          }
5940      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5941        {        {
5942        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));
# Line 5488  if (opcode == OP_ASSERT || opcode == OP_ Line 5949  if (opcode == OP_ASSERT || opcode == OP_
5949        {        {
5950        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5951        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
5952        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 2) * sizeof(sljit_sw));
5953        }        }
5954      else      else
5955        {        {
5956        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5957        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));
5958        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
5959        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
5960            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5961            if (bra == OP_BRAMINZERO)
5962              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5963            }
5964          else
5965            {
5966            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5967            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
5968            }
5969        }        }
5970      }      }
5971    
# Line 5524  else Line 5994  else
5994      {      {
5995      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5996      if (bra != OP_BRA)      if (bra != OP_BRA)
5997          {
5998          if (extrasize == 2)
5999            free_stack(common, 1);
6000        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6001          }
6002      else      else
6003        free_stack(common, 1);        free_stack(common, extrasize);
6004      }      }
6005    else    else
6006      {      {
6007      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6008      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
6009      /* The topmost item should be 0. */      /* The topmost item should be 0. */
6010      if (bra != OP_BRA)      if (bra != OP_BRA)
6011        {        {
6012        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
6013        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6014        }        }
6015      else      else
6016        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
6017      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
6018      }      }
6019    
# Line 5559  else Line 6033  else
6033      }      }
6034    }    }
6035    
6036  common->quit_label = save_quit_label;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6037      {
6038      common->local_exit = save_local_exit;
6039      common->quit_label = save_quit_label;
6040      common->quit = save_quit;
6041      }
6042    common->positive_assert = save_positive_assert;
6043    common->then_trap = save_then_trap;
6044  common->accept_label = save_accept_label;  common->accept_label = save_accept_label;
6045  common->quit = save_quit;  common->positive_assert_quit = save_positive_assert_quit;
6046  common->accept = save_accept;  common->accept = save_accept;
6047  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6048  }  }
6049    
6050  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)
6051  {  {
6052  int condition = FALSE;  DEFINE_COMPILER;
6053  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];  
6054    
6055  for (i = 0; i < name_count; i++)  if (framesize < 0)
6056    {    {
6057    if (GET2(slotA, 0) == refno) break;    if (framesize == no_frame)
6058    slotA += name_entry_size;      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6059    }    else
6060        {
6061        stacksize = needs_control_head ? 1 : 0;
6062        if (ket != OP_KET || has_alternatives)
6063          stacksize++;
6064        free_stack(common, stacksize);
6065        }
6066    
6067  if (i < name_count)    if (needs_control_head)
6068    {      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. */  
6069    
6070    slotB = slotA;    /* TMP2 which is set here used by OP_KETRMAX below. */
6071    while (slotB > name_table)    if (ket == OP_KETRMAX)
6072        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
6073      else if (ket == OP_KETRMIN)
6074      {      {
6075      slotB -= name_entry_size;      /* Move the STR_PTR to the private_data_ptr. */
6076      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;  
6077      }      }
6078      }
6079    else
6080      {
6081      stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
6082      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
6083      if (needs_control_head)
6084        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
6085    
6086    /* Scan up for duplicates */    if (ket == OP_KETRMAX)
   if (!condition)  
6087      {      {
6088      slotB = slotA;      /* TMP2 which is set here used by OP_KETRMAX below. */
6089      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;  
       }  
6090      }      }
6091    }    }
6092  return condition;  if (needs_control_head)
6093      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
6094  }  }
6095    
6096  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)
6097  {  {
6098  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;  
6099    
6100  for (i = 0; i < name_count; i++)  if (common->capture_last_ptr != 0)
6101    {    {
6102    if (GET2(slotA, 0) == recno) break;    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6103    slotA += name_entry_size;    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6104      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6105      stacksize++;
6106    }    }
6107    if (common->optimized_cbracket[offset >> 1] == 0)
 if (i < name_count)  
6108    {    {
6109    /* Found a name for the number - there can be only one; duplicate    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6110    names for different numbers are allowed, but not vice versa. First    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6111    scan down for duplicates. */    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6112      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6113    slotB = slotA;    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6114    while (slotB > name_table)    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6115      {    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6116      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;  
       }  
     }  
6117    }    }
6118  return condition;  return stacksize;
6119  }  }
6120    
6121  /*  /*
# Line 5737  backtrack_common *backtrack; Line 6179  backtrack_common *backtrack;
6179  pcre_uchar opcode;  pcre_uchar opcode;
6180  int private_data_ptr = 0;  int private_data_ptr = 0;
6181  int offset = 0;  int offset = 0;
6182  int stacksize;  int i, stacksize;
6183    int repeat_ptr = 0, repeat_length = 0;
6184    int repeat_type = 0, repeat_count = 0;
6185  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6186  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6187    pcre_uchar *slot;
6188  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6189  pcre_uchar ket;  pcre_uchar ket;
6190  assert_backtrack *assert;  assert_backtrack *assert;
6191  BOOL has_alternatives;  BOOL has_alternatives;
6192    BOOL needs_control_head = FALSE;
6193  struct sljit_jump *jump;  struct sljit_jump *jump;
6194  struct sljit_jump *skip;  struct sljit_jump *skip;
6195  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmax_label = NULL;
6196  struct sljit_jump *braminzerojump = NULL;  struct sljit_jump *braminzero = NULL;
6197    
6198  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);
6199    
# Line 5760  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 6206  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
6206    
6207  opcode = *cc;  opcode = *cc;
6208  ccbegin = cc;  ccbegin = cc;
6209  matchingpath = ccbegin + 1 + LINK_SIZE;  matchingpath = bracketend(cc) - 1 - LINK_SIZE;
6210    ket = *matchingpath;
6211    if (ket == OP_KET && PRIVATE_DATA(matchingpath) != 0)
6212      {
6213      repeat_ptr = PRIVATE_DATA(matchingpath);
6214      repeat_length = PRIVATE_DATA(matchingpath + 1);
6215      repeat_type = PRIVATE_DATA(matchingpath + 2);
6216      repeat_count = PRIVATE_DATA(matchingpath + 3);
6217      SLJIT_ASSERT(repeat_length != 0 && repeat_type != 0 && repeat_count != 0);
6218      if (repeat_type == OP_UPTO)
6219        ket = OP_KETRMAX;
6220      if (repeat_type == OP_MINUPTO)
6221        ket = OP_KETRMIN;
6222      }
6223    
6224  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)
6225    {    {
6226    /* Drop this bracket_backtrack. */    /* Drop this bracket_backtrack. */
6227    parent->top = backtrack->prev;    parent->top = backtrack->prev;
6228    return bracketend(cc);    return matchingpath + 1 + LINK_SIZE + repeat_length;
6229    }    }
6230    
6231  ket = *(bracketend(cc) - 1 - LINK_SIZE);  matchingpath = ccbegin + 1 + LINK_SIZE;
6232  SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);  SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);
6233  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)));
6234  cc += GET(cc, 1);  cc += GET(cc, 1);
6235    
6236  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6237  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND))
6238    {    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);  
     }  
   }  
6239    
6240  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
6241    opcode = OP_SCOND;    opcode = OP_SCOND;
# Line 5819  else if (opcode == OP_ONCE || opcode == Line 6266  else if (opcode == OP_ONCE || opcode ==
6266    SLJIT_ASSERT(private_data_ptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
6267    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
6268    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
6269      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);
6270    }    }
6271    
6272  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
6273  stacksize = 0;  stacksize = 0;
6274  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6275    stacksize++;    stacksize++;
6276  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6277    stacksize++;    stacksize++;
# Line 5833  if (stacksize > 0) Line 6280  if (stacksize > 0)
6280    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6281    
6282  stacksize = 0;  stacksize = 0;
6283  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6284    {    {
6285    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6286    stacksize++;    stacksize++;
# Line 5849  if (bra == OP_BRAMINZERO) Line 6296  if (bra == OP_BRAMINZERO)
6296    if (ket != OP_KETRMIN)    if (ket != OP_KETRMIN)
6297      {      {
6298      free_stack(common, 1);      free_stack(common, 1);
6299      braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);      braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
6300      }      }
6301    else    else
6302      {      {
# Line 5864  if (bra == OP_BRAMINZERO) Line 6311  if (bra == OP_BRAMINZERO)
6311        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6312          {          {
6313          /* 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. */
6314          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);
6315          }          }
6316        else        else
6317          {          {
6318          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
6319          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);
6320          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));
6321          }          }
6322        JUMPHERE(skip);        JUMPHERE(skip);
6323        }        }
# Line 5883  if (bra == OP_BRAMINZERO) Line 6330  if (bra == OP_BRAMINZERO)
6330      }      }
6331    }    }
6332    
6333    if (repeat_type != 0)
6334      {
6335      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, repeat_count);
6336      if (repeat_type == OP_EXACT)
6337        rmax_label = LABEL();
6338      }
6339    
6340  if (ket == OP_KETRMIN)  if (ket == OP_KETRMIN)
6341    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();
6342    
6343  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
6344    {    {
6345    rmaxlabel = LABEL();    rmax_label = LABEL();
6346    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA)    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA && repeat_type == 0)
6347      BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmaxlabel;      BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmax_label;
6348    }    }
6349    
6350  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
6351  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6352    {    {
6353      stacksize = 0;
6354      if (needs_control_head)
6355        {
6356        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6357        stacksize++;
6358        }
6359    
6360    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6361      {      {
6362      /* Neither capturing brackets nor recursions are not found in the block. */      /* Neither capturing brackets nor recursions are found in the block. */
6363      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
6364        {        {
6365        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        stacksize += 2;
6366        allocate_stack(common, 2);        if (!needs_control_head)
6367        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));  
6368        }        }
6369      else if (ket == OP_KETRMAX || has_alternatives)      else
6370        {        {
6371        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6372        allocate_stack(common, 1);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6373        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        if (ket == OP_KETRMAX || has_alternatives)
6374            stacksize++;
6375        }        }
6376      else  
6377        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      if (stacksize > 0)
6378          allocate_stack(common, stacksize);
6379    
6380        stacksize = 0;
6381        if (needs_control_head)
6382          {
6383          stacksize++;
6384          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6385          }
6386    
6387        if (ket == OP_KETRMIN)
6388          {
6389          if (needs_control_head)
6390            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6391          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6392          if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6393            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));
6394          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6395          }
6396        else if (ket == OP_KETRMAX || has_alternatives)
6397          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6398      }      }
6399    else    else
6400      {      {
6401      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)      if (ket != OP_KET || has_alternatives)
6402          stacksize++;
6403    
6404        stacksize += BACKTRACK_AS(bracket_backtrack)->u.framesize + 1;
6405        allocate_stack(common, stacksize);
6406    
6407        if (needs_control_head)
6408          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6409    
6410        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6411        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6412    
6413        stacksize = needs_control_head ? 1 : 0;
6414        if (ket != OP_KET || has_alternatives)
6415        {        {
6416        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);  
6417        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);
6418        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);        stacksize++;
6419        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1, 2, FALSE);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6420        }        }
6421      else      else
6422        {        {
       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));  
6423        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);
6424        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);  
6425        }        }
6426        init_frame(common, ccbegin, NULL, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);
6427      }      }
6428    }    }
6429  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
# Line 5985  if (opcode == OP_COND || opcode == OP_SC Line 6472  if (opcode == OP_COND || opcode == OP_SC
6472        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)));
6473      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
6474      }      }
6475    else if (*matchingpath == OP_NCREF)    else if (*matchingpath == OP_DNCREF)
6476      {      {
6477      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));  
6478    
6479      JUMPHERE(jump);      i = GET2(matchingpath, 1 + IMM2_SIZE);
6480      matchingpath += 1 + IMM2_SIZE;      slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6481        OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
6482        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
6483        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6484        slot += common->name_entry_size;
6485        i--;
6486        while (i-- > 0)
6487          {
6488          OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6489          OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);
6490          slot += common->name_entry_size;
6491          }
6492        OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
6493        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), JUMP(SLJIT_C_ZERO));
6494        matchingpath += 1 + 2 * IMM2_SIZE;
6495      }      }
6496    else if (*matchingpath == OP_RREF || *matchingpath == OP_NRREF)    else if (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF)
6497      {      {
6498      /* Never has other case. */      /* Never has other case. */
6499      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;
6500        SLJIT_ASSERT(!has_alternatives);
6501    
6502      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)  
6503        {        {
6504        SLJIT_ASSERT(!has_alternatives);        stacksize = GET2(matchingpath, 1);
6505          if (common->currententry == NULL)
6506            stacksize = 0;
6507          else if (stacksize == RREF_ANY)
6508            stacksize = 1;
6509          else if (common->currententry->start == 0)
6510            stacksize = stacksize == 0;
6511          else
6512            stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6513    
6514        if (stacksize != 0)        if (stacksize != 0)
6515          matchingpath += 1 + IMM2_SIZE;          matchingpath += 1 + IMM2_SIZE;
6516          }
6517        else
6518          {
6519          if (common->currententry == NULL || common->currententry->start == 0)
6520            stacksize = 0;
6521        else        else
6522          {          {
6523            stacksize = GET2(matchingpath, 1 + IMM2_SIZE);
6524            slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6525            i = (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6526            while (stacksize > 0)
6527              {
6528              if ((int)GET2(slot, 0) == i)
6529                break;
6530              slot += common->name_entry_size;
6531              stacksize--;
6532              }
6533            }
6534    
6535          if (stacksize != 0)
6536            matchingpath += 1 + 2 * IMM2_SIZE;
6537          }
6538    
6539          /* The stacksize == 0 is a common "else" case. */
6540          if (stacksize == 0)
6541            {
6542          if (*cc == OP_ALT)          if (*cc == OP_ALT)
6543            {            {
6544            matchingpath = cc + 1 + LINK_SIZE;            matchingpath = cc + 1 + LINK_SIZE;
# Line 6034  if (opcode == OP_COND || opcode == OP_SC Line 6547  if (opcode == OP_COND || opcode == OP_SC
6547          else          else
6548            matchingpath = cc;            matchingpath = cc;
6549          }          }
       }  
     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;  
       }  
6550      }      }
6551    else    else
6552      {      {
# Line 6072  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 6567  if (SLJIT_UNLIKELY(sljit_get_compiler_er
6567    return NULL;    return NULL;
6568    
6569  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6570    {    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));  
       }  
     }  
   }  
6571    
6572  stacksize = 0;  stacksize = 0;
6573    if (repeat_type == OP_MINUPTO)
6574      {
6575      /* We need to preserve the counter. TMP2 will be used below. */
6576      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);
6577      stacksize++;
6578      }
6579  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6580    stacksize++;    stacksize++;
6581  if (offset != 0)  if (offset != 0)
# Line 6114  if (stacksize > 0) Line 6592  if (stacksize > 0)
6592    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6593    
6594  stacksize = 0;  stacksize = 0;
6595    if (repeat_type == OP_MINUPTO)
6596      {
6597      /* TMP2 was set above. */
6598      OP2(SLJIT_SUB, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0, SLJIT_IMM, 1);
6599      stacksize++;
6600      }
6601    
6602  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6603    {    {
6604    if (ket != OP_KET)    if (ket != OP_KET)
# Line 6124  if (ket != OP_KET || bra != OP_BRA) Line 6609  if (ket != OP_KET || bra != OP_BRA)
6609    }    }
6610    
6611  if (offset != 0)  if (offset != 0)
6612    {    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;  
     }  
   }  
6613    
6614  if (has_alternatives)  if (has_alternatives)
6615    {    {
# Line 6162  if (offset != 0 && common->optimized_cbr Line 6628  if (offset != 0 && common->optimized_cbr
6628    
6629  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
6630    {    {
6631    if (opcode == OP_ONCE || opcode >= OP_SBRA)    if (repeat_type != 0)
6632        {
6633        if (has_alternatives)
6634          BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();
6635        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
6636        JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);
6637        /* Drop STR_PTR for greedy plus quantifier. */
6638        if (opcode != OP_ONCE)
6639          free_stack(common, 1);
6640        }
6641      else if (opcode == OP_ONCE || opcode >= OP_SBRA)
6642      {      {
6643      if (has_alternatives)      if (has_alternatives)
6644        BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();        BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();
6645      /* Checking zero-length iteration. */      /* Checking zero-length iteration. */
6646      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
6647        {        {
6648        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);
6649        /* Drop STR_PTR for greedy plus quantifier. */        /* Drop STR_PTR for greedy plus quantifier. */
6650        if (bra != OP_BRAZERO)        if (bra != OP_BRAZERO)
6651          free_stack(common, 1);          free_stack(common, 1);
6652        }        }
6653      else      else
6654        /* TMP2 must contain the starting STR_PTR. */        /* TMP2 must contain the starting STR_PTR. */
6655        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, rmaxlabel);        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, rmax_label);
6656      }      }
6657    else    else
6658      JUMPTO(SLJIT_JUMP, rmaxlabel);      JUMPTO(SLJIT_JUMP, rmax_label);
6659    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();
6660    }    }
6661    
6662    if (repeat_type == OP_EXACT)
6663      {
6664      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
6665      JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);
6666      }
6667    else if (repeat_type == OP_UPTO)
6668      {
6669      /* We need to preserve the counter. */
6670      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);
6671      allocate_stack(common, 1);
6672      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6673      }
6674    
6675  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6676    BACKTRACK_AS(bracket_backtrack)->zero_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->zero_matchingpath = LABEL();
6677    
# Line 6190  if (bra == OP_BRAMINZERO) Line 6679  if (bra == OP_BRAMINZERO)
6679    {    {
6680    /* This is a backtrack path! (From the viewpoint of OP_BRAMINZERO) */    /* This is a backtrack path! (From the viewpoint of OP_BRAMINZERO) */
6681    JUMPTO(SLJIT_JUMP, ((braminzero_backtrack *)parent)->matchingpath);    JUMPTO(SLJIT_JUMP, ((braminzero_backtrack *)parent)->matchingpath);
6682    if (braminzerojump != NULL)    if (braminzero != NULL)
6683      {      {
6684      JUMPHERE(braminzerojump);      JUMPHERE(braminzero);
6685      /* We need to release the end pointer to perform the      /* We need to release the end pointer to perform the
6686      backtrack for the zero-length iteration. When      backtrack for the zero-length iteration. When
6687      framesize is < 0, OP_ONCE will do the release itself. */      framesize is < 0, OP_ONCE will do the release itself. */
# Line 6208  if (bra == OP_BRAMINZERO) Line 6697  if (bra == OP_BRAMINZERO)
6697    }    }
6698    
6699  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)
6700    decrease_call_count(common);    count_match(common);
6701    
6702  /* Skip the other alternatives. */  /* Skip the other alternatives. */
6703  while (*cc == OP_ALT)  while (*cc == OP_ALT)
6704    cc += GET(cc, 1);    cc += GET(cc, 1);
6705  cc += 1 + LINK_SIZE;  cc += 1 + LINK_SIZE;
6706  return cc;  
6707    /* Temporarily encoding the needs_control_head in framesize. */
6708    if (opcode == OP_ONCE)
6709      BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);
6710    return cc + repeat_length;
6711  }  }
6712    
6713  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 6224  backtrack_common *backtrack; Line 6717  backtrack_common *backtrack;
6717  pcre_uchar opcode;  pcre_uchar opcode;
6718  int private_data_ptr;  int private_data_ptr;
6719  int cbraprivptr = 0;  int cbraprivptr = 0;
6720    BOOL needs_control_head;
6721  int framesize;  int framesize;
6722  int stacksize;  int stacksize;
6723  int offset = 0;  int offset = 0;
6724  BOOL zero = FALSE;  BOOL zero = FALSE;
6725  pcre_uchar *ccbegin = NULL;  pcre_uchar *ccbegin = NULL;
6726  int stack;  int stack; /* Also contains the offset of control head. */
6727  struct sljit_label *loop = NULL;  struct sljit_label *loop = NULL;
6728  struct jump_list *emptymatch = NULL;  struct jump_list *emptymatch = NULL;
6729    
# Line 6267  switch(opcode) Line 6761  switch(opcode)
6761    break;    break;
6762    }    }
6763    
6764  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
6765  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6766  if (framesize < 0)  if (framesize < 0)
6767    {    {
# Line 6280  if (framesize < 0) Line 6774  if (framesize < 0)
6774    else    else
6775      stacksize = 1;      stacksize = 1;
6776    
6777      if (needs_control_head)
6778        stacksize++;
6779    if (!zero)    if (!zero)
6780      stacksize++;      stacksize++;
6781    
# Line 6288  if (framesize < 0) Line 6784  if (framesize < 0)
6784    if (framesize == no_frame)    if (framesize == no_frame)
6785      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);
6786    
6787      stack = 0;
6788    if (offset != 0)    if (offset != 0)
6789      {      {
6790        stack = 2;
6791      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6792      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));
6793      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6794      if (common->capture_last_ptr != 0)      if (common->capture_last_ptr != 0)
6795        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);
6796      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6797        if (needs_control_head)
6798          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6799      if (common->capture_last_ptr != 0)      if (common->capture_last_ptr != 0)
6800          {
6801        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6802          stack = 3;
6803          }
6804      }      }
6805    else    else
6806        {
6807        if (needs_control_head)
6808          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6809      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6810        stack = 1;
6811        }
6812    
6813      if (needs_control_head)
6814        stack++;
6815    if (!zero)    if (!zero)
6816      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);
6817      if (needs_control_head)
6818        {
6819        stack--;
6820        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6821        }
6822    }    }
6823  else  else
6824    {    {
6825    stacksize = framesize + 1;    stacksize = framesize + 1;
6826    if (!zero)    if (!zero)
6827      stacksize++;      stacksize++;
6828    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (needs_control_head)
6829        stacksize++;
6830      if (offset == 0)
6831      stacksize++;      stacksize++;
6832    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
6833    
6834    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6835    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);
6836    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));    if (needs_control_head)
6837    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);
6838      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));
6839    
6840    stack = 0;    stack = 0;
6841    if (!zero)    if (!zero)
6842      {      {
6843      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);
6844        stack = 1;
6845        }
6846      if (needs_control_head)
6847        {
6848        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6849      stack++;      stack++;
6850      }      }
6851    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (offset == 0)
6852      {      {
6853      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);
6854      stack++;      stack++;
6855      }      }
6856    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);
6857    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, NULL, stacksize - 1, stacksize - framesize, FALSE);
6858      stack -= 1 + (offset == 0);
6859    }    }
6860    
6861  if (offset != 0)  if (offset != 0)
# Line 6407  while (*cc != OP_KETRPOS) Line 6931  while (*cc != OP_KETRPOS)
6931          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6932        }        }
6933      }      }
6934    
6935      if (needs_control_head)
6936        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(stack));
6937    
6938    JUMPTO(SLJIT_JUMP, loop);    JUMPTO(SLJIT_JUMP, loop);
6939    flush_stubs(common);    flush_stubs(common);
6940    
# Line 6443  while (*cc != OP_KETRPOS) Line 6971  while (*cc != OP_KETRPOS)
6971    ccbegin = cc + 1 + LINK_SIZE;    ccbegin = cc + 1 + LINK_SIZE;
6972    }    }
6973    
6974    /* We don't have to restore the control head in case of a failed match. */
6975    
6976  backtrack->topbacktracks = NULL;  backtrack->topbacktracks = NULL;
6977  if (!zero)  if (!zero)
6978    {    {
# Line 6454  if (!zero) Line 6984  if (!zero)
6984    
6985  /* None of them matched. */  /* None of them matched. */
6986  set_jumps(emptymatch, LABEL());  set_jumps(emptymatch, LABEL());
6987  decrease_call_count(common);  count_match(common);
6988  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6989  }  }
6990    
6991  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)
6992  {  {
6993  int class_len;  int class_len;
6994    
# Line 6494  else if (*opcode >= OP_TYPESTAR && *opco Line 7024  else if (*opcode >= OP_TYPESTAR && *opco
7024    }    }
7025  else  else
7026    {    {
7027    SLJIT_ASSERT(*opcode >= OP_CLASS || *opcode <= OP_XCLASS);    SLJIT_ASSERT(*opcode == OP_CLASS || *opcode == OP_NCLASS || *opcode == OP_XCLASS);
7028    *type = *opcode;    *type = *opcode;
7029    cc++;    cc++;
7030    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 6505  else Line 7035  else
7035      if (end != NULL)      if (end != NULL)
7036        *end = cc + class_len;        *end = cc + class_len;
7037      }      }
7038      else if (*opcode >= OP_CRPOSSTAR && *opcode <= OP_CRPOSQUERY)
7039        {
7040        *opcode -= OP_CRPOSSTAR - OP_POSSTAR;
7041        if (end != NULL)
7042          *end = cc + class_len;
7043        }
7044    else    else
7045      {      {
7046      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE);      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE || *opcode == OP_CRPOSRANGE);
7047      *arg1 = GET2(cc, (class_len + IMM2_SIZE));      *max = GET2(cc, (class_len + IMM2_SIZE));
7048      *arg2 = GET2(cc, class_len);      *min = GET2(cc, class_len);
7049    
7050      if (*arg2 == 0)      if (*min == 0)
7051        {        {
7052        SLJIT_ASSERT(*arg1 != 0);        SLJIT_ASSERT(*max != 0);
7053        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : OP_MINUPTO;        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : (*opcode == OP_CRMINRANGE ? OP_MINUPTO : OP_POSUPTO);
7054        }        }
7055      if (*arg1 == *arg2)      if (*max == *min)
7056        *opcode = OP_EXACT;        *opcode = OP_EXACT;
7057    
7058      if (end != NULL)      if (end != NULL)
# Line 6527  else Line 7063  else
7063    
7064  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)
7065    {    {
7066    *arg1 = GET2(cc, 0);    *max = GET2(cc, 0);
7067    cc += IMM2_SIZE;    cc += IMM2_SIZE;
7068    }    }
7069    
# Line 6556  DEFINE_COMPILER; Line 7092  DEFINE_COMPILER;
7092  backtrack_common *backtrack;  backtrack_common *backtrack;
7093  pcre_uchar opcode;  pcre_uchar opcode;
7094  pcre_uchar type;  pcre_uchar type;
7095  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7096  pcre_uchar* end;  pcre_uchar* end;
7097  jump_list *nomatch = NULL;  jump_list *nomatch = NULL;
7098  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 6569  int tmp_base, tmp_offset; Line 7105  int tmp_base, tmp_offset;
7105    
7106  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
7107    
7108  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, &end);
7109    
7110  switch(type)  switch(type)
7111    {    {
# Line 6640  switch(opcode) Line 7176  switch(opcode)
7176        {        {
7177        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
7178        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7179        if (opcode == OP_CRRANGE && arg2 > 0)        if (opcode == OP_CRRANGE && min > 0)
7180          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2, label);          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
7181        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && arg1 > 0))        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && max > 0))
7182          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, arg1);          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);
7183        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);
7184        }        }
7185    
# Line 6670  switch(opcode) Line 7206  switch(opcode)
7206      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
7207      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7208        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
7209      else if (opcode == OP_CRRANGE && arg1 == 0)      else if (opcode == OP_CRRANGE && max == 0)
7210        {        {
7211        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);
7212        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
# Line 6680  switch(opcode) Line 7216  switch(opcode)
7216        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7217        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7218        OP1(SLJIT_MOV, base, offset1, TMP1, 0);        OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7219        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 1, label);        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, max + 1, label);
7220        }        }
7221      set_jumps(nomatch, LABEL());      set_jumps(nomatch, LABEL());
7222      if (opcode == OP_CRRANGE)      if (opcode == OP_CRRANGE)
7223        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));
7224      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7225      }      }
7226    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
# Line 6722  switch(opcode) Line 7258  switch(opcode)
7258    break;    break;
7259    
7260    case OP_EXACT:    case OP_EXACT:
7261    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, arg1);    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, max);
7262    label = LABEL();    label = LABEL();
7263    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7264    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 6735  switch(opcode) Line 7271  switch(opcode)
7271    if (opcode == OP_POSPLUS)    if (opcode == OP_POSPLUS)
7272      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7273    if (opcode == OP_POSUPTO)    if (opcode == OP_POSUPTO)
7274      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, arg1);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max);
7275    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7276    label = LABEL();    label = LABEL();
7277    compile_char1_matchingpath(common, type, cc, &nomatch);    compile_char1_matchingpath(common, type, cc, &nomatch);
# Line 6759  switch(opcode) Line 7295  switch(opcode)
7295    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7296    break;    break;
7297    
7298      case OP_CRPOSRANGE:
7299      /* Combination of OP_EXACT and OP_POSSTAR or OP_POSUPTO */
7300      OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, min);
7301      label = LABEL();
7302      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7303      OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);
7304      JUMPTO(SLJIT_C_NOT_ZERO, label);
7305    
7306      if (max != 0)
7307        {
7308        SLJIT_ASSERT(max - min > 0);
7309        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max - min);
7310        }
7311      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7312      label = LABEL();
7313      compile_char1_matchingpath(common, type, cc, &nomatch);
7314      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7315      if (max == 0)
7316        JUMPTO(SLJIT_JUMP, label);
7317      else
7318        {
7319        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, 1);
7320        JUMPTO(SLJIT_C_NOT_ZERO, label);
7321        }
7322      set_jumps(nomatch, LABEL());
7323      OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7324      break;
7325    
7326    default:    default:
7327    SLJIT_ASSERT_STOP();    SLJIT_ASSERT_STOP();
7328    break;    break;
7329    }    }
7330    
7331  decrease_call_count(common);  count_match(common);
7332  return end;  return end;
7333  }  }
7334    
# Line 6822  BOOL optimized_cbracket = common->optimi Line 7386  BOOL optimized_cbracket = common->optimi
7386  if (common->currententry != NULL)  if (common->currententry != NULL)
7387    return cc + 1 + IMM2_SIZE;    return cc + 1 + IMM2_SIZE;
7388    
7389  if (!optimized_cbracket)  if (!optimized_cbracket)
7390    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR_PRIV(offset));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR_PRIV(offset));
7391  offset <<= 1;  offset <<= 1;
7392  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
7393  if (!optimized_cbracket)  if (!optimized_cbracket)
7394    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
7395  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
7396    }
7397    
7398    static SLJIT_INLINE pcre_uchar *compile_control_verb_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
7399    {
7400    DEFINE_COMPILER;
7401    backtrack_common *backtrack;
7402    pcre_uchar opcode = *cc;
7403    pcre_uchar *ccend = cc + 1;
7404    
7405    if (opcode == OP_PRUNE_ARG || opcode == OP_SKIP_ARG || opcode == OP_THEN_ARG)
7406      ccend += 2 + cc[1];
7407    
7408    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
7409    
7410    if (opcode == OP_SKIP)
7411      {
7412      allocate_stack(common, 1);
7413      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
7414      return ccend;
7415      }
7416    
7417    if (opcode == OP_PRUNE_ARG || opcode == OP_THEN_ARG)
7418      {
7419      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7420      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7421      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7422      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7423      }
7424    
7425    return ccend;
7426    }
7427    
7428    static pcre_uchar then_trap_opcode[1] = { OP_THEN_TRAP };
7429    
7430    static SLJIT_INLINE void compile_then_trap_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
7431    {
7432    DEFINE_COMPILER;
7433    backtrack_common *backtrack;
7434    BOOL needs_control_head;
7435    int size;
7436    
7437    PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7438    common->then_trap = BACKTRACK_AS(then_trap_backtrack);
7439    BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7440    BACKTRACK_AS(then_trap_backtrack)->start = (sljit_sw)(cc - common->start);
7441    BACKTRACK_AS(then_trap_backtrack)->framesize = get_framesize(common, cc, ccend, FALSE, &needs_control_head);
7442    
7443    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7444    size = 3 + (size < 0 ? 0 : size);
7445    
7446    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7447    allocate_stack(common, size);
7448    if (size > 3)
7449      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0, SLJIT_IMM, (size - 3) * sizeof(sljit_sw));
7450    else
7451      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7452    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 1), SLJIT_IMM, BACKTRACK_AS(then_trap_backtrack)->start);
7453    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 2), SLJIT_IMM, type_then_trap);
7454    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 3), TMP2, 0);
7455    
7456    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7457    if (size >= 0)
7458      init_frame(common, cc, ccend, size - 1, 0, FALSE);
7459  }  }
7460    
7461  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)
7462  {  {
7463  DEFINE_COMPILER;  DEFINE_COMPILER;
7464  backtrack_common *backtrack;  backtrack_common *backtrack;
7465    BOOL has_then_trap = FALSE;
7466    then_trap_backtrack *save_then_trap = NULL;
7467    
7468    SLJIT_ASSERT(*ccend == OP_END || (*ccend >= OP_ALT && *ccend <= OP_KETRPOS));
7469    
7470    if (common->has_then && common->then_offsets[cc - common->start] != 0)
7471      {
7472      SLJIT_ASSERT(*ccend != OP_END && common->control_head_ptr != 0);
7473      has_then_trap = TRUE;
7474      save_then_trap = common->then_trap;
7475      /* Tail item on backtrack. */
7476      compile_then_trap_matchingpath(common, cc, ccend, parent);
7477      }
7478    
7479  while (cc < ccend)  while (cc < ccend)
7480    {    {
# Line 6960  while (cc < ccend) Line 7600  while (cc < ccend)
7600    
7601      case OP_CLASS:      case OP_CLASS:
7602      case OP_NCLASS:      case OP_NCLASS:
7603      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)
7604        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7605      else      else
7606        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 6968  while (cc < ccend) Line 7608  while (cc < ccend)
7608    
7609  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
7610      case OP_XCLASS:      case OP_XCLASS:
7611      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)
7612        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7613      else      else
7614        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 6977  while (cc < ccend) Line 7617  while (cc < ccend)
7617    
7618      case OP_REF:      case OP_REF:
7619      case OP_REFI:      case OP_REFI:
7620      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)
7621          cc = compile_ref_iterator_matchingpath(common, cc, parent);
7622        else
7623          {
7624          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7625          cc += 1 + IMM2_SIZE;
7626          }
7627        break;
7628    
7629        case OP_DNREF:
7630        case OP_DNREFI:
7631        if (cc[1 + 2 * IMM2_SIZE] >= OP_CRSTAR && cc[1 + 2 * IMM2_SIZE] <= OP_CRPOSRANGE)
7632        cc = compile_ref_iterator_matchingpath(common, cc, parent);        cc = compile_ref_iterator_matchingpath(common, cc, parent);
7633      else      else
7634        cc = compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);        {
7635          compile_dnref_search(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
7636          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7637          cc += 1 + 2 * IMM2_SIZE;
7638          }
7639      break;      break;
7640    
7641      case OP_RECURSE:      case OP_RECURSE:
# Line 7015  while (cc < ccend) Line 7670  while (cc < ccend)
7670        }        }
7671      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();
7672      if (cc[1] > OP_ASSERTBACK_NOT)      if (cc[1] > OP_ASSERTBACK_NOT)
7673        decrease_call_count(common);        count_match(common);
7674      break;      break;
7675    
7676      case OP_ONCE:      case OP_ONCE:
# Line 7051  while (cc < ccend) Line 7706  while (cc < ccend)
7706      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
7707      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
7708      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);
7709      allocate_stack(common, 1);      allocate_stack(common, common->has_skip_arg ? 5 : 1);
7710      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7711      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);
7712      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7713      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);
7714      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);
7715        if (common->has_skip_arg)
7716          {
7717          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7718          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7719          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_mark);
7720          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), SLJIT_IMM, (sljit_sw)(cc + 2));
7721          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0);
7722          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
7723          }
7724      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
7725      break;      break;
7726    
7727        case OP_PRUNE:
7728        case OP_PRUNE_ARG:
7729        case OP_SKIP:
7730        case OP_SKIP_ARG:
7731        case OP_THEN:
7732        case OP_THEN_ARG:
7733      case OP_COMMIT:      case OP_COMMIT:
7734      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      cc = compile_control_verb_matchingpath(common, cc, parent);
     cc += 1;  
7735      break;      break;
7736    
7737      case OP_FAIL:      case OP_FAIL:
# Line 7086  while (cc < ccend) Line 7755  while (cc < ccend)
7755    if (cc == NULL)    if (cc == NULL)
7756      return;      return;
7757    }    }
7758    
7759    if (has_then_trap)
7760      {
7761      /* Head item on backtrack. */
7762      PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7763      BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7764      BACKTRACK_AS(then_trap_backtrack)->then_trap = common->then_trap;
7765      common->then_trap = save_then_trap;
7766      }
7767  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
7768  }  }
7769    
# Line 7110  DEFINE_COMPILER; Line 7788  DEFINE_COMPILER;
7788  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7789  pcre_uchar opcode;  pcre_uchar opcode;
7790  pcre_uchar type;  pcre_uchar type;
7791  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7792  struct sljit_label *label = NULL;  struct sljit_label *label = NULL;
7793  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
7794  jump_list *jumplist = NULL;  jump_list *jumplist = NULL;
# Line 7119  int base = (private_data_ptr == 0) ? SLJ Line 7797  int base = (private_data_ptr == 0) ? SLJ
7797  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
7798  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);
7799    
7800  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, NULL);
7801    
7802  switch(opcode)  switch(opcode)
7803    {    {
# Line 7138  switch(opcode) Line 7816  switch(opcode)
7816    else    else
7817      {      {
7818      if (opcode == OP_UPTO)      if (opcode == OP_UPTO)
7819        arg2 = 0;        min = 0;
7820      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7821        {        {
7822        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
# Line 7148  switch(opcode) Line 7826  switch(opcode)
7826        {        {
7827        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7828        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7829        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, arg2 + 1);        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, min + 1);
7830        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);
7831        }        }
7832      skip_char_back(common);      skip_char_back(common);
# Line 7193  switch(opcode) Line 7871  switch(opcode)
7871    OP1(SLJIT_MOV, base, offset1, TMP1, 0);    OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7872    
7873    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
7874      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2 + 1, label);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min + 1, label);
7875    
7876    if (opcode == OP_CRMINRANGE && arg1 == 0)    if (opcode == OP_CRMINRANGE && max == 0)
7877      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);
7878    else    else
7879      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);
7880    
7881    set_jumps(jumplist, LABEL());    set_jumps(jumplist, LABEL());
7882    if (private_data_ptr == 0)    if (private_data_ptr == 0)
# Line 7233  switch(opcode) Line 7911  switch(opcode)
7911    
7912    case OP_EXACT:    case OP_EXACT:
7913    case OP_POSPLUS:    case OP_POSPLUS:
7914      case OP_CRPOSRANGE:
7915    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7916    break;    break;
7917    
# Line 7247  switch(opcode) Line 7926  switch(opcode)
7926    }    }
7927  }  }
7928    
7929  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)
7930  {  {
7931  DEFINE_COMPILER;  DEFINE_COMPILER;
7932  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7933    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
7934  pcre_uchar type;  pcre_uchar type;
7935    
7936  type = cc[1 + IMM2_SIZE];  type = cc[ref ? 1 + IMM2_SIZE : 1 + 2 * IMM2_SIZE];
7937    
7938  if ((type & 0x1) == 0)  if ((type & 0x1) == 0)
7939    {    {
7940      /* Maximize case. */
7941    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7942    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7943    free_stack(common, 1);    free_stack(common, 1);
# Line 7266  if ((type & 0x1) == 0) Line 7948  if ((type & 0x1) == 0)
7948  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7949  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);
7950  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
7951  free_stack(common, 2);  free_stack(common, ref ? 2 : 3);
7952  }  }
7953    
7954  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)
7955  {  {
7956  DEFINE_COMPILER;  DEFINE_COMPILER;
7957    
# Line 7365  if (bra == OP_BRAZERO) Line 8047  if (bra == OP_BRAZERO)
8047  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8048  {  {
8049  DEFINE_COMPILER;  DEFINE_COMPILER;
8050  int opcode;  int opcode, stacksize, count;
8051  int offset = 0;  int offset = 0;
8052  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;
8053  int stacksize;  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;
 int count;  
8054  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8055  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
8056  pcre_uchar *ccprev;  pcre_uchar *ccprev;
# Line 7379  pcre_uchar bra = OP_BRA; Line 8060  pcre_uchar bra = OP_BRA;
8060  pcre_uchar ket;  pcre_uchar ket;
8061  assert_backtrack *assert;  assert_backtrack *assert;
8062  BOOL has_alternatives;  BOOL has_alternatives;
8063    BOOL needs_control_head = FALSE;
8064  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
8065  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
8066  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
8067  struct sljit_label *rminlabel = NULL;  struct sljit_label *rmin_label = NULL;
8068    struct sljit_label *exact_label = NULL;
8069    
8070  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
8071    {    {
# Line 7391  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 8074  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
8074    }    }
8075    
8076  opcode = *cc;  opcode = *cc;
8077    ccbegin = bracketend(cc) - 1 - LINK_SIZE;
8078    ket = *ccbegin;
8079    if (ket == OP_KET && PRIVATE_DATA(ccbegin) != 0)
8080      {
8081      repeat_ptr = PRIVATE_DATA(ccbegin);
8082      repeat_type = PRIVATE_DATA(ccbegin + 2);
8083      repeat_count = PRIVATE_DATA(ccbegin + 3);
8084      SLJIT_ASSERT(repeat_type != 0 && repeat_count != 0);
8085      if (repeat_type == OP_UPTO)
8086        ket = OP_KETRMAX;
8087      if (repeat_type == OP_MINUPTO)
8088        ket = OP_KETRMIN;
8089      }
8090  ccbegin = cc;  ccbegin = cc;
 ket = *(bracketend(ccbegin) - 1 - LINK_SIZE);  
8091  cc += GET(cc, 1);  cc += GET(cc, 1);
8092  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
8093  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))
# Line 7404  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 8099  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
8099  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
8100    opcode = OP_ONCE;    opcode = OP_ONCE;
8101    
8102    /* Decoding the needs_control_head in framesize. */
8103    if (opcode == OP_ONCE)
8104      {
8105      needs_control_head = (CURRENT_AS(bracket_backtrack)->u.framesize & 0x1) != 0;
8106      CURRENT_AS(bracket_backtrack)->u.framesize >>= 1;
8107      }
8108    
8109    if (ket != OP_KET && repeat_type != 0)
8110      {
8111      /* TMP1 is used in OP_KETRMIN below. */
8112      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8113      free_stack(common, 1);
8114      if (repeat_type == OP_UPTO)
8115        OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0, SLJIT_IMM, 1);
8116      else
8117        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0);
8118      }
8119    
8120  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
8121    {    {
8122    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
# Line 7418  else if (ket == OP_KETRMIN) Line 8131  else if (ket == OP_KETRMIN)
8131    if (bra != OP_BRAMINZERO)    if (bra != OP_BRAMINZERO)
8132      {      {
8133      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8134      if (opcode >= OP_SBRA || opcode == OP_ONCE)      if (repeat_type != 0)
8135          {
8136          /* TMP1 was set a few lines above. */
8137          CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8138          /* Drop STR_PTR for non-greedy plus quantifier. */
8139          if (opcode != OP_ONCE)
8140            free_stack(common, 1);
8141          }
8142        else if (opcode >= OP_SBRA || opcode == OP_ONCE)
8143        {        {
8144        /* Checking zero-length iteration. */        /* Checking zero-length iteration. */
8145        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize < 0)
# Line 7428  else if (ket == OP_KETRMIN) Line 8149  else if (ket == OP_KETRMIN)
8149          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);
8150          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);
8151          }          }
8152          /* Drop STR_PTR for non-greedy plus quantifier. */
8153        if (opcode != OP_ONCE)        if (opcode != OP_ONCE)
8154          free_stack(common, 1);          free_stack(common, 1);
8155        }        }
8156      else      else
8157        JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);        JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8158      }      }
8159    rminlabel = LABEL();    rmin_label = LABEL();
8160      if (repeat_type != 0)
8161        OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
8162    }    }
8163  else if (bra == OP_BRAZERO)  else if (bra == OP_BRAZERO)
8164    {    {
# Line 7442  else if (bra == OP_BRAZERO) Line 8166  else if (bra == OP_BRAZERO)
8166    free_stack(common, 1);    free_stack(common, 1);
8167    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);
8168    }    }
8169    else if (repeat_type == OP_EXACT)
8170      {
8171      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
8172      exact_label = LABEL();
8173      }
8174    
8175  if (offset != 0)  if (offset != 0)
8176    {    {
# Line 7561  if (has_alternatives) Line 8290  if (has_alternatives)
8290      current->top = NULL;      current->top = NULL;
8291      current->topbacktracks = NULL;      current->topbacktracks = NULL;
8292      current->nextbacktracks = NULL;      current->nextbacktracks = NULL;
8293        /* Conditional blocks always have an additional alternative, even if it is empty. */
8294      if (*cc == OP_ALT)      if (*cc == OP_ALT)
8295        {        {
8296        ccprev = cc + 1 + LINK_SIZE;        ccprev = cc + 1 + LINK_SIZE;
8297        cc += GET(cc, 1);        cc += GET(cc, 1);
8298        if (opcode != OP_COND && opcode != OP_SCOND)        if (opcode != OP_COND && opcode != OP_SCOND)
8299          {          {
8300          if (private_data_ptr != 0 && opcode != OP_ONCE)          if (opcode != OP_ONCE)
8301            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);            {
8302              if (private_data_ptr != 0)
8303                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
8304              else
8305                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8306              }
8307          else          else
8308            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));
8309          }          }
8310        compile_matchingpath(common, ccprev, cc, current);        compile_matchingpath(common, ccprev, cc, current);
8311        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
8312          return;          return;
8313        }        }
8314    
8315      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is successfully matched. */
8316      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8317      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8318        {        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));  
           }  
         }  
       }  
8319    
8320      stacksize = 0;      stacksize = 0;
8321        if (repeat_type == OP_MINUPTO)
8322          {
8323          /* We need to preserve the counter. TMP2 will be used below. */
8324          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);
8325          stacksize++;
8326          }
8327      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
8328        stacksize++;        stacksize++;
8329      if (offset != 0)      if (offset != 0)
# Line 7617  if (has_alternatives) Line 8336  if (has_alternatives)
8336      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8337        stacksize++;        stacksize++;
8338    
8339      if (stacksize > 0) {      if (stacksize > 0)
8340        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));  
         }  
     }  
8341    
8342      stacksize = 0;      stacksize = 0;
8343        if (repeat_type == OP_MINUPTO)
8344          {
8345          /* TMP2 was set above. */
8346          OP2(SLJIT_SUB, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0, SLJIT_IMM, 1);
8347          stacksize++;
8348          }
8349    
8350      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
8351        {        {
8352        if (ket != OP_KET)        if (ket != OP_KET)
# Line 7639  if (has_alternatives) Line 8357  if (has_alternatives)
8357        }        }
8358    
8359      if (offset != 0)      if (offset != 0)
8360        {        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;  
         }  
       }  
8361    
8362      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8363        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 7692  if (has_alternatives) Line 8391  if (has_alternatives)
8391      SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND);      SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND);
8392      assert = CURRENT_AS(bracket_backtrack)->u.assert;      assert = CURRENT_AS(bracket_backtrack)->u.assert;
8393      if ((ccbegin[1 + LINK_SIZE] == OP_ASSERT_NOT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK_NOT) && assert->framesize >= 0)      if ((ccbegin[1 + LINK_SIZE] == OP_ASSERT_NOT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK_NOT) && assert->framesize >= 0)
   
8394        {        {
8395        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr);
8396        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
# Line 7732  else if (opcode == OP_SBRA || opcode == Line 8430  else if (opcode == OP_SBRA || opcode ==
8430  else if (opcode == OP_ONCE)  else if (opcode == OP_ONCE)
8431    {    {
8432    cc = ccbegin + GET(ccbegin, 1);    cc = ccbegin + GET(ccbegin, 1);
8433      stacksize = needs_control_head ? 1 : 0;
8434    
8435    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
8436      {      {
8437      /* Reset head and drop saved frame. */      /* Reset head and drop saved frame. */
8438      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);  
8439      }      }
8440    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))
8441      {      {
8442      /* The STR_PTR must be released. */      /* The STR_PTR must be released. */
8443      free_stack(common, 1);      stacksize++;
8444      }      }
8445      free_stack(common, stacksize);
8446    
8447    JUMPHERE(once);    JUMPHERE(once);
8448    /* Restore previous private_data_ptr */    /* Restore previous private_data_ptr */
# Line 7757  else if (opcode == OP_ONCE) Line 8457  else if (opcode == OP_ONCE)
8457      }      }
8458    }    }
8459    
8460  if (ket == OP_KETRMAX)  if (repeat_type == OP_EXACT)
8461      {
8462      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
8463      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0);
8464      CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, repeat_count, exact_label);
8465      }
8466    else if (ket == OP_KETRMAX)
8467    {    {
8468    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8469    if (bra != OP_BRAZERO)    if (bra != OP_BRAZERO)
8470      free_stack(common, 1);      free_stack(common, 1);
8471    
8472    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);
8473    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
8474      {      {
# Line 7780  else if (ket == OP_KETRMIN) Line 8487  else if (ket == OP_KETRMIN)
8487    affect badly the free_stack(2) above. */    affect badly the free_stack(2) above. */
8488    if (opcode != OP_ONCE)    if (opcode != OP_ONCE)
8489      free_stack(common, 1);      free_stack(common, 1);
8490    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, rminlabel);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, rmin_label);
8491    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
8492      free_stack(common, bra == OP_BRAMINZERO ? 2 : 1);      free_stack(common, bra == OP_BRAMINZERO ? 2 : 1);
8493    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
# Line 7794  else if (bra == OP_BRAZERO) Line 8501  else if (bra == OP_BRAZERO)
8501    }    }
8502  }  }
8503    
8504  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)
8505  {  {
8506  DEFINE_COMPILER;  DEFINE_COMPILER;
8507  int offset;  int offset;
# Line 7833  if (current->topbacktracks) Line 8540  if (current->topbacktracks)
8540  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));
8541  }  }
8542    
8543  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)
8544  {  {
8545  assert_backtrack backtrack;  assert_backtrack backtrack;
8546    
# Line 7857  else Line 8564  else
8564  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);
8565  }  }
8566    
8567    static SLJIT_INLINE void compile_control_verb_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8568    {
8569    DEFINE_COMPILER;
8570    pcre_uchar opcode = *current->cc;
8571    struct sljit_label *loop;
8572    struct sljit_jump *jump;
8573    
8574    if (opcode == OP_THEN || opcode == OP_THEN_ARG)
8575      {
8576      if (common->then_trap != NULL)
8577        {
8578        SLJIT_ASSERT(common->control_head_ptr != 0);
8579    
8580        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8581        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, type_then_trap);
8582        OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, common->then_trap->start);
8583        jump = JUMP(SLJIT_JUMP);
8584    
8585        loop = LABEL();
8586        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), -(int)sizeof(sljit_sw));
8587        JUMPHERE(jump);
8588        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), -(int)(2 * sizeof(sljit_sw)), TMP1, 0, loop);
8589        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), -(int)(3 * sizeof(sljit_sw)), TMP2, 0, loop);
8590        add_jump(compiler, &common->then_trap->quit, JUMP(SLJIT_JUMP));
8591        return;
8592        }
8593      else if (common->positive_assert)
8594        {
8595        add_jump(compiler, &common->positive_assert_quit, JUMP(SLJIT_JUMP));
8596        return;
8597        }
8598      }
8599    
8600    if (common->local_exit)
8601      {
8602      if (common->quit_label == NULL)
8603        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8604      else
8605        JUMPTO(SLJIT_JUMP, common->quit_label);
8606      return;
8607      }
8608    
8609    if (opcode == OP_SKIP_ARG)
8610      {
8611      SLJIT_ASSERT(common->control_head_ptr != 0);
8612      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8613      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
8614      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, (sljit_sw)(current->cc + 2));
8615      sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_search_mark));
8616      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
8617    
8618      OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
8619      add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));
8620      return;
8621      }
8622    
8623    if (opcode == OP_SKIP)
8624      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8625    else
8626      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_IMM, 0);
8627    add_jump(compiler, &common->reset_match, JUMP(SLJIT_JUMP));
8628    }
8629    
8630    static SLJIT_INLINE void compile_then_trap_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8631    {
8632    DEFINE_COMPILER;
8633    struct sljit_jump *jump;
8634    int size;
8635    
8636    if (CURRENT_AS(then_trap_backtrack)->then_trap)
8637      {
8638      common->then_trap = CURRENT_AS(then_trap_backtrack)->then_trap;
8639      return;
8640      }
8641    
8642    size = CURRENT_AS(then_trap_backtrack)->framesize;
8643    size = 3 + (size < 0 ? 0 : size);
8644    
8645    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(size - 3));
8646    free_stack(common, size);
8647    jump = JUMP(SLJIT_JUMP);
8648    
8649    set_jumps(CURRENT_AS(then_trap_backtrack)->quit, LABEL());
8650    /* STACK_TOP is set by THEN. */
8651    if (CURRENT_AS(then_trap_backtrack)->framesize >= 0)
8652      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
8653    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8654    free_stack(common, 3);
8655    
8656    JUMPHERE(jump);
8657    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
8658    }
8659    
8660  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8661  {  {
8662  DEFINE_COMPILER;  DEFINE_COMPILER;
8663    then_trap_backtrack *save_then_trap = common->then_trap;
8664    
8665  while (current)  while (current)
8666    {    {
# Line 7948  while (current) Line 8749  while (current)
8749    
8750      case OP_REF:      case OP_REF:
8751      case OP_REFI:      case OP_REFI:
8752        case OP_DNREF:
8753        case OP_DNREFI:
8754      compile_ref_iterator_backtrackingpath(common, current);      compile_ref_iterator_backtrackingpath(common, current);
8755      break;      break;
8756    
# Line 7993  while (current) Line 8796  while (current)
8796      break;      break;
8797    
8798      case OP_MARK:      case OP_MARK:
8799      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));
8800      free_stack(common, 1);      if (common->has_skip_arg)
8801          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8802        free_stack(common, common->has_skip_arg ? 5 : 1);
8803      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);
8804        if (common->has_skip_arg)
8805          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP2, 0);
8806        break;
8807    
8808        case OP_THEN:
8809        case OP_THEN_ARG:
8810        case OP_PRUNE:
8811        case OP_PRUNE_ARG:
8812        case OP_SKIP:
8813        case OP_SKIP_ARG:
8814        compile_control_verb_backtrackingpath(common, current);
8815      break;      break;
8816    
8817      case OP_COMMIT:      case OP_COMMIT:
8818      OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);      if (!common->local_exit)
8819          OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
8820      if (common->quit_label == NULL)      if (common->quit_label == NULL)
8821        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8822      else      else
# Line 8013  while (current) Line 8830  while (current)
8830      set_jumps(current->topbacktracks, LABEL());      set_jumps(current->topbacktracks, LABEL());
8831      break;      break;
8832    
8833        case OP_THEN_TRAP:
8834        /* A virtual opcode for then traps. */
8835        compile_then_trap_backtrackingpath(common, current);
8836        break;
8837    
8838      default:      default:
8839      SLJIT_ASSERT_STOP();      SLJIT_ASSERT_STOP();
8840      break;      break;
8841      }      }
8842    current = current->prev;    current = current->prev;
8843    }    }
8844    common->then_trap = save_then_trap;
8845  }  }
8846    
8847  static SLJIT_INLINE void compile_recurse(compiler_common *common)  static SLJIT_INLINE void compile_recurse(compiler_common *common)
# Line 8027  DEFINE_COMPILER; Line 8850  DEFINE_COMPILER;
8850  pcre_uchar *cc = common->start + common->currententry->start;  pcre_uchar *cc = common->start + common->currententry->start;
8851  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);
8852  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
8853  int private_data_size = get_private_data_length_for_copy(common, ccbegin, ccend);  BOOL needs_control_head;
8854  int framesize = get_framesize(common, cc, TRUE);  int framesize = get_framesize(common, cc, NULL, TRUE, &needs_control_head);
8855    int private_data_size = get_private_data_copy_length(common, ccbegin, ccend, needs_control_head);
8856  int alternativesize;  int alternativesize;
8857  BOOL needsframe;  BOOL needs_frame;
8858  backtrack_common altbacktrack;  backtrack_common altbacktrack;
 struct sljit_label *save_quit_label = common->quit_label;  
 jump_list *save_quit = common->quit;  
8859  struct sljit_jump *jump;  struct sljit_jump *jump;
8860    
8861    /* Recurse captures then. */
8862    common->then_trap = NULL;
8863    
8864  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);
8865  needsframe = framesize >= 0;  needs_frame = framesize >= 0;
8866  if (!needsframe)  if (!needs_frame)
8867    framesize = 0;    framesize = 0;
8868  alternativesize = *(cc + GET(cc, 1)) == OP_ALT ? 1 : 0;  alternativesize = *(cc + GET(cc, 1)) == OP_ALT ? 1 : 0;
8869    
# Line 8049  set_jumps(common->currententry->calls, c Line 8874  set_jumps(common->currententry->calls, c
8874  sljit_emit_fast_enter(compiler, TMP2, 0);  sljit_emit_fast_enter(compiler, TMP2, 0);
8875  allocate_stack(common, private_data_size + framesize + alternativesize);  allocate_stack(common, private_data_size + framesize + alternativesize);
8876  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);
8877  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);
8878    if (needs_control_head)
8879      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
8880  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);
8881