/[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 1245 by zherczeg, Sat Feb 9 11:30:51 2013 UTC revision 1300 by zherczeg, Mon Mar 25 12:34:26 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68    /* Defines for debugging purposes. */
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #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 159  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      int real_offset_count;
172    int offset_count;    int offset_count;
173    int call_limit;    int call_limit;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
# Line 180  typedef struct jump_list { Line 190  typedef struct jump_list {
190    struct jump_list *next;    struct jump_list *next;
191  } jump_list;  } jump_list;
192    
 enum stub_types { stack_alloc };  
   
193  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
194    struct sljit_jump *start;    struct sljit_jump *start;
195    struct sljit_label *quit;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum frame_types {
200      no_frame = -1,
201      no_stack = -2
202    };
203    
204    enum control_types {
205      type_mark = 0,
206      type_then_trap = 1
207    };
208    
209  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
210    
211  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
# Line 210  typedef struct backtrack_common { Line 226  typedef struct backtrack_common {
226  typedef struct assert_backtrack {  typedef struct assert_backtrack {
227    backtrack_common common;    backtrack_common common;
228    jump_list *condfailed;    jump_list *condfailed;
229    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
230    int framesize;    int framesize;
231    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
232    int private_data_ptr;    int private_data_ptr;
# Line 231  typedef struct bracket_backtrack { Line 247  typedef struct bracket_backtrack {
247      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
248      jump_list *condfailed;      jump_list *condfailed;
249      assert_backtrack *assert;      assert_backtrack *assert;
250      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
251      int framesize;      int framesize;
252    } u;    } u;
253    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 266  typedef struct recurse_entry { Line 282  typedef struct recurse_entry {
282    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
283    jump_list *calls;    jump_list *calls;
284    /* Points to the starting opcode. */    /* Points to the starting opcode. */
285    int start;    sljit_sw start;
286  } recurse_entry;  } recurse_entry;
287    
288  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
289    backtrack_common common;    backtrack_common common;
290      BOOL inlined_pattern;
291  } recurse_backtrack;  } recurse_backtrack;
292    
293    #define OP_THEN_TRAP OP_TABLE_LENGTH
294    
295    typedef struct then_trap_backtrack {
296      backtrack_common common;
297      /* If then_trap is not NULL, this structure contains the real
298      then_trap for the backtracking path. */
299      struct then_trap_backtrack *then_trap;
300      /* Points to the starting opcode. */
301      sljit_sw start;
302      /* Exit point for the then opcodes of this alternative. */
303      jump_list *quit;
304      /* Frame size of the current alternative. */
305      int framesize;
306    } then_trap_backtrack;
307    
308  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
309    
310  typedef struct compiler_common {  typedef struct compiler_common {
311      /* The sljit ceneric compiler. */
312    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
313      /* First byte code. */
314    pcre_uchar *start;    pcre_uchar *start;
   
315    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
316    int *private_data_ptrs;    int *private_data_ptrs;
317    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
318    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
319      /* Tells whether the starting offset is a target of then. */
320      pcre_uint8 *then_offsets;
321      /* Current position where a THEN must jump. */
322      then_trap_backtrack *then_trap;
323    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
324    int cbraptr;    int cbra_ptr;
325    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
326    int ovector_start;    int ovector_start;
327    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
328    int req_char_ptr;    int req_char_ptr;
# Line 299  typedef struct compiler_common { Line 336  typedef struct compiler_common {
336    int first_line_end;    int first_line_end;
337    /* Points to the marked string. */    /* Points to the marked string. */
338    int mark_ptr;    int mark_ptr;
339      /* Recursive control verb management chain. */
340      int control_head_ptr;
341    /* Points to the last matched capture block index. */    /* Points to the last matched capture block index. */
342    int capture_last_ptr;    int capture_last_ptr;
343      /* Points to the starting position of the current match. */
344      int start_ptr;
345    
346    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
347    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
348    sljit_sw lcc;    sljit_sw lcc;
349    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
350    int mode;    int mode;
351      /* \K is found in the pattern. */
352      BOOL has_set_som;
353      /* (*SKIP:arg) is found in the pattern. */
354      BOOL has_skip_arg;
355      /* (*THEN) is found in the pattern. */
356      BOOL has_then;
357      /* Needs to know the start position anytime. */
358      BOOL needs_start_ptr;
359      /* Currently in recurse. */
360      BOOL local_exit;
361      /* Currently in assert. */
362      int then_local_exit;
363    /* Newline control. */    /* Newline control. */
364    int nltype;    int nltype;
365    int newline;    int newline;
366    int bsr_nltype;    int bsr_nltype;
367    /* Dollar endonly. */    /* Dollar endonly. */
368    int endonly;    int endonly;
   BOOL has_set_som;  
369    /* Tables. */    /* Tables. */
370    sljit_sw ctypes;    sljit_sw ctypes;
371    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
# Line 332  typedef struct compiler_common { Line 384  typedef struct compiler_common {
384    recurse_entry *currententry;    recurse_entry *currententry;
385    jump_list *partialmatch;    jump_list *partialmatch;
386    jump_list *quit;    jump_list *quit;
387      jump_list *then_quit;
388    jump_list *forced_quit;    jump_list *forced_quit;
389    jump_list *accept;    jump_list *accept;
390    jump_list *calllimit;    jump_list *calllimit;
# Line 343  typedef struct compiler_common { Line 396  typedef struct compiler_common {
396    jump_list *vspace;    jump_list *vspace;
397    jump_list *casefulcmp;    jump_list *casefulcmp;
398    jump_list *caselesscmp;    jump_list *caselesscmp;
399      jump_list *reset_match;
400    BOOL jscript_compat;    BOOL jscript_compat;
401  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
402    BOOL utf;    BOOL utf;
# Line 395  typedef struct compare_context { Line 449  typedef struct compare_context {
449  #endif  #endif
450  } compare_context;  } compare_context;
451    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
452  /* Undefine sljit macros. */  /* Undefine sljit macros. */
453  #undef CMP  #undef CMP
454    
# Line 433  group contains the start / end character Line 481  group contains the start / end character
481  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. */
482  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
483  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
484  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
485  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
486    
487  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 464  the start pointers when the end of the c Line 512  the start pointers when the end of the c
512    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
513  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
514    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
515    #define SET_LABEL(jump, label) \
516      sljit_set_label((jump), (label))
517  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
518    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
519  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
# Line 488  return cc; Line 538  return cc;
538   set_private_data_ptrs   set_private_data_ptrs
539   get_framesize   get_framesize
540   init_frame   init_frame
541   get_private_data_length_for_copy   get_private_data_copy_length
542   copy_private_data   copy_private_data
543   compile_matchingpath   compile_matchingpath
544   compile_backtrackingpath   compile_backtrackingpath
# Line 512  switch(*cc) Line 562  switch(*cc)
562    case OP_WORDCHAR:    case OP_WORDCHAR:
563    case OP_ANY:    case OP_ANY:
564    case OP_ALLANY:    case OP_ALLANY:
565      case OP_NOTPROP:
566      case OP_PROP:
567    case OP_ANYNL:    case OP_ANYNL:
568    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
569    case OP_HSPACE:    case OP_HSPACE:
# Line 524  switch(*cc) Line 576  switch(*cc)
576    case OP_CIRCM:    case OP_CIRCM:
577    case OP_DOLL:    case OP_DOLL:
578    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
579    case OP_CRSTAR:    case OP_CRSTAR:
580    case OP_CRMINSTAR:    case OP_CRMINSTAR:
581    case OP_CRPLUS:    case OP_CRPLUS:
582    case OP_CRMINPLUS:    case OP_CRMINPLUS:
583    case OP_CRQUERY:    case OP_CRQUERY:
584    case OP_CRMINQUERY:    case OP_CRMINQUERY:
585      case OP_CRRANGE:
586      case OP_CRMINRANGE:
587      case OP_CLASS:
588      case OP_NCLASS:
589      case OP_REF:
590      case OP_REFI:
591      case OP_RECURSE:
592      case OP_CALLOUT:
593      case OP_ALT:
594      case OP_KET:
595      case OP_KETRMAX:
596      case OP_KETRMIN:
597      case OP_KETRPOS:
598      case OP_REVERSE:
599      case OP_ASSERT:
600      case OP_ASSERT_NOT:
601      case OP_ASSERTBACK:
602      case OP_ASSERTBACK_NOT:
603      case OP_ONCE:
604      case OP_ONCE_NC:
605      case OP_BRA:
606      case OP_BRAPOS:
607      case OP_CBRA:
608      case OP_CBRAPOS:
609      case OP_COND:
610      case OP_SBRA:
611      case OP_SBRAPOS:
612      case OP_SCBRA:
613      case OP_SCBRAPOS:
614      case OP_SCOND:
615      case OP_CREF:
616      case OP_NCREF:
617      case OP_RREF:
618      case OP_NRREF:
619    case OP_DEF:    case OP_DEF:
620    case OP_BRAZERO:    case OP_BRAZERO:
621    case OP_BRAMINZERO:    case OP_BRAMINZERO:
622    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
623      case OP_PRUNE:
624      case OP_SKIP:
625      case OP_THEN:
626    case OP_COMMIT:    case OP_COMMIT:
627    case OP_FAIL:    case OP_FAIL:
628    case OP_ACCEPT:    case OP_ACCEPT:
629    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
630      case OP_CLOSE:
631    case OP_SKIPZERO:    case OP_SKIPZERO:
632    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
633    
634    case OP_CHAR:    case OP_CHAR:
635    case OP_CHARI:    case OP_CHARI:
# Line 566  switch(*cc) Line 641  switch(*cc)
641    case OP_MINPLUS:    case OP_MINPLUS:
642    case OP_QUERY:    case OP_QUERY:
643    case OP_MINQUERY:    case OP_MINQUERY:
644      case OP_UPTO:
645      case OP_MINUPTO:
646      case OP_EXACT:
647    case OP_POSSTAR:    case OP_POSSTAR:
648    case OP_POSPLUS:    case OP_POSPLUS:
649    case OP_POSQUERY:    case OP_POSQUERY:
650      case OP_POSUPTO:
651    case OP_STARI:    case OP_STARI:
652    case OP_MINSTARI:    case OP_MINSTARI:
653    case OP_PLUSI:    case OP_PLUSI:
654    case OP_MINPLUSI:    case OP_MINPLUSI:
655    case OP_QUERYI:    case OP_QUERYI:
656    case OP_MINQUERYI:    case OP_MINQUERYI:
657      case OP_UPTOI:
658      case OP_MINUPTOI:
659      case OP_EXACTI:
660    case OP_POSSTARI:    case OP_POSSTARI:
661    case OP_POSPLUSI:    case OP_POSPLUSI:
662    case OP_POSQUERYI:    case OP_POSQUERYI:
663      case OP_POSUPTOI:
664    case OP_NOTSTAR:    case OP_NOTSTAR:
665    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
666    case OP_NOTPLUS:    case OP_NOTPLUS:
667    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
668    case OP_NOTQUERY:    case OP_NOTQUERY:
669    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
670      case OP_NOTUPTO:
671      case OP_NOTMINUPTO:
672      case OP_NOTEXACT:
673    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
674    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
675    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
676      case OP_NOTPOSUPTO:
677    case OP_NOTSTARI:    case OP_NOTSTARI:
678    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
679    case OP_NOTPLUSI:    case OP_NOTPLUSI:
680    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
681    case OP_NOTQUERYI:    case OP_NOTQUERYI:
682    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
683    case OP_NOTUPTOI:    case OP_NOTUPTOI:
684    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
685    case OP_NOTEXACTI:    case OP_NOTEXACTI:
686      case OP_NOTPOSSTARI:
687      case OP_NOTPOSPLUSI:
688      case OP_NOTPOSQUERYI:
689    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
690    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
691  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
692    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
693  #endif  #endif
694    return cc;    return cc;
695    
696    case OP_NOTPROP:    /* Special cases. */
697    case OP_PROP:    case OP_TYPESTAR:
698    return cc + 1 + 2;    case OP_TYPEMINSTAR:
699      case OP_TYPEPLUS:
700      case OP_TYPEMINPLUS:
701      case OP_TYPEQUERY:
702      case OP_TYPEMINQUERY:
703    case OP_TYPEUPTO:    case OP_TYPEUPTO:
704    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
705    case OP_TYPEEXACT:    case OP_TYPEEXACT:
706      case OP_TYPEPOSSTAR:
707      case OP_TYPEPOSPLUS:
708      case OP_TYPEPOSQUERY:
709    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
710    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
711    
712    case OP_CLASS:    case OP_ANYBYTE:
713    case OP_NCLASS:  #ifdef SUPPORT_UTF
714    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
715    #endif
716      return cc + 1;
717    
718  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
719    case OP_XCLASS:    case OP_XCLASS:
720    return cc + GET(cc, 1);    return cc + GET(cc, 1);
721  #endif  #endif
722    
   case OP_RECURSE:  
   case OP_ASSERT:  
   case OP_ASSERT_NOT:  
   case OP_ASSERTBACK:  
   case OP_ASSERTBACK_NOT:  
   case OP_REVERSE:  
   case OP_ONCE:  
   case OP_ONCE_NC:  
   case OP_BRA:  
   case OP_BRAPOS:  
   case OP_COND:  
   case OP_SBRA:  
   case OP_SBRAPOS:  
   case OP_SCOND:  
   case OP_ALT:  
   case OP_KET:  
   case OP_KETRMAX:  
   case OP_KETRMIN:  
   case OP_KETRPOS:  
   return cc + 1 + LINK_SIZE;  
   
   case OP_CBRA:  
   case OP_CBRAPOS:  
   case OP_SCBRA:  
   case OP_SCBRAPOS:  
   return cc + 1 + LINK_SIZE + IMM2_SIZE;  
   
723    case OP_MARK:    case OP_MARK:
724      case OP_PRUNE_ARG:
725      case OP_SKIP_ARG:
726      case OP_THEN_ARG:
727    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
728    
   case OP_CALLOUT:  
   return cc + 2 + 2 * LINK_SIZE;  
   
729    default:    default:
730      /* All opcodes are supported now! */
731      SLJIT_ASSERT_STOP();
732    return NULL;    return NULL;
733    }    }
734  }  }
# Line 937  while (cc < ccend) Line 977  while (cc < ccend)
977      cc += 2 + 2 * LINK_SIZE;      cc += 2 + 2 * LINK_SIZE;
978      break;      break;
979    
980        case OP_THEN_ARG:
981        common->has_then = TRUE;
982        common->control_head_ptr = 1;
983        /* Fall through. */
984    
985        case OP_PRUNE_ARG:
986        common->needs_start_ptr = TRUE;
987        /* Fall through. */
988    
989      case OP_MARK:      case OP_MARK:
990      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
991        {        {
# Line 946  while (cc < ccend) Line 995  while (cc < ccend)
995      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
996      break;      break;
997    
998        case OP_THEN:
999        common->has_then = TRUE;
1000        common->control_head_ptr = 1;
1001        /* Fall through. */
1002    
1003        case OP_PRUNE:
1004        case OP_SKIP:
1005        common->needs_start_ptr = TRUE;
1006        cc += 1;
1007        break;
1008    
1009        case OP_SKIP_ARG:
1010        common->control_head_ptr = 1;
1011        common->has_skip_arg = TRUE;
1012        cc += 1 + 2 + cc[1];
1013        break;
1014    
1015      default:      default:
1016      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1017      if (cc == NULL)      if (cc == NULL)
# Line 1122  while (cc < ccend) Line 1188  while (cc < ccend)
1188    }    }
1189  }  }
1190    
1191  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1192  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)
1193  {  {
 pcre_uchar *ccend = bracketend(cc);  
1194  int length = 0;  int length = 0;
1195  BOOL possessive = FALSE;  int possessive = 0;
1196    BOOL stack_restore = FALSE;
1197  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1198  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1199    /* The last capture is a local variable even for recursions. */
1200    BOOL capture_last_found = FALSE;
1201    
1202  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1203    SLJIT_ASSERT(common->control_head_ptr != 0);
1204    *needs_control_head = TRUE;
1205    #else
1206    *needs_control_head = FALSE;
1207    #endif
1208    
1209    if (ccend == NULL)
1210    {    {
1211    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1212    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1213        {
1214        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1215        /* This is correct regardless of common->capture_last_ptr. */
1216        capture_last_found = TRUE;
1217        }
1218      cc = next_opcode(common, cc);
1219    }    }
1220    
 cc = next_opcode(common, cc);  
1221  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1222  while (cc < ccend)  while (cc < ccend)
1223    switch(*cc)    switch(*cc)
1224      {      {
1225      case OP_SET_SOM:      case OP_SET_SOM:
1226      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1227        stack_restore = TRUE;
1228      if (!setsom_found)      if (!setsom_found)
1229        {        {
1230        length += 2;        length += 2;
# Line 1153  while (cc < ccend) Line 1234  while (cc < ccend)
1234      break;      break;
1235    
1236      case OP_MARK:      case OP_MARK:
1237        case OP_PRUNE_ARG:
1238        case OP_THEN_ARG:
1239      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1240        stack_restore = TRUE;
1241      if (!setmark_found)      if (!setmark_found)
1242        {        {
1243        length += 2;        length += 2;
1244        setmark_found = TRUE;        setmark_found = TRUE;
1245        }        }
1246        if (common->control_head_ptr != 0)
1247          *needs_control_head = TRUE;
1248      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1249      break;      break;
1250    
1251      case OP_RECURSE:      case OP_RECURSE:
1252        stack_restore = TRUE;
1253      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1254        {        {
1255        length += 2;        length += 2;
# Line 1173  while (cc < ccend) Line 1260  while (cc < ccend)
1260        length += 2;        length += 2;
1261        setmark_found = TRUE;        setmark_found = TRUE;
1262        }        }
1263        if (common->capture_last_ptr != 0 && !capture_last_found)
1264          {
1265          length += 2;
1266          capture_last_found = TRUE;
1267          }
1268      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1269      break;      break;
1270    
# Line 1180  while (cc < ccend) Line 1272  while (cc < ccend)
1272      case OP_CBRAPOS:      case OP_CBRAPOS:
1273      case OP_SCBRA:      case OP_SCBRA:
1274      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1275        stack_restore = TRUE;
1276        if (common->capture_last_ptr != 0 && !capture_last_found)
1277          {
1278          length += 2;
1279          capture_last_found = TRUE;
1280          }
1281      length += 3;      length += 3;
1282      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1283      break;      break;
1284    
1285      default:      default:
1286        stack_restore = TRUE;
1287        /* Fall through. */
1288    
1289        case OP_NOT_WORD_BOUNDARY:
1290        case OP_WORD_BOUNDARY:
1291        case OP_NOT_DIGIT:
1292        case OP_DIGIT:
1293        case OP_NOT_WHITESPACE:
1294        case OP_WHITESPACE:
1295        case OP_NOT_WORDCHAR:
1296        case OP_WORDCHAR:
1297        case OP_ANY:
1298        case OP_ALLANY:
1299        case OP_ANYBYTE:
1300        case OP_NOTPROP:
1301        case OP_PROP:
1302        case OP_ANYNL:
1303        case OP_NOT_HSPACE:
1304        case OP_HSPACE:
1305        case OP_NOT_VSPACE:
1306        case OP_VSPACE:
1307        case OP_EXTUNI:
1308        case OP_EODN:
1309        case OP_EOD:
1310        case OP_CIRC:
1311        case OP_CIRCM:
1312        case OP_DOLL:
1313        case OP_DOLLM:
1314        case OP_CHAR:
1315        case OP_CHARI:
1316        case OP_NOT:
1317        case OP_NOTI:
1318    
1319        case OP_EXACT:
1320        case OP_POSSTAR:
1321        case OP_POSPLUS:
1322        case OP_POSQUERY:
1323        case OP_POSUPTO:
1324    
1325        case OP_EXACTI:
1326        case OP_POSSTARI:
1327        case OP_POSPLUSI:
1328        case OP_POSQUERYI:
1329        case OP_POSUPTOI:
1330    
1331        case OP_NOTEXACT:
1332        case OP_NOTPOSSTAR:
1333        case OP_NOTPOSPLUS:
1334        case OP_NOTPOSQUERY:
1335        case OP_NOTPOSUPTO:
1336    
1337        case OP_NOTEXACTI:
1338        case OP_NOTPOSSTARI:
1339        case OP_NOTPOSPLUSI:
1340        case OP_NOTPOSQUERYI:
1341        case OP_NOTPOSUPTOI:
1342    
1343        case OP_TYPEEXACT:
1344        case OP_TYPEPOSSTAR:
1345        case OP_TYPEPOSPLUS:
1346        case OP_TYPEPOSQUERY:
1347        case OP_TYPEPOSUPTO:
1348    
1349        case OP_CLASS:
1350        case OP_NCLASS:
1351        case OP_XCLASS:
1352    
1353      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1354      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1355      break;      break;
1356      }      }
1357    
1358  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1359  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1360    return -1;    return stack_restore ? no_frame : no_stack;
1361    
1362  if (length > 0)  if (length > 0)
1363    return length + 1;    return length + 1;
1364  return -1;  return stack_restore ? no_frame : no_stack;
1365  }  }
1366    
1367  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)
1368  {  {
1369  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1370  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1371  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1372    /* The last capture is a local variable even for recursions. */
1373    BOOL capture_last_found = FALSE;
1374  int offset;  int offset;
1375    
1376  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1212  SLJIT_UNUSED_ARG(stacktop); Line 1378  SLJIT_UNUSED_ARG(stacktop);
1378  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1379    
1380  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1381  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1382    cc = next_opcode(common, cc);    {
1383      ccend = bracketend(cc) - (1 + LINK_SIZE);
1384      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1385        cc = next_opcode(common, cc);
1386      }
1387    
1388  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1389  while (cc < ccend)  while (cc < ccend)
1390    switch(*cc)    switch(*cc)
# Line 1223  while (cc < ccend) Line 1394  while (cc < ccend)
1394      if (!setsom_found)      if (!setsom_found)
1395        {        {
1396        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1397        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1398        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1399        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1400        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1233  while (cc < ccend) Line 1404  while (cc < ccend)
1404      break;      break;
1405    
1406      case OP_MARK:      case OP_MARK:
1407        case OP_PRUNE_ARG:
1408        case OP_THEN_ARG:
1409      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1410      if (!setmark_found)      if (!setmark_found)
1411        {        {
1412        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1413        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1414        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1415        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1416        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1250  while (cc < ccend) Line 1423  while (cc < ccend)
1423      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1424        {        {
1425        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1426        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1427        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1428        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1429        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1259  while (cc < ccend) Line 1432  while (cc < ccend)
1432      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1433        {        {
1434        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1435        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1436        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1437        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1438        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1439        setmark_found = TRUE;        setmark_found = TRUE;
1440        }        }
1441        if (common->capture_last_ptr != 0 && !capture_last_found)
1442          {
1443          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1444          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1445          stackpos += (int)sizeof(sljit_sw);
1446          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1447          stackpos += (int)sizeof(sljit_sw);
1448          capture_last_found = TRUE;
1449          }
1450      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1451      break;      break;
1452    
# Line 1272  while (cc < ccend) Line 1454  while (cc < ccend)
1454      case OP_CBRAPOS:      case OP_CBRAPOS:
1455      case OP_SCBRA:      case OP_SCBRA:
1456      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1457        if (common->capture_last_ptr != 0 && !capture_last_found)
1458          {
1459          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1460          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1461          stackpos += (int)sizeof(sljit_sw);
1462          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1463          stackpos += (int)sizeof(sljit_sw);
1464          capture_last_found = TRUE;
1465          }
1466      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1467      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1468      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
# Line 1291  while (cc < ccend) Line 1482  while (cc < ccend)
1482      break;      break;
1483      }      }
1484    
1485  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1486  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1487  }  }
1488    
1489  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)
1490  {  {
1491  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1492  int size;  int size;
1493  pcre_uchar *alternative;  pcre_uchar *alternative;
1494  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1410  return private_data_length; Line 1601  return private_data_length;
1601  }  }
1602    
1603  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,
1604    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1605  {  {
1606  DEFINE_COMPILER;  DEFINE_COMPILER;
1607  int srcw[2];  int srcw[2];
# Line 1431  stacktop = STACK(stacktop - 1); Line 1622  stacktop = STACK(stacktop - 1);
1622    
1623  if (!save)  if (!save)
1624    {    {
1625    stackptr += sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1626    if (stackptr < stacktop)    if (stackptr < stacktop)
1627      {      {
1628      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
# Line 1447  if (!save) Line 1638  if (!save)
1638    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1639    }    }
1640    
1641  while (status != end)  do
1642    {    {
1643    count = 0;    count = 0;
1644    switch(status)    switch(status)
# Line 1456  while (status != end) Line 1647  while (status != end)
1647      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1648      count = 1;      count = 1;
1649      srcw[0] = common->recursive_head_ptr;      srcw[0] = common->recursive_head_ptr;
1650        if (needs_control_head)
1651          {
1652          SLJIT_ASSERT(common->control_head_ptr != 0);
1653          count = 2;
1654          srcw[1] = common->control_head_ptr;
1655          }
1656      status = loop;      status = loop;
1657      break;      break;
1658    
# Line 1680  while (status != end) Line 1877  while (status != end)
1877        }        }
1878      }      }
1879    }    }
1880    while (status != end);
1881    
1882  if (save)  if (save)
1883    {    {
# Line 1710  if (save) Line 1908  if (save)
1908        }        }
1909      }      }
1910    }    }
1911  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1912    }
1913    
1914    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1915    {
1916    pcre_uchar *end = bracketend(cc);
1917    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1918    
1919    /* Assert captures then. */
1920    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1921      current_offset = NULL;
1922    /* Conditional block does not. */
1923    if (*cc == OP_COND || *cc == OP_SCOND)
1924      has_alternatives = FALSE;
1925    
1926    cc = next_opcode(common, cc);
1927    if (has_alternatives)
1928      current_offset = common->then_offsets + (cc - common->start);
1929    
1930    while (cc < end)
1931      {
1932      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1933        cc = set_then_offsets(common, cc, current_offset);
1934      else
1935        {
1936        if (*cc == OP_ALT && has_alternatives)
1937          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1938        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1939          *current_offset = 1;
1940        cc = next_opcode(common, cc);
1941        }
1942      }
1943    
1944    return end;
1945  }  }
1946    
1947  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
# Line 1731  while (list) Line 1962  while (list)
1962    {    {
1963    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1964    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1965    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1966    list = list->next;    list = list->next;
1967    }    }
1968  }  }
# Line 1747  if (list_item) Line 1978  if (list_item)
1978    }    }
1979  }  }
1980    
1981  static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start)  static void add_stub(compiler_common *common, struct sljit_jump *start)
1982  {  {
1983  DEFINE_COMPILER;  DEFINE_COMPILER;
1984  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1985    
1986  if (list_item)  if (list_item)
1987    {    {
   list_item->type = type;  
   list_item->data = data;  
1988    list_item->start = start;    list_item->start = start;
1989    list_item->quit = LABEL();    list_item->quit = LABEL();
1990    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1771  stub_list* list_item = common->stubs; Line 2000  stub_list* list_item = common->stubs;
2000  while (list_item)  while (list_item)
2001    {    {
2002    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2003    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
     {  
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
2004    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2005    list_item = list_item->next;    list_item = list_item->next;
2006    }    }
# Line 1804  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2028  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2028  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2029  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2030  #endif  #endif
2031  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
2032  }  }
2033    
2034  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
# Line 1818  static SLJIT_INLINE void reset_ovector(c Line 2042  static SLJIT_INLINE void reset_ovector(c
2042  DEFINE_COMPILER;  DEFINE_COMPILER;
2043  struct sljit_label *loop;  struct sljit_label *loop;
2044  int i;  int i;
2045    
2046  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2047    SLJIT_ASSERT(length > 1);
2048  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2049  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));
2050  if (length < 8)  if (length < 8)
2051    {    {
2052    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
2053      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);
2054    }    }
2055  else  else
2056    {    {
2057    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2058    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2059    loop = LABEL();    loop = LABEL();
2060    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);
2061    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 1837  else Line 2063  else
2063    }    }
2064  }  }
2065    
2066    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2067    {
2068    DEFINE_COMPILER;
2069    struct sljit_label *loop;
2070    int i;
2071    
2072    SLJIT_ASSERT(length > 1);
2073    /* OVECTOR(1) contains the "string begin - 1" constant. */
2074    if (length > 2)
2075      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2076    if (length < 8)
2077      {
2078      for (i = 2; i < length; i++)
2079        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2080      }
2081    else
2082      {
2083      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2084      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2085      loop = LABEL();
2086      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2087      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2088      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2089      }
2090    
2091    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2092    if (common->mark_ptr != 0)
2093      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2094    if (common->control_head_ptr != 0)
2095      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2096    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2097    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2098    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2099    }
2100    
2101    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2102    {
2103    while (current != NULL)
2104      {
2105      switch (current[-2])
2106        {
2107        case type_then_trap:
2108        break;
2109    
2110        case type_mark:
2111        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2112          return current[-4];
2113        break;
2114    
2115        default:
2116        SLJIT_ASSERT_STOP();
2117        break;
2118        }
2119      current = (sljit_sw*)current[-1];
2120      }
2121    return -1;
2122    }
2123    
2124  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2125  {  {
2126  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1890  else Line 2174  else
2174  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2175  {  {
2176  DEFINE_COMPILER;  DEFINE_COMPILER;
2177    struct sljit_jump *jump;
2178    
2179  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);
2180  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
2181      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2182    
2183  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2184  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2185  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offset_count));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2186  CMPTO(SLJIT_C_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2187    
2188  /* Store match begin and end. */  /* Store match begin and end. */
2189  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2190  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));
2191    
2192    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2193    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);
2194    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2195    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2196    #endif
2197    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2198    JUMPHERE(jump);
2199    
2200  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2201  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2202  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
# Line 2078  else if (common->mode == JIT_PARTIAL_SOF Line 2373  else if (common->mode == JIT_PARTIAL_SOF
2373    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2374    
2375  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2376    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2377  else  else
2378    {    {
2379    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2091  if (jump != NULL) Line 2386  if (jump != NULL)
2386    JUMPHERE(jump);    JUMPHERE(jump);
2387  }  }
2388    
2389  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2390  {  {
2391  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2392  DEFINE_COMPILER;  DEFINE_COMPILER;
2393  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2394    
2395  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2396    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2397      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2398      return;
2399      }
2400    
2401  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2402  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2403    {    {
2404    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2405    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2406    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2407    }    }
2408  else  else
2409    {    {
2410    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2411    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2412      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2413    else    else
2414      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2415    }    }
2416  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2417  }  }
2418    
2419  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2138  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2432  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2432  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2433  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2434    {    {
2435    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2436    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2437    }    }
2438  else  else
# Line 3060  GET_LOCAL_BASE(TMP3, 0, 0); Line 3354  GET_LOCAL_BASE(TMP3, 0, 0);
3354  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3355  mainloop = LABEL();  mainloop = LABEL();
3356  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3357  jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);
3358    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3359    
3360  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3361  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3362  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
# Line 3068  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I Line 3364  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I
3364  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3365    
3366  JUMPHERE(jump);  JUMPHERE(jump);
3367  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3368  /* End of dropping frames. */  /* End of dropping frames. */
3369  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3370    
3371  JUMPHERE(jump);  JUMPHERE(jump);
3372  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3373  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3374  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));  
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  
 JUMPTO(SLJIT_JUMP, mainloop);  
   
 JUMPHERE(jump);  
 if (common->mark_ptr != 0)  
   {  
   jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setmark);  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  
   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
   JUMPTO(SLJIT_JUMP, mainloop);  
   
   JUMPHERE(jump);  
   }  
   
 /* Unknown command. */  
3375  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
3376  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3377  }  }
# Line 3101  static void check_wordboundary(compiler_ Line 3380  static void check_wordboundary(compiler_
3380  {  {
3381  DEFINE_COMPILER;  DEFINE_COMPILER;
3382  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3383    jump_list *skipread_list = NULL;
3384  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3385  struct sljit_jump *jump;  struct sljit_jump *jump;
3386  #endif  #endif
# Line 3158  else Line 3438  else
3438  JUMPHERE(skipread);  JUMPHERE(skipread);
3439    
3440  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3441  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3442  peek_char(common);  peek_char(common);
3443    
3444  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3199  else Line 3479  else
3479      JUMPHERE(jump);      JUMPHERE(jump);
3480  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3481    }    }
3482  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3483    
3484  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3485  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3839  while (*cc != XCL_END) Line 4119  while (*cc != XCL_END)
4119        break;        break;
4120    
4121        case PT_CLIST:        case PT_CLIST:
4122          case PT_UCNC:
4123        needschar = TRUE;        needschar = TRUE;
4124        break;        break;
4125    
# Line 4040  while (*cc != XCL_END) Line 4321  while (*cc != XCL_END)
4321        case PT_WORD:        case PT_WORD:
4322        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);
4323        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4324        /* ... fall through */        /* Fall through. */
4325    
4326        case PT_ALNUM:        case PT_ALNUM:
4327        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
# Line 4104  while (*cc != XCL_END) Line 4385  while (*cc != XCL_END)
4385          }          }
4386        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4387        break;        break;
4388    
4389          case PT_UCNC:
4390          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4391          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4392          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4393          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4394          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4395          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4396    
4397          SET_CHAR_OFFSET(0xa0);
4398          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4399          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4400          SET_CHAR_OFFSET(0);
4401          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4402          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4403          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4404          break;
4405        }        }
4406      cc += 2;      cc += 2;
4407      }      }
# Line 4129  int length; Line 4427  int length;
4427  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4428  compare_context context;  compare_context context;
4429  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4430    jump_list *end_list;
4431  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4432  struct sljit_label *label;  struct sljit_label *label;
4433  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4197  switch(type) Line 4496  switch(type)
4496    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4497      {      {
4498      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4499        end_list = NULL;
4500      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4501        jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);        add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4502      else      else
4503        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4504    
4505      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4506      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));
4507      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4508      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4509      }      }
4510    else    else
# Line 4264  switch(type) Line 4563  switch(type)
4563    read_char(common);    read_char(common);
4564    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
4565    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4566      end_list = NULL;
4567    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4568      jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4569    else    else
4570      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4571    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4572    jump[2] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);    jump[1] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);
4573    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4574    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4575    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4576    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4577      set_jumps(end_list, LABEL());
4578    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4579    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4580    return cc;    return cc;
4581    
4582    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 5026  DEFINE_COMPILER; Line 5326  DEFINE_COMPILER;
5326  backtrack_common *backtrack;  backtrack_common *backtrack;
5327  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5328  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5329  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5330    pcre_uchar *start_cc;
5331    BOOL needs_control_head;
5332    
5333  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5334    
5335    /* Inlining simple patterns. */
5336    if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5337      {
5338      start_cc = common->start + start;
5339      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5340      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5341      return cc + 1 + LINK_SIZE;
5342      }
5343    
5344  while (entry != NULL)  while (entry != NULL)
5345    {    {
5346    if (entry->start == start)    if (entry->start == start)
# Line 5140  allocate_stack(common, CALLOUT_ARG_SIZE Line 5452  allocate_stack(common, CALLOUT_ARG_SIZE
5452  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);
5453  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5454  SLJIT_ASSERT(common->capture_last_ptr != 0);  SLJIT_ASSERT(common->capture_last_ptr != 0);
5455  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]);
5456  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);
5457    
5458  /* These pointer sized fields temporarly stores internal variables. */  /* These pointer sized fields temporarly stores internal variables. */
5459  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 5150  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CA Line 5462  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CA
5462    
5463  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
5464    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));
5465  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));
5466  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));
5467  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);
5468    
5469  /* Needed to save important temporary registers. */  /* Needed to save important temporary registers. */
# Line 5180  static pcre_uchar *compile_assert_matchi Line 5492  static pcre_uchar *compile_assert_matchi
5492  {  {
5493  DEFINE_COMPILER;  DEFINE_COMPILER;
5494  int framesize;  int framesize;
5495    int extrasize;
5496    BOOL needs_control_head;
5497  int private_data_ptr;  int private_data_ptr;
5498  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5499  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5189  jump_list *tmp = NULL; Line 5503  jump_list *tmp = NULL;
5503  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5504  jump_list **found;  jump_list **found;
5505  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5506  struct sljit_label *save_quit_label = common->quit_label;  int save_then_local_exit = common->then_local_exit;
5507    then_trap_backtrack *save_then_trap = common->then_trap;
5508  struct sljit_label *save_accept_label = common->accept_label;  struct sljit_label *save_accept_label = common->accept_label;
5509  jump_list *save_quit = common->quit;  jump_list *save_then_quit = common->then_quit;
5510  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5511  struct sljit_jump *jump;  struct sljit_jump *jump;
5512  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5513    
5514    /* Assert captures then. */
5515    common->then_trap = NULL;
5516    
5517  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5518    {    {
5519    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5204  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5522  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5522    }    }
5523  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5524  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5525  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5526  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5527  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5528  opcode = *cc;  opcode = *cc;
# Line 5223  if (bra == OP_BRAMINZERO) Line 5541  if (bra == OP_BRAMINZERO)
5541    
5542  if (framesize < 0)  if (framesize < 0)
5543    {    {
5544    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5545    allocate_stack(common, 1);    if (framesize == no_frame)
5546        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5547      allocate_stack(common, extrasize);
5548      if (needs_control_head)
5549        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5550    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5551      if (needs_control_head)
5552        {
5553        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5554        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5555        }
5556    }    }
5557  else  else
5558    {    {
5559    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5560      allocate_stack(common, framesize + extrasize);
5561    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);
5562    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));
5563    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);
5564      if (needs_control_head)
5565        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5566    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5567    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5568    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5569        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5570        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5571        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5572        }
5573      else
5574        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5575      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5576    }    }
5577    
5578  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5579  common->quit_label = NULL;  common->then_local_exit = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? 1 : -1;
5580  common->quit = NULL;  common->then_quit = NULL;
5581  while (1)  while (1)
5582    {    {
5583    common->accept_label = NULL;    common->accept_label = NULL;
# Line 5255  while (1) Line 5592  while (1)
5592    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5593    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5594      {      {
5595      common->quit_label = save_quit_label;      common->then_local_exit = save_then_local_exit;
5596        common->then_trap = save_then_trap;
5597      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
5598      common->quit = save_quit;      common->then_quit = save_then_quit;
5599      common->accept = save_accept;      common->accept = save_accept;
5600      return NULL;      return NULL;
5601      }      }
# Line 5267  while (1) Line 5605  while (1)
5605    
5606    /* Reset stack. */    /* Reset stack. */
5607    if (framesize < 0)    if (framesize < 0)
5608      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
5609    else {      if (framesize == no_frame)
5610          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5611        else
5612          free_stack(common, extrasize);
5613        if (needs_control_head)
5614          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5615        }
5616      else
5617        {
5618      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5619        {        {
5620        /* 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. */
5621        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));
5622          if (needs_control_head)
5623            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5624        }        }
5625      else      else
5626        {        {
5627        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);
5628          if (needs_control_head)
5629            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5630        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5631        }        }
5632    }      }
5633    
5634    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5635      {      {
5636      /* 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. */
5637      if (conditional)      if (conditional)
5638        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);
5639      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
5640        {        {
5641        if (framesize < 0)        if (framesize < 0)
5642          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));
5643        else        else
5644          {          {
5645          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));
5646          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));
5647          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);
5648          }          }
5649        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 5310  while (1) Line 5660  while (1)
5660    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5661    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5662      {      {
5663      common->quit_label = save_quit_label;      common->then_local_exit = save_then_local_exit;
5664        common->then_trap = save_then_trap;
5665      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
5666      common->quit = save_quit;      common->then_quit = save_then_quit;
5667      common->accept = save_accept;      common->accept = save_accept;
5668      return NULL;      return NULL;
5669      }      }
# Line 5324  while (1) Line 5675  while (1)
5675    ccbegin = cc;    ccbegin = cc;
5676    cc += GET(cc, 1);    cc += GET(cc, 1);
5677    }    }
5678    
5679  /* None of them matched. */  /* None of them matched. */
5680  if (common->quit != NULL)  if (common->then_quit != NULL)
5681    set_jumps(common->quit, LABEL());    {
5682      jump = JUMP(SLJIT_JUMP);
5683      set_jumps(common->then_quit, LABEL());
5684      SLJIT_ASSERT(framesize != no_stack);
5685      if (framesize < 0)
5686        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
5687      else
5688        {
5689        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5690        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5691        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5692        }
5693      JUMPHERE(jump);
5694      }
5695    
5696    if (needs_control_head)
5697      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
5698    
5699  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
5700    {    {
# Line 5338  if (opcode == OP_ASSERT || opcode == OP_ Line 5706  if (opcode == OP_ASSERT || opcode == OP_
5706      {      {
5707      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5708      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5709          {
5710          if (extrasize == 2)
5711            free_stack(common, 1);
5712        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5713          }
5714      else      else
5715        free_stack(common, 1);        free_stack(common, extrasize);
5716      }      }
5717    else    else
5718      {      {
5719      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5720      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5721      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5722        {        {
5723        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5724        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5725        }        }
5726      else      else
5727        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5728      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);
5729      }      }
5730    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5364  if (opcode == OP_ASSERT || opcode == OP_ Line 5736  if (opcode == OP_ASSERT || opcode == OP_
5736    if (framesize < 0)    if (framesize < 0)
5737      {      {
5738      /* 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. */
5739      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));
5740      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5741      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5742          {
5743        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));
5744          if (extrasize == 2)
5745            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5746          }
5747      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5748        {        {
5749        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 5380  if (opcode == OP_ASSERT || opcode == OP_ Line 5756  if (opcode == OP_ASSERT || opcode == OP_
5756        {        {
5757        /* 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. */
5758        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));
5759        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));
5760        }        }
5761      else      else
5762        {        {
5763        /* 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. */
5764        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));
5765        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
5766        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
5767            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5768            if (bra == OP_BRAMINZERO)
5769              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5770            }
5771          else
5772            {
5773            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5774            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
5775            }
5776        }        }
5777      }      }
5778    
5779    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5780      {      {
5781      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
5782      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
5783      }      }
5784    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5785      {      {
# Line 5416  else Line 5801  else
5801      {      {
5802      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5803      if (bra != OP_BRA)      if (bra != OP_BRA)
5804          {
5805          if (extrasize == 2)
5806            free_stack(common, 1);
5807        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5808          }
5809      else      else
5810        free_stack(common, 1);        free_stack(common, extrasize);
5811      }      }
5812    else    else
5813      {      {
5814      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5815      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5816      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5817      if (bra != OP_BRA)      if (bra != OP_BRA)
5818        {        {
5819        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5820        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5821        }        }
5822      else      else
5823        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5824      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);
5825      }      }
5826    
# Line 5451  else Line 5840  else
5840      }      }
5841    }    }
5842    
5843  common->quit_label = save_quit_label;  common->then_local_exit = save_then_local_exit;
5844    common->then_trap = save_then_trap;
5845  common->accept_label = save_accept_label;  common->accept_label = save_accept_label;
5846  common->quit = save_quit;  common->then_quit = save_then_quit;
5847  common->accept = save_accept;  common->accept = save_accept;
5848  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5849  }  }
# Line 5568  if (i < name_count) Line 5958  if (i < name_count)
5958  return condition;  return condition;
5959  }  }
5960    
5961    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)
5962    {
5963    DEFINE_COMPILER;
5964    int stacksize;
5965    
5966    if (framesize < 0)
5967      {
5968      if (framesize == no_frame)
5969        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5970      else
5971        {
5972        stacksize = needs_control_head ? 1 : 0;
5973        if (ket != OP_KET || has_alternatives)
5974          stacksize++;
5975        free_stack(common, stacksize);
5976        }
5977    
5978      if (needs_control_head)
5979        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (ket != OP_KET || has_alternatives) ? sizeof(sljit_sw) : 0);
5980    
5981      /* TMP2 which is set here used by OP_KETRMAX below. */
5982      if (ket == OP_KETRMAX)
5983        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
5984      else if (ket == OP_KETRMIN)
5985        {
5986        /* Move the STR_PTR to the private_data_ptr. */
5987        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
5988        }
5989      }
5990    else
5991      {
5992      stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
5993      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
5994      if (needs_control_head)
5995        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
5996    
5997      if (ket == OP_KETRMAX)
5998        {
5999        /* TMP2 which is set here used by OP_KETRMAX below. */
6000        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6001        }
6002      }
6003    if (needs_control_head)
6004      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
6005    }
6006    
6007    static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr)
6008    {
6009    DEFINE_COMPILER;
6010    
6011    if (common->capture_last_ptr != 0)
6012      {
6013      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6014      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6015      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6016      stacksize++;
6017      }
6018    if (common->optimized_cbracket[offset >> 1] == 0)
6019      {
6020      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6021      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6022      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6023      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6024      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6025      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6026      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6027      stacksize += 2;
6028      }
6029    return stacksize;
6030    }
6031    
6032  /*  /*
6033    Handling bracketed expressions is probably the most complex part.    Handling bracketed expressions is probably the most complex part.
6034    
# Line 5636  pcre_uchar bra = OP_BRA; Line 6097  pcre_uchar bra = OP_BRA;
6097  pcre_uchar ket;  pcre_uchar ket;
6098  assert_backtrack *assert;  assert_backtrack *assert;
6099  BOOL has_alternatives;  BOOL has_alternatives;
6100    BOOL needs_control_head = FALSE;
6101  struct sljit_jump *jump;  struct sljit_jump *jump;
6102  struct sljit_jump *skip;  struct sljit_jump *skip;
6103  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmaxlabel = NULL;
# Line 5711  else if (opcode == OP_ONCE || opcode == Line 6173  else if (opcode == OP_ONCE || opcode ==
6173    SLJIT_ASSERT(private_data_ptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
6174    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
6175    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
6176      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);
6177    }    }
6178    
6179  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
6180  stacksize = 0;  stacksize = 0;
6181  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6182    stacksize++;    stacksize++;
6183  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6184    stacksize++;    stacksize++;
# Line 5725  if (stacksize > 0) Line 6187  if (stacksize > 0)
6187    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6188    
6189  stacksize = 0;  stacksize = 0;
6190  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6191    {    {
6192    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6193    stacksize++;    stacksize++;
# Line 5788  if (ket == OP_KETRMAX) Line 6250  if (ket == OP_KETRMAX)
6250  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
6251  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6252    {    {
6253      stacksize = 0;
6254      if (needs_control_head)
6255        {
6256        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6257        stacksize++;
6258        }
6259    
6260    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6261      {      {
6262      /* Neither capturing brackets nor recursions are not found in the block. */      /* Neither capturing brackets nor recursions are found in the block. */
6263      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
6264        {        {
6265        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        stacksize += 2;
6266        allocate_stack(common, 2);        if (!needs_control_head)
6267        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));  
6268        }        }
6269      else if (ket == OP_KETRMAX || has_alternatives)      else
6270        {        {
6271        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6272        allocate_stack(common, 1);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6273        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        if (ket == OP_KETRMAX || has_alternatives)
6274            stacksize++;
6275        }        }
6276      else  
6277        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      if (stacksize > 0)
6278          allocate_stack(common, stacksize);
6279    
6280        stacksize = 0;
6281        if (needs_control_head)
6282          {
6283          stacksize++;
6284          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6285          }
6286    
6287        if (ket == OP_KETRMIN)
6288          {
6289          if (needs_control_head)
6290            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6291          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6292          if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6293            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));
6294          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6295          }
6296        else if (ket == OP_KETRMAX || has_alternatives)
6297          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6298      }      }
6299    else    else
6300      {      {
6301      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)      if (ket != OP_KET || has_alternatives)
6302          stacksize++;
6303    
6304        stacksize += BACKTRACK_AS(bracket_backtrack)->u.framesize + 1;
6305        allocate_stack(common, stacksize);
6306    
6307        if (needs_control_head)
6308          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6309    
6310        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6311        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6312    
6313        stacksize = needs_control_head ? 1 : 0;
6314        if (ket != OP_KET || has_alternatives)
6315        {        {
6316        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);  
6317        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);
6318        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);        stacksize++;
6319        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1, 2, FALSE);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6320        }        }
6321      else      else
6322        {        {
       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));  
6323        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);
6324        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);  
6325        }        }
6326        init_frame(common, ccbegin, NULL, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);
6327      }      }
6328    }    }
6329  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
# Line 5964  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 6459  if (SLJIT_UNLIKELY(sljit_get_compiler_er
6459    return NULL;    return NULL;
6460    
6461  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6462    {    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));  
       }  
     }  
   }  
6463    
6464  stacksize = 0;  stacksize = 0;
6465  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
# Line 6016  if (ket != OP_KET || bra != OP_BRA) Line 6488  if (ket != OP_KET || bra != OP_BRA)
6488    }    }
6489    
6490  if (offset != 0)  if (offset != 0)
6491    {    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;  
     }  
   }  
6492    
6493  if (has_alternatives)  if (has_alternatives)
6494    {    {
# Line 6106  if ((ket != OP_KET && bra != OP_BRAMINZE Line 6559  if ((ket != OP_KET && bra != OP_BRAMINZE
6559  while (*cc == OP_ALT)  while (*cc == OP_ALT)
6560    cc += GET(cc, 1);    cc += GET(cc, 1);
6561  cc += 1 + LINK_SIZE;  cc += 1 + LINK_SIZE;
6562    
6563    /* Temporarily encoding the needs_control_head in framesize. */
6564    if (opcode == OP_ONCE)
6565      BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);
6566  return cc;  return cc;
6567  }  }
6568    
# Line 6116  backtrack_common *backtrack; Line 6573  backtrack_common *backtrack;
6573  pcre_uchar opcode;  pcre_uchar opcode;
6574  int private_data_ptr;  int private_data_ptr;
6575  int cbraprivptr = 0;  int cbraprivptr = 0;
6576    BOOL needs_control_head;
6577  int framesize;  int framesize;
6578  int stacksize;  int stacksize;
6579  int offset = 0;  int offset = 0;
6580  BOOL zero = FALSE;  BOOL zero = FALSE;
6581  pcre_uchar *ccbegin = NULL;  pcre_uchar *ccbegin = NULL;
6582  int stack;  int stack; /* Also contains the offset of control head. */
6583  struct sljit_label *loop = NULL;  struct sljit_label *loop = NULL;
6584  struct jump_list *emptymatch = NULL;  struct jump_list *emptymatch = NULL;
6585    
# Line 6159  switch(opcode) Line 6617  switch(opcode)
6617    break;    break;
6618    }    }
6619    
6620  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
6621  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6622  if (framesize < 0)  if (framesize < 0)
6623    {    {
6624    stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;    if (offset != 0)
6625        {
6626        stacksize = 2;
6627        if (common->capture_last_ptr != 0)
6628          stacksize++;
6629        }
6630      else
6631        stacksize = 1;
6632    
6633      if (needs_control_head)
6634        stacksize++;
6635    if (!zero)    if (!zero)
6636      stacksize++;      stacksize++;
6637    
6638    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
6639    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6640    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    if (framesize == no_frame)
6641        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6642    
6643    if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)    stack = 0;
6644      if (offset != 0)
6645      {      {
6646        stack = 2;
6647      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6648      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));
6649      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6650        if (common->capture_last_ptr != 0)
6651          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6652      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6653        if (needs_control_head)
6654          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6655        if (common->capture_last_ptr != 0)
6656          {
6657          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6658          stack = 3;
6659          }
6660      }      }
6661    else    else
6662        {
6663        if (needs_control_head)
6664          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6665      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6666        stack = 1;
6667        }
6668    
6669      if (needs_control_head)
6670        stack++;
6671    if (!zero)    if (!zero)
6672      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);
6673      if (needs_control_head)
6674        {
6675        stack--;
6676        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6677        }
6678    }    }
6679  else  else
6680    {    {
6681    stacksize = framesize + 1;    stacksize = framesize + 1;
6682    if (!zero)    if (!zero)
6683      stacksize++;      stacksize++;
6684    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (needs_control_head)
6685        stacksize++;
6686      if (offset == 0)
6687      stacksize++;      stacksize++;
6688    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
   allocate_stack(common, stacksize);  
6689    
6690      allocate_stack(common, stacksize);
6691    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);
6692    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));    if (needs_control_head)
6693    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);
6694      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));
6695    
6696    stack = 0;    stack = 0;
6697    if (!zero)    if (!zero)
6698      {      {
6699      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);
6700        stack = 1;
6701        }
6702      if (needs_control_head)
6703        {
6704        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6705      stack++;      stack++;
6706      }      }
6707    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (offset == 0)
6708      {      {
6709      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);
6710      stack++;      stack++;
6711      }      }
6712    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);
6713    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, NULL, stacksize - 1, stacksize - framesize, FALSE);
6714      stack -= 1 + (offset == 0);
6715    }    }
6716    
6717  if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)  if (offset != 0)
6718    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6719    
6720  loop = LABEL();  loop = LABEL();
# Line 6227  while (*cc != OP_KETRPOS) Line 6730  while (*cc != OP_KETRPOS)
6730    
6731    if (framesize < 0)    if (framesize < 0)
6732      {      {
6733      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      if (framesize == no_frame)
6734          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6735    
6736      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6737        {        {
6738        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6739        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);
6740        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6741          if (common->capture_last_ptr != 0)
6742            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6743        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6744        }        }
6745      else      else
# Line 6251  while (*cc != OP_KETRPOS) Line 6757  while (*cc != OP_KETRPOS)
6757      }      }
6758    else    else
6759      {      {
6760      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6761        {        {
6762        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, stacksize * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6763        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6764        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);
6765        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6766          if (common->capture_last_ptr != 0)
6767            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6768        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6769        }        }
6770      else      else
# Line 6279  while (*cc != OP_KETRPOS) Line 6787  while (*cc != OP_KETRPOS)
6787          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6788        }        }
6789      }      }
6790    
6791      if (needs_control_head)
6792        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(stack));
6793    
6794    JUMPTO(SLJIT_JUMP, loop);    JUMPTO(SLJIT_JUMP, loop);
6795    flush_stubs(common);    flush_stubs(common);
6796    
# Line 6289  while (*cc != OP_KETRPOS) Line 6801  while (*cc != OP_KETRPOS)
6801    
6802    if (framesize < 0)    if (framesize < 0)
6803      {      {
6804      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6805        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6806      else      else
6807        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6808      }      }
6809    else    else
6810      {      {
6811      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6812        {        {
6813        /* Last alternative. */        /* Last alternative. */
6814        if (*cc == OP_KETRPOS)        if (*cc == OP_KETRPOS)
# Line 6315  while (*cc != OP_KETRPOS) Line 6827  while (*cc != OP_KETRPOS)
6827    ccbegin = cc + 1 + LINK_SIZE;    ccbegin = cc + 1 + LINK_SIZE;
6828    }    }
6829    
6830    /* We don't have to restore the control head in case of a failed match. */
6831    
6832  backtrack->topbacktracks = NULL;  backtrack->topbacktracks = NULL;
6833  if (!zero)  if (!zero)
6834    {    {
# Line 6443  PUSH_BACKTRACK(sizeof(iterator_backtrack Line 6957  PUSH_BACKTRACK(sizeof(iterator_backtrack
6957    
6958  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);
6959    
6960  switch (type)  switch(type)
6961    {    {
6962    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
6963    case OP_DIGIT:    case OP_DIGIT:
# Line 6703  if (!optimized_cbracket) Line 7217  if (!optimized_cbracket)
7217  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
7218  }  }
7219    
7220    static SLJIT_INLINE pcre_uchar *compile_control_verb_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
7221    {
7222    DEFINE_COMPILER;
7223    backtrack_common *backtrack;
7224    pcre_uchar opcode = *cc;
7225    pcre_uchar *ccend = cc + 1;
7226    
7227    if (opcode == OP_PRUNE_ARG || opcode == OP_SKIP_ARG || opcode == OP_THEN_ARG)
7228      ccend += 2 + cc[1];
7229    
7230    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
7231    
7232    if (opcode == OP_SKIP)
7233      {
7234      allocate_stack(common, 1);
7235      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
7236      return ccend;
7237      }
7238    
7239    if (opcode == OP_PRUNE_ARG || opcode == OP_THEN_ARG)
7240      {
7241      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7242      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7243      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7244      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7245      }
7246    
7247    return ccend;
7248    }
7249    
7250    static pcre_uchar then_trap_opcode[1] = { OP_THEN_TRAP };
7251    
7252    static SLJIT_INLINE void compile_then_trap_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
7253    {
7254    DEFINE_COMPILER;
7255    backtrack_common *backtrack;
7256    BOOL needs_control_head;
7257    int size;
7258    
7259    PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7260    common->then_trap = BACKTRACK_AS(then_trap_backtrack);
7261    BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7262    BACKTRACK_AS(then_trap_backtrack)->start = (sljit_sw)(cc - common->start);
7263    BACKTRACK_AS(then_trap_backtrack)->framesize = get_framesize(common, cc, ccend, FALSE, &needs_control_head);
7264    
7265    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7266    size = 3 + (size < 0 ? 0 : size);
7267    
7268    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7269    allocate_stack(common, size);
7270    if (size > 3)
7271      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0, SLJIT_IMM, (size - 3) * sizeof(sljit_sw));
7272    else
7273      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7274    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 1), SLJIT_IMM, BACKTRACK_AS(then_trap_backtrack)->start);
7275    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 2), SLJIT_IMM, type_then_trap);
7276    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 3), TMP2, 0);
7277    
7278    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7279    if (size >= 0)
7280      init_frame(common, cc, ccend, size - 1, 0, FALSE);
7281    }
7282    
7283  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)
7284  {  {
7285  DEFINE_COMPILER;  DEFINE_COMPILER;
7286  backtrack_common *backtrack;  backtrack_common *backtrack;
7287    BOOL has_then_trap = FALSE;
7288    then_trap_backtrack *save_then_trap = NULL;
7289    
7290    SLJIT_ASSERT(*ccend == OP_END || (*ccend >= OP_ALT && *ccend <= OP_KETRPOS));
7291    
7292    if (common->has_then && common->then_offsets[cc - common->start] != 0)
7293      {
7294      SLJIT_ASSERT(*ccend != OP_END && common->control_head_ptr != 0);
7295      has_then_trap = TRUE;
7296      save_then_trap = common->then_trap;
7297      /* Tail item on backtrack. */
7298      compile_then_trap_matchingpath(common, cc, ccend, parent);
7299      }
7300    
7301  while (cc < ccend)  while (cc < ccend)
7302    {    {
# Line 6923  while (cc < ccend) Line 7513  while (cc < ccend)
7513      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
7514      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
7515      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);
7516      allocate_stack(common, 1);      allocate_stack(common, common->has_skip_arg ? 5 : 1);
7517      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7518      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);
7519      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7520      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);
7521      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);
7522        if (common->has_skip_arg)
7523          {
7524          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7525          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7526          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_mark);
7527          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), SLJIT_IMM, (sljit_sw)(cc + 2));
7528          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0);
7529          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
7530          }
7531      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
7532      break;      break;
7533    
7534        case OP_PRUNE:
7535        case OP_PRUNE_ARG:
7536        case OP_SKIP:
7537        case OP_SKIP_ARG:
7538        case OP_THEN:
7539        case OP_THEN_ARG:
7540      case OP_COMMIT:      case OP_COMMIT:
7541      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      cc = compile_control_verb_matchingpath(common, cc, parent);
     cc += 1;  
7542      break;      break;
7543    
7544      case OP_FAIL:      case OP_FAIL:
# Line 6958  while (cc < ccend) Line 7562  while (cc < ccend)
7562    if (cc == NULL)    if (cc == NULL)
7563      return;      return;
7564    }    }
7565    
7566    if (has_then_trap)
7567      {
7568      /* Head item on backtrack. */
7569      PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7570      BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7571      BACKTRACK_AS(then_trap_backtrack)->then_trap = common->then_trap;
7572      common->then_trap = save_then_trap;
7573      }
7574  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
7575  }  }
7576    
# Line 7119  switch(opcode) Line 7732  switch(opcode)
7732    }    }
7733  }  }
7734    
7735  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)
7736  {  {
7737  DEFINE_COMPILER;  DEFINE_COMPILER;
7738  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
# Line 7141  set_jumps(current->topbacktracks, LABEL( Line 7754  set_jumps(current->topbacktracks, LABEL(
7754  free_stack(common, 2);  free_stack(common, 2);
7755  }  }
7756    
7757  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)
7758  {  {
7759  DEFINE_COMPILER;  DEFINE_COMPILER;
7760    
7761    if (CURRENT_AS(recurse_backtrack)->inlined_pattern)
7762      compile_backtrackingpath(common, current->top);
7763  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
7764    if (CURRENT_AS(recurse_backtrack)->inlined_pattern)
7765      return;
7766    
7767  if (common->has_set_som && common->mark_ptr != 0)  if (common->has_set_som && common->mark_ptr != 0)
7768    {    {
# Line 7247  pcre_uchar bra = OP_BRA; Line 7864  pcre_uchar bra = OP_BRA;
7864  pcre_uchar ket;  pcre_uchar ket;
7865  assert_backtrack *assert;  assert_backtrack *assert;
7866  BOOL has_alternatives;  BOOL has_alternatives;
7867    BOOL needs_control_head = FALSE;
7868  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
7869  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
7870  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
# Line 7272  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 7890  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
7890  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
7891    opcode = OP_ONCE;    opcode = OP_ONCE;
7892    
7893    /* Decoding the needs_control_head in framesize. */
7894    if (opcode == OP_ONCE)
7895      {
7896      needs_control_head = (CURRENT_AS(bracket_backtrack)->u.framesize & 0x1) != 0;
7897      CURRENT_AS(bracket_backtrack)->u.framesize >>= 1;
7898      }
7899    
7900  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
7901    {    {
7902    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
# Line 7315  if (offset != 0) Line 7940  if (offset != 0)
7940    {    {
7941    if (common->capture_last_ptr != 0)    if (common->capture_last_ptr != 0)
7942      {      {
7943        SLJIT_ASSERT(common->optimized_cbracket[offset >> 1] == 0);
7944      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7945      free_stack(common, 1);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7946      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);
7947        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
7948        free_stack(common, 3);
7949        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP2, 0);
7950        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
7951      }      }
7952    if (common->optimized_cbracket[offset >> 1] == 0)    else if (common->optimized_cbracket[offset >> 1] == 0)
7953      {      {
7954      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7955      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
# Line 7424  if (has_alternatives) Line 8054  if (has_alternatives)
8054      current->top = NULL;      current->top = NULL;
8055      current->topbacktracks = NULL;      current->topbacktracks = NULL;
8056      current->nextbacktracks = NULL;      current->nextbacktracks = NULL;
8057        /* Conditional blocks always have an additional alternative, even if it is empty. */
8058      if (*cc == OP_ALT)      if (*cc == OP_ALT)
8059        {        {
8060        ccprev = cc + 1 + LINK_SIZE;        ccprev = cc + 1 + LINK_SIZE;
8061        cc += GET(cc, 1);        cc += GET(cc, 1);
8062        if (opcode != OP_COND && opcode != OP_SCOND)        if (opcode != OP_COND && opcode != OP_SCOND)
8063          {          {
8064          if (private_data_ptr != 0 && opcode != OP_ONCE)          if (opcode != OP_ONCE)
8065            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);            {
8066              if (private_data_ptr != 0)
8067                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
8068              else
8069                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8070              }
8071          else          else
8072            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));
8073          }          }
8074        compile_matchingpath(common, ccprev, cc, current);        compile_matchingpath(common, ccprev, cc, current);
8075        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
# Line 7443  if (has_alternatives) Line 8079  if (has_alternatives)
8079      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is succesfully matched. */
8080      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8081      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8082        {        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));  
           }  
         }  
       }  
8083    
8084      stacksize = 0;      stacksize = 0;
8085      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
# Line 7480  if (has_alternatives) Line 8094  if (has_alternatives)
8094      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8095        stacksize++;        stacksize++;
8096    
8097      if (stacksize > 0) {      if (stacksize > 0)
8098          {
8099        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
8100          allocate_stack(common, stacksize);          allocate_stack(common, stacksize);
8101        else        else
# Line 7489  if (has_alternatives) Line 8104  if (has_alternatives)
8104          SLJIT_ASSERT(stacksize == 1);          SLJIT_ASSERT(stacksize == 1);
8105          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));
8106          }          }
8107      }        }
8108    
8109      stacksize = 0;      stacksize = 0;
8110      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
# Line 7502  if (has_alternatives) Line 8117  if (has_alternatives)
8117        }        }
8118    
8119      if (offset != 0)      if (offset != 0)
8120        {        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;  
         }  
       }  
8121    
8122      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8123        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 7555  if (has_alternatives) Line 8151  if (has_alternatives)
8151      SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND);      SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND);
8152      assert = CURRENT_AS(bracket_backtrack)->u.assert;      assert = CURRENT_AS(bracket_backtrack)->u.assert;
8153      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)
   
8154        {        {
8155        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);
8156        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
# Line 7595  else if (opcode == OP_SBRA || opcode == Line 8190  else if (opcode == OP_SBRA || opcode ==
8190  else if (opcode == OP_ONCE)  else if (opcode == OP_ONCE)
8191    {    {
8192    cc = ccbegin + GET(ccbegin, 1);    cc = ccbegin + GET(ccbegin, 1);
8193      stacksize = needs_control_head ? 1 : 0;
8194    
8195    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
8196      {      {
8197      /* Reset head and drop saved frame. */      /* Reset head and drop saved frame. */
8198      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);  
8199      }      }
8200    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))
8201      {      {
8202      /* The STR_PTR must be released. */      /* The STR_PTR must be released. */
8203      free_stack(common, 1);      stacksize++;
8204      }      }
8205      free_stack(common, stacksize);
8206    
8207    JUMPHERE(once);    JUMPHERE(once);
8208    /* Restore previous private_data_ptr */    /* Restore previous private_data_ptr */
# Line 7657  else if (bra == OP_BRAZERO) Line 8254  else if (bra == OP_BRAZERO)
8254    }    }
8255  }  }
8256    
8257  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)
8258  {  {
8259  DEFINE_COMPILER;  DEFINE_COMPILER;
8260  int offset;  int offset;
# Line 7671  if (CURRENT_AS(bracketpos_backtrack)->fr Line 8268  if (CURRENT_AS(bracketpos_backtrack)->fr
8268      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8269      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
8270      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
8271        if (common->capture_last_ptr != 0)
8272          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
8273      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);
8274        if (common->capture_last_ptr != 0)
8275          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);
8276      }      }
8277    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
8278    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);
# Line 7692  if (current->topbacktracks) Line 8293  if (current->topbacktracks)
8293  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));
8294  }  }
8295    
8296  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)
8297  {  {
8298  assert_backtrack backtrack;  assert_backtrack backtrack;
8299    
# Line 7716  else Line 8317  else
8317  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);
8318  }  }
8319    
8320    static SLJIT_INLINE void compile_control_verb_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8321    {
8322    DEFINE_COMPILER;
8323    pcre_uchar opcode = *current->cc;
8324    struct sljit_label *loop;
8325    struct sljit_jump *jump;
8326    
8327    if (opcode == OP_THEN || opcode == OP_THEN_ARG)
8328      {
8329      if (common->then_trap != NULL)
8330        {
8331        SLJIT_ASSERT(common->control_head_ptr != 0);
8332    
8333        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8334        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, type_then_trap);
8335        OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, common->then_trap->start);
8336        jump = JUMP(SLJIT_JUMP);
8337    
8338        loop = LABEL();
8339        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), -(int)sizeof(sljit_sw));
8340        JUMPHERE(jump);
8341        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), -(int)(2 * sizeof(sljit_sw)), TMP1, 0, loop);
8342        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), -(int)(3 * sizeof(sljit_sw)), TMP2, 0, loop);
8343        add_jump(compiler, &common->then_trap->quit, JUMP(SLJIT_JUMP));
8344        return;
8345        }
8346      else if (common->then_local_exit != 0)
8347        {
8348        if (common->then_local_exit > 0)
8349          add_jump(compiler, &common->then_quit, JUMP(SLJIT_JUMP));
8350        else if (common->accept_label == NULL)
8351          add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));
8352        else
8353          JUMPTO(SLJIT_JUMP, common->accept_label);
8354        return;
8355        }
8356      }
8357    
8358    if (common->local_exit)
8359      {
8360      if (common->quit_label == NULL)
8361        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8362      else
8363        JUMPTO(SLJIT_JUMP, common->quit_label);
8364      return;
8365      }
8366    
8367    if (opcode == OP_SKIP_ARG)
8368      {
8369      SLJIT_ASSERT(common->control_head_ptr != 0);
8370      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8371      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
8372      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, (sljit_sw)(current->cc + 2));
8373      sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_search_mark));
8374      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
8375    
8376      OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
8377      add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));
8378      return;
8379      }
8380    
8381    if (opcode == OP_SKIP)
8382      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8383    else
8384      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_IMM, 0);
8385    add_jump(compiler, &common->reset_match, JUMP(SLJIT_JUMP));
8386    }
8387    
8388    static SLJIT_INLINE void compile_then_trap_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8389    {
8390    DEFINE_COMPILER;
8391    struct sljit_jump *jump;
8392    int size;
8393    
8394    if (CURRENT_AS(then_trap_backtrack)->then_trap)
8395      {
8396      common->then_trap = CURRENT_AS(then_trap_backtrack)->then_trap;
8397      return;
8398      }
8399    
8400    size = CURRENT_AS(then_trap_backtrack)->framesize;
8401    size = 3 + (size < 0 ? 0 : size);
8402    
8403    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(size - 3));
8404    free_stack(common, size);
8405    jump = JUMP(SLJIT_JUMP);
8406    
8407    set_jumps(CURRENT_AS(then_trap_backtrack)->quit, LABEL());
8408    /* STACK_TOP is set by THEN. */
8409    if (CURRENT_AS(then_trap_backtrack)->framesize >= 0)
8410      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
8411    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8412    free_stack(common, 3);
8413    
8414    JUMPHERE(jump);
8415    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
8416    }
8417    
8418  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8419  {  {
8420  DEFINE_COMPILER;  DEFINE_COMPILER;
8421    then_trap_backtrack *save_then_trap = common->then_trap;
8422    
8423  while (current)  while (current)
8424    {    {
# Line 7852  while (current) Line 8552  while (current)
8552      break;      break;
8553    
8554      case OP_MARK:      case OP_MARK:
8555      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));
8556      free_stack(common, 1);      if (common->has_skip_arg)
8557          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8558        free_stack(common, common->has_skip_arg ? 5 : 1);
8559      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);
8560        if (common->has_skip_arg)
8561          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP2, 0);
8562        break;
8563    
8564        case OP_THEN:
8565        case OP_THEN_ARG:
8566        case OP_PRUNE:
8567        case OP_PRUNE_ARG:
8568        case OP_SKIP:
8569        case OP_SKIP_ARG:
8570        compile_control_verb_backtrackingpath(common, current);
8571      break;      break;
8572    
8573      case OP_COMMIT:      case OP_COMMIT:
8574      OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);      if (!common->local_exit)
8575          OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
8576      if (common->quit_label == NULL)      if (common->quit_label == NULL)
8577        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8578      else      else
# Line 7872  while (current) Line 8586  while (current)
8586      set_jumps(current->topbacktracks, LABEL());      set_jumps(current->topbacktracks, LABEL());
8587      break;      break;
8588    
8589        case OP_THEN_TRAP:
8590        /* A virtual opcode for then traps. */
8591        compile_then_trap_backtrackingpath(common, current);
8592        break;
8593    
8594      default:      default:
8595      SLJIT_ASSERT_STOP();      SLJIT_ASSERT_STOP();
8596      break;      break;
8597      }      }
8598    current = current->prev;    current = current->prev;
8599    }    }
8600    common->then_trap = save_then_trap;
8601  }  }
8602    
8603  static SLJIT_INLINE void compile_recurse(compiler_common *common)  static SLJIT_INLINE void compile_recurse(compiler_common *common)
# Line 7886  DEFINE_COMPILER; Line 8606  DEFINE_COMPILER;
8606  pcre_uchar *cc = common->start + common->currententry->start;  pcre_uchar *cc = common->start + common->currententry->start;
8607  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);
8608  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
8609  int private_data_size = get_private_data_length_for_copy(common, ccbegin, ccend);  BOOL needs_control_head;
8610  int framesize = get_framesize(common, cc, TRUE);  int framesize = get_framesize(common, cc, NULL, TRUE, &needs_control_head);
8611    int private_data_size = get_private_data_copy_length(common, ccbegin, ccend, needs_control_head);
8612  int alternativesize;  int alternativesize;
8613  BOOL needsframe;  BOOL needs_frame;
8614  backtrack_common altbacktrack;  backtrack_common altbacktrack;
 struct sljit_label *save_quit_label = common->quit_label;  
 jump_list *save_quit = common->quit;  
8615  struct sljit_jump *jump;  struct sljit_jump *jump;
8616    
8617    /* Recurse captures then. */
8618    common->then_trap = NULL;
8619    
8620  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);
8621  needsframe = framesize >= 0;  needs_frame = framesize >= 0;
8622  if (!needsframe)  if (!needs_frame)
8623    framesize = 0;    framesize = 0;
8624  alternativesize = *(cc + GET(cc, 1)) == OP_ALT ? 1 : 0;  alternativesize = *(cc + GET(cc, 1)) == OP_ALT ? 1 : 0;
8625    
# Line 7908  set_jumps(common->currententry->calls, c Line 8630  set_jumps(common->currententry->calls, c
8630  sljit_emit_fast_enter(compiler, TMP2, 0);  sljit_emit_fast_enter(compiler, TMP2, 0);
8631  allocate_stack(common, private_data_size + framesize + alternativesize);  allocate_stack(common, private_data_size + framesize + alternativesize);
8632  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);
8633  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);
8634    if (needs_control_head)
8635      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
8636  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);
8637  if (needsframe)  if (needs_frame)
8638    init_frame(common, cc, framesize + alternativesize - 1, alternativesize, TRUE);    init_frame(common, cc, NULL, framesize + alternativesize - 1, alternativesize, TRUE);
8639    
8640  if (alternativesize > 0)  if (alternativesize > 0)
8641    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
# Line 7933  while (1) Line 8657  while (1)
8657    
8658    compile_matchingpath(common, altbacktrack.cc, cc, &altbacktrack);    compile_matchingpath(common, altbacktrack.cc, cc, &altbacktrack);
8659    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
     {  
     common->quit_label = save_quit_label;  
     common->quit = save_quit;  
8660      return;      return;
     }  
8661    
8662    add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));    add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));
8663    
8664    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
8665    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
     {  
     common->quit_label = save_quit_label;  
     common->quit = save_quit;  
8666      return;      return;
     }  
8667    set_jumps(altbacktrack.topbacktracks, LABEL());    set_jumps(altbacktrack.topbacktracks, LABEL());
8668    
8669    if (*cc != OP_ALT)    if (*cc != OP_ALT)
# Line 7956  while (1) Line 8672  while (1)
8672    altbacktrack.cc = cc + 1 + LINK_SIZE;    altbacktrack.cc = cc + 1 + LINK_SIZE;
8673    cc += GET(cc, 1);    cc += GET(cc, 1);
8674    }    }
 /* None of them matched. */  
 if (common->quit != NULL)  
   set_jumps(common->quit, LABEL());  
8675    
8676    /* None of them matched. */
8677  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0);
8678  jump = JUMP(SLJIT_JUMP);  jump = JUMP(SLJIT_JUMP);
8679    
8680    if (common->quit != NULL)
8681      {
8682      set_jumps(common->quit, LABEL());
8683      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr);
8684      if (needs_frame)
8685        {
8686        OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));
8687        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
8688        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));
8689        }
8690      OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0);
8691      common->quit = NULL;
8692      add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8693      }
8694    
8695  set_jumps(common->accept, LABEL());  set_jumps(common->accept, LABEL());
8696  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr);  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr);
8697  if (needsframe)  if (needs_frame)
8698    {    {
8699    OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));    OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));
8700    add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
# Line 7974  if (needsframe) Line 8703  if (needsframe)
8703  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1);  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1);
8704    
8705  JUMPHERE(jump);  JUMPHERE(jump);
8706  copy_private_data(common, ccbegin, ccend, FALSE, private_data_size + framesize + alternativesize, framesize + alternativesize);  if (common->quit != NULL)
8707      set_jumps(common->quit, LABEL());
8708    copy_private_data(common, ccbegin, ccend, FALSE, private_data_size + framesize + alternativesize, framesize + alternativesize, needs_control_head);
8709  free_stack(common, private_data_size + framesize + alternativesize);  free_stack(common, private_data_size + framesize + alternativesize);
8710  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));  if (needs_control_head)
8711  OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    {
8712  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, TMP2, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 2 * sizeof(sljit_sw));
8713      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));
8714      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, TMP1, 0);
8715      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
8716      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP2, 0);
8717      }
8718    else
8719      {
8720      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));
8721      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
8722      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, TMP2, 0);
8723      }
8724  sljit_emit_fast_return(compiler, SLJIT_MEM1(STACK_TOP), 0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(STACK_TOP), 0);
   
 common->quit_label = save_quit_label;  
 common->quit = save_quit;  
8725  }  }
8726    
8727  #undef COMPILE_BACKTRACKINGPATH  #undef COMPILE_BACKTRACKINGPATH
# Line 8002  pcre_uchar *ccend; Line 8741  pcre_uchar *ccend;
8741  executable_functions *functions;  executable_functions *functions;
8742  void *executable_func;  void *executable_func;
8743  sljit_uw executable_size;  sljit_uw executable_size;
8744  struct sljit_label *mainloop = NULL;  struct sljit_label *mainloop_label = NULL;
8745  struct sljit_label *empty_match_found;  struct sljit_label *continue_match_label;
8746  struct sljit_label *empty_match_backtrack;  struct sljit_label *empty_match_found_label;
8747    struct sljit_label *empty_match_backtrack_label;
8748    struct sljit_label *reset_match_label;
8749  struct sljit_jump *jump;  struct sljit_jump *jump;
8750  struct sljit_jump *minlength_check_failed = NULL;  struct sljit_jump *minlength_check_failed = NULL;
8751  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
8752  struct sljit_jump *empty_match;  struct sljit_jump *empty_match;
8753    struct sljit_label *quit_label;
8754    
8755  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);
8756  study = extra->study_data;  study = extra->study_data;
# Line 8077  common->ovector_start = CALL_LIMIT + siz Line 8819  common->ovector_start = CALL_LIMIT + siz
8819  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);
8820  if (!common->optimized_cbracket)  if (!common->optimized_cbracket)
8821    return;    return;
8822    #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 1
8823    memset(common->optimized_cbracket, 0, re->top_bracket + 1);
8824    #else
8825  memset(common->optimized_cbracket, 1, re->top_bracket + 1);  memset(common->optimized_cbracket, 1, re->top_bracket + 1);
8826    #endif
8827    
8828  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
8829    #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2
8830    common->capture_last_ptr = common->ovector_start;
8831    common->ovector_start += sizeof(sljit_sw);
8832    #endif
8833  private_data_size = get_private_data_length(common, rootbacktrack.cc, ccend);  private_data_size = get_private_data_length(common, rootbacktrack.cc, ccend);
8834  if (private_data_size < 0)  if (private_data_size < 0)
8835    {    {
# Line 8100  if (mode != JIT_COMPILE) Line 8850  if (mode != JIT_COMPILE)
8850    if (mode == JIT_PARTIAL_SOFT_COMPILE)    if (mode == JIT_PARTIAL_SOFT_COMPILE)
8851      {      {
8852      common->hit_start = common->ovector_start;      common->hit_start = common->ovector_start;
8853      common->ovector_start += sizeof(sljit_sw);      common->ovector_start += 2 * sizeof(sljit_sw);
8854        }
8855      else
8856        {
8857        SLJIT_ASSERT(mode == JIT_PARTIAL_HARD_COMPILE);
8858        common->needs_start_ptr = TRUE;
8859      }      }
8860    }    }
8861  if ((re->options & PCRE_FIRSTLINE) != 0)  if ((re->options & PCRE_FIRSTLINE) != 0)
# Line 8108  if ((re->options & PCRE_FIRSTLINE) != 0) Line 8863  if ((re->options & PCRE_FIRSTLINE) != 0)
8863    common->first_line_end = common->ovector_start;    common->first_line_end = common->ovector_start;
8864    common->ovector_start += sizeof(sljit_sw);    common->ovector_start += sizeof(sljit_sw);
8865    }    }
8866    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
8867    common->control_head_ptr = 1;
8868    #endif
8869    if (common->control_head_ptr != 0)
8870      {
8871      common->control_head_ptr = common->ovector_start;
8872      common->ovector_start += sizeof(sljit_sw);
8873      }
8874    if (common->needs_start_ptr && common->has_set_som)
8875      {
8876      /* Saving the real start pointer is necessary. */
8877      common->start_ptr = common->ovector_start;
8878      common->ovector_start += sizeof(sljit_sw);
8879      }
8880    else
8881      common->needs_start_ptr = FALSE;
8882    
8883  /* Aligning ovector to even number of sljit words. */  /* Aligning ovector to even number of sljit words. */
8884  if ((common->ovector_start & sizeof(sljit_sw)) != 0)  if ((common->ovector_start & sizeof(sljit_sw)) != 0)
8885    common->ovector_start += sizeof(sljit_sw);    common->ovector_start += sizeof(sljit_sw);
8886    
8887    if (common->start_ptr == 0)
8888      common->start_ptr = OVECTOR(0);
8889    
8890  /* Capturing brackets cannot be optimized if callouts are allowed. */  /* Capturing brackets cannot be optimized if callouts are allowed. */
8891  if (common->capture_last_ptr != 0)  if (common->capture_last_ptr != 0)
8892    memset(common->optimized_cbracket, 0, re->top_bracket + 1);    memset(common->optimized_cbracket, 0, re->top_bracket + 1);
8893    
8894  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
8895  common->cbraptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);
8896  private_data_size += common->cbraptr + (re->top_bracket + 1) * sizeof(sljit_sw);  private_data_size += common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);
8897  if (private_data_size > SLJIT_MAX_LOCAL_SIZE)  if (private_data_size > SLJIT_MAX_LOCAL_SIZE)
8898    {    {
8899    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
8900    return;    return;
8901    }    }
8902    
8903  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(int));  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(int));
8904  if (!common->private_data_ptrs)  if (!common->private_data_ptrs)
8905    {    {
# Line 8132  if (!common->private_data_ptrs) Line 8907  if (!common->private_data_ptrs)
8907    return;    return;
8908    }    }
8909  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));
8910  set_private_data_ptrs(common, common->cbraptr + (re->top_bracket + 1) * sizeof(sljit_sw), ccend);  set_private_data_ptrs(common, common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw), ccend);
8911    
8912    if (common->has_then)
8913      {
8914      common->then_offsets = (pcre_uint8 *)SLJIT_MALLOC(ccend - rootbacktrack.cc);
8915      if (!common->then_offsets)
8916        {
8917        SLJIT_FREE(common->optimized_cbracket);
8918        SLJIT_FREE(common->private_data_ptrs);
8919        return;
8920        }
8921      memset(common->then_offsets, 0, ccend - rootbacktrack.cc);
8922      set_then_offsets(common, rootbacktrack.cc, NULL);
8923      }
8924    
8925  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
8926  if (!compiler)  if (!compiler)
8927    {    {
8928    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
8929    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
8930      if (common->has_then)
8931        SLJIT_FREE(common->then_offsets);
8932    return;    return;
8933    }    }
8934  common->compiler = compiler;  common->compiler = compiler;
# Line 8162  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM Line 8952  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM
8952  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);
8953    
8954  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8955    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
8956    if (common->mark_ptr != 0)
8957      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
8958    if (common->control_head_ptr != 0)
8959      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
8960    
8961  /* Main part of the matching */  /* Main part of the matching */
8962  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
8963    {    {
8964    mainloop = mainloop_entry(common, (re->flags & PCRE_HASCRORLF) != 0, (re->options & PCRE_FIRSTLINE) != 0);    mainloop_label = mainloop_entry(common, (re->flags & PCRE_HASCRORLF) != 0, (re->options & PCRE_FIRSTLINE) != 0);
8965      continue_match_label = LABEL();
8966    /* Forward search if possible. */    /* Forward search if possible. */
8967    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)
8968      {      {
# Line 8181  if ((re->options & PCRE_ANCHORED) == 0) Line 8976  if ((re->options & PCRE_ANCHORED) == 0)
8976        fast_forward_start_bits(common, (sljit_uw)study->start_bits, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_start_bits(common, (sljit_uw)study->start_bits, (re->options & PCRE_FIRSTLINE) != 0);
8977      }      }
8978    }    }
8979    else
8980      continue_match_label = LABEL();
8981    
8982  if (mode == JIT_COMPILE && study->minlength > 0 && (re->options & PCRE_NO_START_OPTIMIZE) == 0)  if (mode == JIT_COMPILE && study->minlength > 0 && (re->options & PCRE_NO_START_OPTIMIZE) == 0)
8983    {    {
8984    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
# Line 8194  if (common->req_char_ptr != 0) Line 8992  if (common->req_char_ptr != 0)
8992  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), STR_PTR, 0);
8993  /* Copy the limit of allowed recursions. */  /* Copy the limit of allowed recursions. */
8994  OP1(SLJIT_MOV, CALL_COUNT, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT);  OP1(SLJIT_MOV, CALL_COUNT, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT);
 if (common->mark_ptr != 0)  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);  
8995  if (common->capture_last_ptr != 0)  if (common->capture_last_ptr != 0)
8996    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, -1);
8997    
8998    if (common->needs_start_ptr)
8999      {
9000      SLJIT_ASSERT(common->start_ptr != OVECTOR(0));
9001      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr, STR_PTR, 0);
9002      }
9003    else
9004      SLJIT_ASSERT(common->start_ptr == OVECTOR(0));
9005    
9006  /* Copy the beginning of the string. */  /* Copy the beginning of the string. */
9007  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9008    {    {
9009    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
9010    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
9011      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start + sizeof(sljit_sw), STR_PTR, 0);
9012    JUMPHERE(jump);    JUMPHERE(jump);
9013    }    }
9014  else if (mode == JIT_PARTIAL_HARD_COMPILE)  else if (mode == JIT_PARTIAL_HARD_COMPILE)
# Line 8214  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 9020  if (SLJIT_UNLIKELY(sljit_get_compiler_er
9020    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
9021    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9022    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9023      if (common->has_then)
9024        SLJIT_FREE(common->then_offsets);
9025    return;    return;
9026    }    }
9027    
9028  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
9029  empty_match_found = LABEL();  empty_match_found_label = LABEL();
9030    
9031  common->accept_label = LABEL();  common->accept_label = LABEL();
9032  if (common->accept != NULL)  if (common->accept != NULL)
# Line 8232  if (common->quit != NULL) Line 9040  if (common->quit != NULL)
9040  if (common->forced_quit != NULL)  if (common->forced_quit != NULL)
9041    set_jumps(common->forced_quit, common->forced_quit_label);    set_jumps(common->forced_quit, common->forced_quit_label);
9042  if (minlength_check_failed != NULL)  if (minlength_check_failed != NULL)
9043    sljit_set_label(minlength_check_failed, common->forced_quit_label);    SET_LABEL(minlength_check_failed, common->forced_quit_label);
9044  sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);  sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
9045    
9046  if (mode != JIT_COMPILE)  if (mode != JIT_COMPILE)
# Line 8242  if (mode != JIT_COMPILE) Line 9050  if (mode != JIT_COMPILE)
9050    return_with_partial_match(common, common->quit_label);    return_with_partial_match(common, common->quit_label);
9051    }    }
9052    
9053  empty_match_backtrack = LABEL();  empty_match_backtrack_label = LABEL();
9054  compile_backtrackingpath(common, rootbacktrack.top);  compile_backtrackingpath(common, rootbacktrack.top);
9055  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
9056    {    {
9057    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
9058    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9059    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9060      if (common->has_then)
9061        SLJIT_FREE(common->then_offsets);
9062    return;    return;
9063    }    }
9064    
9065  SLJIT_ASSERT(rootbacktrack.prev == NULL);  SLJIT_ASSERT(rootbacktrack.prev == NULL);
9066    reset_match_label = LABEL();
9067    
9068  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9069    {    {
9070    /* Update hit_start only in the first time. */    /* Update hit_start only in the first time. */
9071    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
9072    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr);
9073    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
9074    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, TMP1, 0);
# Line 8265  if (mode == JIT_PARTIAL_SOFT_COMPILE) Line 9076  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9076    }    }
9077    
9078  /* Check we have remaining characters. */  /* Check we have remaining characters. */
9079  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  if ((re->options & PCRE_ANCHORED) == 0 && (re->options & PCRE_FIRSTLINE) != 0)
9080      {
9081      SLJIT_ASSERT(common->first_line_end != 0);
9082      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
9083      }
9084    
9085    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
9086    
9087  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
9088    {    {
9089    if ((re->options & PCRE_FIRSTLINE) == 0)    if ((re->options & PCRE_FIRSTLINE) == 0)
9090      {      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop_label);
     if (mode == JIT_COMPILE && study != NULL && study->minlength > 1 && (re->options & PCRE_NO_START_OPTIMIZE) == 0)  
       {  
       OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(study->minlength + 1));  
       CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_END, 0, mainloop);  
       }  
     else  
       CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);  
     }  
9091    else    else
9092      {      CMPTO(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0, mainloop_label);
     SLJIT_ASSERT(common->first_line_end != 0);  
     if (mode == JIT_COMPILE && study != NULL && study->minlength > 1 && (re->options & PCRE_NO_START_OPTIMIZE) == 0)  
       {  
       OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(study->minlength + 1));  
       OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, STR_END, 0);  
       OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);  
       OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);  
       OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);  
       JUMPTO(SLJIT_C_ZERO, mainloop);  
       }  
     else  
       CMPTO(SLJIT_C_LESS, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, mainloop);  
     }  
9093    }    }
9094    
9095  /* No more remaining characters. */  /* No more remaining characters. */
# Line 8301  if (reqbyte_notfound != NULL) Line 9097  if (reqbyte_notfound != NULL)
9097    JUMPHERE(reqbyte_notfound);    JUMPHERE(reqbyte_notfound);
9098    
9099  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9100    CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0, common->partialmatchlabel);    CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1, common->partialmatchlabel);
9101    
9102  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
9103  JUMPTO(SLJIT_JUMP, common->quit_label);  JUMPTO(SLJIT_JUMP, common->quit_label);
# Line 8311  flush_stubs(common); Line 9107  flush_stubs(common);
9107  JUMPHERE(empty_match);  JUMPHERE(empty_match);
9108  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
9109  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));
9110  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);
9111  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));
9112  CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found);  CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found_label);
9113  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
9114  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);
9115  JUMPTO(SLJIT_JUMP, empty_match_backtrack);  JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);
9116    
9117  common->currententry = common->entries;  common->currententry = common->entries;
9118    common->local_exit = TRUE;
9119    quit_label = common->quit_label;
9120  while (common->currententry != NULL)  while (common->currententry != NULL)
9121    {    {
9122    /* Might add new entries. */    /* Might add new entries. */
# Line 8328  while (common->currententry != NULL) Line 9126  while (common->currententry != NULL)
9126      sljit_free_compiler(compiler);      sljit_free_compiler(compiler);
9127      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9128      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9129        if (common->has_then)
9130          SLJIT_FREE(common->then_offsets);
9131      return;      return;
9132      }      }
9133    flush_stubs(common);    flush_stubs(common);
9134    common->currententry = common->currententry->next;    common->currententry = common->currententry->next;
9135    }    }
9136    common->local_exit = FALSE;
9137    common->quit_label = quit_label;
9138    
9139  /* Allocating stack, returns with PCRE_ERROR_JIT_STACKLIMIT if fails. */  /* Allocating stack, returns with PCRE_ERROR_JIT_STACKLIMIT if fails. */
9140  /* This is a (really) rare case. */  /* This is a (really) rare case. */
# Line 8400  if (common->caselesscmp != NULL) Line 9202  if (common->caselesscmp != NULL)
9202    set_jumps(common->caselesscmp, LABEL());    set_jumps(common->caselesscmp, LABEL());
9203    do_caselesscmp(common);    do_caselesscmp(common);
9204    }    }
9205    if (common->reset_match != NULL)
9206      {
9207      set_jumps(common->reset_match, LABEL());
9208      do_reset_match(common, (re->top_bracket + 1) * 2);
9209      CMPTO(SLJIT_C_GREATER, STR_PTR, 0, TMP1, 0, continue_match_label);
9210      OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
9211      JUMPTO(SLJIT_JUMP, reset_match_label);
9212      }
9213  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
9214  #ifndef COMPILE_PCRE32  #ifndef COMPILE_PCRE32
9215  if (common->utfreadchar != NULL)  if (common->utfreadchar != NULL)
# Line 8426  if (common->getucd != NULL) Line 9236  if (common->getucd != NULL)
9236    
9237  SLJIT_FREE(common->optimized_cbracket);  SLJIT_FREE(common->optimized_cbracket);
9238  SLJIT_FREE(common->private_data_ptrs);  SLJIT_FREE(common->private_data_ptrs);
9239    if (common->has_then)
9240      SLJIT_FREE(common->then_offsets);
9241    
9242  executable_func = sljit_generate_code(compiler);  executable_func = sljit_generate_code(compiler);
9243  executable_size = sljit_get_generated_code_size(compiler);  executable_size = sljit_get_generated_code_size(compiler);
9244  sljit_free_compiler(compiler);  sljit_free_compiler(compiler);
# Line 8517  arguments.notempty = (options & PCRE_NOT Line 9330  arguments.notempty = (options & PCRE_NOT
9330  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
9331  arguments.offsets = offsets;  arguments.offsets = offsets;
9332  arguments.callout_data = (extra_data->flags & PCRE_EXTRA_CALLOUT_DATA) != 0 ? extra_data->callout_data : NULL;  arguments.callout_data = (extra_data->flags & PCRE_EXTRA_CALLOUT_DATA) != 0 ? extra_data->callout_data : NULL;
9333    arguments.real_offset_count = offset_count;
9334    
9335  /* pcre_exec() rounds offset_count to a multiple of 3, and then uses only 2/3 of  /* pcre_exec() rounds offset_count to a multiple of 3, and then uses only 2/3 of
9336  the output vector for storing captured strings, with the remainder used as  the output vector for storing captured strings, with the remainder used as
# Line 8607  arguments.notempty = (options & PCRE_NOT Line 9421  arguments.notempty = (options & PCRE_NOT
9421  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
9422  arguments.offsets = offsets;  arguments.offsets = offsets;
9423  arguments.callout_data = (extra_data->flags & PCRE_EXTRA_CALLOUT_DATA) != 0 ? extra_data->callout_data : NULL;  arguments.callout_data = (extra_data->flags & PCRE_EXTRA_CALLOUT_DATA) != 0 ? extra_data->callout_data : NULL;
9424    arguments.real_offset_count = offset_count;
9425    
9426  /* pcre_exec() rounds offset_count to a multiple of 3, and then uses only 2/3 of  /* pcre_exec() rounds offset_count to a multiple of 3, and then uses only 2/3 of
9427  the output vector for storing captured strings, with the remainder used as  the output vector for storing captured strings, with the remainder used as

Legend:
Removed from v.1245  
changed lines
  Added in v.1300

  ViewVC Help
Powered by ViewVC 1.1.5