/[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 1221 by ph10, Sun Nov 11 20:27:03 2012 UTC revision 1269 by zherczeg, Mon Mar 4 10:47:12 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  /* Allocate memory for the regex stack on the real machine stack.  /* Allocate memory for the regex stack on the real machine stack.
75  Fast, but limited size. */  Fast, but limited size. */
76  #define MACHINE_STACK_SIZE 32768  #define MACHINE_STACK_SIZE 32768
# Line 157  typedef struct jit_arguments { Line 163  typedef struct jit_arguments {
163    int *offsets;    int *offsets;
164    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
165    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
166      void *callout_data;
167    /* Everything else after. */    /* Everything else after. */
168    int offsetcount;    int real_offset_count;
169    int calllimit;    int offset_count;
170      int call_limit;
171    pcre_uint8 notbol;    pcre_uint8 notbol;
172    pcre_uint8 noteol;    pcre_uint8 noteol;
173    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 179  typedef struct jump_list { Line 187  typedef struct jump_list {
187    struct jump_list *next;    struct jump_list *next;
188  } jump_list;  } jump_list;
189    
 enum stub_types { stack_alloc };  
   
190  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
191    struct sljit_jump *start;    struct sljit_jump *start;
192    struct sljit_label *quit;    struct sljit_label *quit;
193    struct stub_list *next;    struct stub_list *next;
194  } stub_list;  } stub_list;
195    
196    enum frame_types { no_frame = -1, no_stack = -2 };
197    
198  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
199    
200  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
# Line 270  typedef struct recurse_entry { Line 276  typedef struct recurse_entry {
276    
277  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
278    backtrack_common common;    backtrack_common common;
279      BOOL inlined_pattern;
280  } recurse_backtrack;  } recurse_backtrack;
281    
282  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
# Line 289  typedef struct compiler_common { Line 296  typedef struct compiler_common {
296    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
297    int req_char_ptr;    int req_char_ptr;
298    /* Head of the last recursion. */    /* Head of the last recursion. */
299    int recursive_head;    int recursive_head_ptr;
300    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
301    int start_used_ptr;    int start_used_ptr;
302    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 298  typedef struct compiler_common { Line 305  typedef struct compiler_common {
305    int first_line_end;    int first_line_end;
306    /* Points to the marked string. */    /* Points to the marked string. */
307    int mark_ptr;    int mark_ptr;
308      /* Points to the last matched capture block index. */
309      int capture_last_ptr;
310    
311    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
312    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
# Line 321  typedef struct compiler_common { Line 330  typedef struct compiler_common {
330    
331    /* Labels and jump lists. */    /* Labels and jump lists. */
332    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
333    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
334    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
335      struct sljit_label *accept_label;
336    stub_list *stubs;    stub_list *stubs;
337    recurse_entry *entries;    recurse_entry *entries;
338    recurse_entry *currententry;    recurse_entry *currententry;
339    jump_list *partialmatch;    jump_list *partialmatch;
340    jump_list *quit;    jump_list *quit;
341      jump_list *forced_quit;
342    jump_list *accept;    jump_list *accept;
343    jump_list *calllimit;    jump_list *calllimit;
344    jump_list *stackalloc;    jump_list *stackalloc;
# Line 390  typedef struct compare_context { Line 401  typedef struct compare_context {
401  #endif  #endif
402  } compare_context;  } compare_context;
403    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
404  /* Undefine sljit macros. */  /* Undefine sljit macros. */
405  #undef CMP  #undef CMP
406    
# Line 459  the start pointers when the end of the c Line 464  the start pointers when the end of the c
464    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
465  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
466    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
467    #define SET_LABEL(jump, label) \
468      sljit_set_label((jump), (label))
469  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
470    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
471  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
# Line 507  switch(*cc) Line 514  switch(*cc)
514    case OP_WORDCHAR:    case OP_WORDCHAR:
515    case OP_ANY:    case OP_ANY:
516    case OP_ALLANY:    case OP_ALLANY:
517      case OP_NOTPROP:
518      case OP_PROP:
519    case OP_ANYNL:    case OP_ANYNL:
520    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
521    case OP_HSPACE:    case OP_HSPACE:
# Line 519  switch(*cc) Line 528  switch(*cc)
528    case OP_CIRCM:    case OP_CIRCM:
529    case OP_DOLL:    case OP_DOLL:
530    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:  
531    case OP_CRSTAR:    case OP_CRSTAR:
532    case OP_CRMINSTAR:    case OP_CRMINSTAR:
533    case OP_CRPLUS:    case OP_CRPLUS:
534    case OP_CRMINPLUS:    case OP_CRMINPLUS:
535    case OP_CRQUERY:    case OP_CRQUERY:
536    case OP_CRMINQUERY:    case OP_CRMINQUERY:
537      case OP_CRRANGE:
538      case OP_CRMINRANGE:
539      case OP_CLASS:
540      case OP_NCLASS:
541      case OP_REF:
542      case OP_REFI:
543      case OP_RECURSE:
544      case OP_CALLOUT:
545      case OP_ALT:
546      case OP_KET:
547      case OP_KETRMAX:
548      case OP_KETRMIN:
549      case OP_KETRPOS:
550      case OP_REVERSE:
551      case OP_ASSERT:
552      case OP_ASSERT_NOT:
553      case OP_ASSERTBACK:
554      case OP_ASSERTBACK_NOT:
555      case OP_ONCE:
556      case OP_ONCE_NC:
557      case OP_BRA:
558      case OP_BRAPOS:
559      case OP_CBRA:
560      case OP_CBRAPOS:
561      case OP_COND:
562      case OP_SBRA:
563      case OP_SBRAPOS:
564      case OP_SCBRA:
565      case OP_SCBRAPOS:
566      case OP_SCOND:
567      case OP_CREF:
568      case OP_NCREF:
569      case OP_RREF:
570      case OP_NRREF:
571    case OP_DEF:    case OP_DEF:
572    case OP_BRAZERO:    case OP_BRAZERO:
573    case OP_BRAMINZERO:    case OP_BRAMINZERO:
# Line 542  switch(*cc) Line 576  switch(*cc)
576    case OP_FAIL:    case OP_FAIL:
577    case OP_ACCEPT:    case OP_ACCEPT:
578    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
579      case OP_CLOSE:
580    case OP_SKIPZERO:    case OP_SKIPZERO:
581    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
582    
583    case OP_CHAR:    case OP_CHAR:
584    case OP_CHARI:    case OP_CHARI:
# Line 561  switch(*cc) Line 590  switch(*cc)
590    case OP_MINPLUS:    case OP_MINPLUS:
591    case OP_QUERY:    case OP_QUERY:
592    case OP_MINQUERY:    case OP_MINQUERY:
593      case OP_UPTO:
594      case OP_MINUPTO:
595      case OP_EXACT:
596    case OP_POSSTAR:    case OP_POSSTAR:
597    case OP_POSPLUS:    case OP_POSPLUS:
598    case OP_POSQUERY:    case OP_POSQUERY:
599      case OP_POSUPTO:
600    case OP_STARI:    case OP_STARI:
601    case OP_MINSTARI:    case OP_MINSTARI:
602    case OP_PLUSI:    case OP_PLUSI:
603    case OP_MINPLUSI:    case OP_MINPLUSI:
604    case OP_QUERYI:    case OP_QUERYI:
605    case OP_MINQUERYI:    case OP_MINQUERYI:
606      case OP_UPTOI:
607      case OP_MINUPTOI:
608      case OP_EXACTI:
609    case OP_POSSTARI:    case OP_POSSTARI:
610    case OP_POSPLUSI:    case OP_POSPLUSI:
611    case OP_POSQUERYI:    case OP_POSQUERYI:
612      case OP_POSUPTOI:
613    case OP_NOTSTAR:    case OP_NOTSTAR:
614    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
615    case OP_NOTPLUS:    case OP_NOTPLUS:
616    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
617    case OP_NOTQUERY:    case OP_NOTQUERY:
618    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
619      case OP_NOTUPTO:
620      case OP_NOTMINUPTO:
621      case OP_NOTEXACT:
622    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
623    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
624    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
625      case OP_NOTPOSUPTO:
626    case OP_NOTSTARI:    case OP_NOTSTARI:
627    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
628    case OP_NOTPLUSI:    case OP_NOTPLUSI:
629    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
630    case OP_NOTQUERYI:    case OP_NOTQUERYI:
631    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:  
632    case OP_NOTUPTOI:    case OP_NOTUPTOI:
633    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
634    case OP_NOTEXACTI:    case OP_NOTEXACTI:
635      case OP_NOTPOSSTARI:
636      case OP_NOTPOSPLUSI:
637      case OP_NOTPOSQUERYI:
638    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
639    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
640  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
641    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
642  #endif  #endif
643    return cc;    return cc;
644    
645    case OP_NOTPROP:    /* Special cases. */
646    case OP_PROP:    case OP_TYPESTAR:
647    return cc + 1 + 2;    case OP_TYPEMINSTAR:
648      case OP_TYPEPLUS:
649      case OP_TYPEMINPLUS:
650      case OP_TYPEQUERY:
651      case OP_TYPEMINQUERY:
652    case OP_TYPEUPTO:    case OP_TYPEUPTO:
653    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
654    case OP_TYPEEXACT:    case OP_TYPEEXACT:
655      case OP_TYPEPOSSTAR:
656      case OP_TYPEPOSPLUS:
657      case OP_TYPEPOSQUERY:
658    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
659    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;  
660    
661    case OP_CLASS:    case OP_ANYBYTE:
662    case OP_NCLASS:  #ifdef SUPPORT_UTF
663    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
664    #endif
665      return cc + 1;
666    
667  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
668    case OP_XCLASS:    case OP_XCLASS:
669    return cc + GET(cc, 1);    return cc + GET(cc, 1);
670  #endif  #endif
671    
   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;  
   
672    case OP_MARK:    case OP_MARK:
673    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
674    
# Line 812  while (cc < ccend) Line 804  while (cc < ccend)
804    
805      case OP_COND:      case OP_COND:
806      case OP_SCOND:      case OP_SCOND:
807      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
808      if (bracketlen == OP_CREF)         not intend to support this case. */
809        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
810        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        return -1;
       common->optimized_cbracket[bracketlen] = 0;  
       }  
     else if (bracketlen == OP_NCREF)  
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       name = (pcre_uchar *)common->name_table;  
       alternative = name;  
       for (i = 0; i < common->name_count; i++)  
         {  
         if (GET2(name, 0) == bracketlen) break;  
         name += common->name_entry_size;  
         }  
       SLJIT_ASSERT(i != common->name_count);  
   
       for (i = 0; i < common->name_count; i++)  
         {  
         if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)  
           common->optimized_cbracket[GET2(alternative, 0)] = 0;  
         alternative += common->name_entry_size;  
         }  
       }  
811    
812      if (*cc == OP_COND)      if (*cc == OP_COND)
813        {        {
# Line 850  while (cc < ccend) Line 821  while (cc < ccend)
821      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
822      break;      break;
823    
824        case OP_CREF:
825        i = GET2(cc, 1);
826        common->optimized_cbracket[i] = 0;
827        cc += 1 + IMM2_SIZE;
828        break;
829    
830        case OP_NCREF:
831        bracketlen = GET2(cc, 1);
832        name = (pcre_uchar *)common->name_table;
833        alternative = name;
834        for (i = 0; i < common->name_count; i++)
835          {
836          if (GET2(name, 0) == bracketlen) break;
837          name += common->name_entry_size;
838          }
839        SLJIT_ASSERT(i != common->name_count);
840    
841        for (i = 0; i < common->name_count; i++)
842          {
843          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
844            common->optimized_cbracket[GET2(alternative, 0)] = 0;
845          alternative += common->name_entry_size;
846          }
847        bracketlen = 0;
848        cc += 1 + IMM2_SIZE;
849        break;
850    
851      case OP_BRA:      case OP_BRA:
852      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
853      break;      break;
# Line 906  while (cc < ccend) Line 904  while (cc < ccend)
904    
905      case OP_RECURSE:      case OP_RECURSE:
906      /* Set its value only once. */      /* Set its value only once. */
907      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
908        {        {
909        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
910        common->ovector_start += sizeof(sljit_sw);        common->ovector_start += sizeof(sljit_sw);
911        }        }
912      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
913      break;      break;
914    
915        case OP_CALLOUT:
916        if (common->capture_last_ptr == 0)
917          {
918          common->capture_last_ptr = common->ovector_start;
919          common->ovector_start += sizeof(sljit_sw);
920          }
921        cc += 2 + 2 * LINK_SIZE;
922        break;
923    
924      case OP_MARK:      case OP_MARK:
925      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
926        {        {
# Line 1099  while (cc < ccend) Line 1106  while (cc < ccend)
1106    }    }
1107  }  }
1108    
1109  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1110  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1111  {  {
1112  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1113  int length = 0;  int length = 0;
1114  BOOL possessive = FALSE;  int possessive = 0;
1115    BOOL stack_restore = FALSE;
1116  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1117  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1118    /* The last capture is a local variable even for recursions. */
1119    BOOL capture_last_found = FALSE;
1120    
1121  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1122    {    {
1123    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1124    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1125      capture_last_found = TRUE;
1126    }    }
1127    
1128  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 1121  while (cc < ccend) Line 1132  while (cc < ccend)
1132      {      {
1133      case OP_SET_SOM:      case OP_SET_SOM:
1134      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1135        stack_restore = TRUE;
1136      if (!setsom_found)      if (!setsom_found)
1137        {        {
1138        length += 2;        length += 2;
# Line 1131  while (cc < ccend) Line 1143  while (cc < ccend)
1143    
1144      case OP_MARK:      case OP_MARK:
1145      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1146        stack_restore = TRUE;
1147      if (!setmark_found)      if (!setmark_found)
1148        {        {
1149        length += 2;        length += 2;
# Line 1140  while (cc < ccend) Line 1153  while (cc < ccend)
1153      break;      break;
1154    
1155      case OP_RECURSE:      case OP_RECURSE:
1156        stack_restore = TRUE;
1157      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1158        {        {
1159        length += 2;        length += 2;
# Line 1150  while (cc < ccend) Line 1164  while (cc < ccend)
1164        length += 2;        length += 2;
1165        setmark_found = TRUE;        setmark_found = TRUE;
1166        }        }
1167        if (common->capture_last_ptr != 0 && !capture_last_found)
1168          {
1169          length += 2;
1170          capture_last_found = TRUE;
1171          }
1172      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1173      break;      break;
1174    
# Line 1157  while (cc < ccend) Line 1176  while (cc < ccend)
1176      case OP_CBRAPOS:      case OP_CBRAPOS:
1177      case OP_SCBRA:      case OP_SCBRA:
1178      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1179        stack_restore = TRUE;
1180        if (common->capture_last_ptr != 0 && !capture_last_found)
1181          {
1182          length += 2;
1183          capture_last_found = TRUE;
1184          }
1185      length += 3;      length += 3;
1186      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1187      break;      break;
1188    
1189      default:      default:
1190        stack_restore = TRUE;
1191        /* Fall through. */
1192    
1193        case OP_NOT_WORD_BOUNDARY:
1194        case OP_WORD_BOUNDARY:
1195        case OP_NOT_DIGIT:
1196        case OP_DIGIT:
1197        case OP_NOT_WHITESPACE:
1198        case OP_WHITESPACE:
1199        case OP_NOT_WORDCHAR:
1200        case OP_WORDCHAR:
1201        case OP_ANY:
1202        case OP_ALLANY:
1203        case OP_ANYBYTE:
1204        case OP_NOTPROP:
1205        case OP_PROP:
1206        case OP_ANYNL:
1207        case OP_NOT_HSPACE:
1208        case OP_HSPACE:
1209        case OP_NOT_VSPACE:
1210        case OP_VSPACE:
1211        case OP_EXTUNI:
1212        case OP_EODN:
1213        case OP_EOD:
1214        case OP_CIRC:
1215        case OP_CIRCM:
1216        case OP_DOLL:
1217        case OP_DOLLM:
1218        case OP_CHAR:
1219        case OP_CHARI:
1220        case OP_NOT:
1221        case OP_NOTI:
1222    
1223        case OP_EXACT:
1224        case OP_POSSTAR:
1225        case OP_POSPLUS:
1226        case OP_POSQUERY:
1227        case OP_POSUPTO:
1228    
1229        case OP_EXACTI:
1230        case OP_POSSTARI:
1231        case OP_POSPLUSI:
1232        case OP_POSQUERYI:
1233        case OP_POSUPTOI:
1234    
1235        case OP_NOTEXACT:
1236        case OP_NOTPOSSTAR:
1237        case OP_NOTPOSPLUS:
1238        case OP_NOTPOSQUERY:
1239        case OP_NOTPOSUPTO:
1240    
1241        case OP_NOTEXACTI:
1242        case OP_NOTPOSSTARI:
1243        case OP_NOTPOSPLUSI:
1244        case OP_NOTPOSQUERYI:
1245        case OP_NOTPOSUPTOI:
1246    
1247        case OP_TYPEEXACT:
1248        case OP_TYPEPOSSTAR:
1249        case OP_TYPEPOSPLUS:
1250        case OP_TYPEPOSQUERY:
1251        case OP_TYPEPOSUPTO:
1252    
1253        case OP_CLASS:
1254        case OP_NCLASS:
1255        case OP_XCLASS:
1256    
1257      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1258      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1259      break;      break;
1260      }      }
1261    
1262  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1263  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1264    return -1;    return stack_restore ? no_frame : no_stack;
1265    
1266  if (length > 0)  if (length > 0)
1267    return length + 1;    return length + 1;
1268  return -1;  return stack_restore ? no_frame : no_stack;
1269  }  }
1270    
1271  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, int stackpos, int stacktop, BOOL recursive)
1272  {  {
1273  DEFINE_COMPILER;  DEFINE_COMPILER;
1274  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1275  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1276  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1277    /* The last capture is a local variable even for recursions. */
1278    BOOL capture_last_found = FALSE;
1279  int offset;  int offset;
1280    
1281  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1200  while (cc < ccend) Line 1294  while (cc < ccend)
1294      if (!setsom_found)      if (!setsom_found)
1295        {        {
1296        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1297        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1298        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1299        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1300        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1214  while (cc < ccend) Line 1308  while (cc < ccend)
1308      if (!setmark_found)      if (!setmark_found)
1309        {        {
1310        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);
1311        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);
1312        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1313        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1314        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1227  while (cc < ccend) Line 1321  while (cc < ccend)
1321      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1322        {        {
1323        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1324        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1325        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1326        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1327        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1236  while (cc < ccend) Line 1330  while (cc < ccend)
1330      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1331        {        {
1332        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);
1333        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);
1334        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1335        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1336        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1337        setmark_found = TRUE;        setmark_found = TRUE;
1338        }        }
1339        if (common->capture_last_ptr != 0 && !capture_last_found)
1340          {
1341          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1342          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1343          stackpos += (int)sizeof(sljit_sw);
1344          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1345          stackpos += (int)sizeof(sljit_sw);
1346          capture_last_found = TRUE;
1347          }
1348      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1349      break;      break;
1350    
# Line 1249  while (cc < ccend) Line 1352  while (cc < ccend)
1352      case OP_CBRAPOS:      case OP_CBRAPOS:
1353      case OP_SCBRA:      case OP_SCBRA:
1354      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1355        if (common->capture_last_ptr != 0 && !capture_last_found)
1356          {
1357          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1358          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1359          stackpos += (int)sizeof(sljit_sw);
1360          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1361          stackpos += (int)sizeof(sljit_sw);
1362          capture_last_found = TRUE;
1363          }
1364      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1365      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1366      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
# Line 1268  while (cc < ccend) Line 1380  while (cc < ccend)
1380      break;      break;
1381      }      }
1382    
1383  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1384  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1385  }  }
1386    
# Line 1430  while (status != end) Line 1542  while (status != end)
1542    switch(status)    switch(status)
1543      {      {
1544      case start:      case start:
1545      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1546      count = 1;      count = 1;
1547      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1548      status = loop;      status = loop;
1549      break;      break;
1550    
# Line 1708  while (list) Line 1820  while (list)
1820    {    {
1821    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1822    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1823    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1824    list = list->next;    list = list->next;
1825    }    }
1826  }  }
# Line 1724  if (list_item) Line 1836  if (list_item)
1836    }    }
1837  }  }
1838    
1839  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)
1840  {  {
1841  DEFINE_COMPILER;  DEFINE_COMPILER;
1842  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1843    
1844  if (list_item)  if (list_item)
1845    {    {
   list_item->type = type;  
   list_item->data = data;  
1846    list_item->start = start;    list_item->start = start;
1847    list_item->quit = LABEL();    list_item->quit = LABEL();
1848    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1748  stub_list* list_item = common->stubs; Line 1858  stub_list* list_item = common->stubs;
1858  while (list_item)  while (list_item)
1859    {    {
1860    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1861    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;  
     }  
1862    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
1863    list_item = list_item->next;    list_item = list_item->next;
1864    }    }
# Line 1781  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 1886  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1886  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1887  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1888  #endif  #endif
1889  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));
1890  }  }
1891    
1892  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 copy_ovector(co Line 1923  static SLJIT_INLINE void copy_ovector(co
1923  {  {
1924  DEFINE_COMPILER;  DEFINE_COMPILER;
1925  struct sljit_label *loop;  struct sljit_label *loop;
1926  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
1927    
1928  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
1929  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
# Line 1827  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R Line 1932  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R
1932  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
1933  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
1934    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1935  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));
1936  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
1937    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
1938  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
1939  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
1940  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
1941  /* Unlikely, but possible */  /* Unlikely, but possible */
1942  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
1943  loop = LABEL();  loop = LABEL();
1944  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
1945  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
# Line 1845  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJ Line 1950  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJ
1950  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
1951  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
1952  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
1953  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
1954    
1955  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
1956  if (topbracket > 1)  if (topbracket > 1)
# Line 1867  else Line 1972  else
1972  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)
1973  {  {
1974  DEFINE_COMPILER;  DEFINE_COMPILER;
1975    struct sljit_jump *jump;
1976    
1977  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);
1978  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->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
1979    
1980  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
1981  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
1982  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
1983  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);
1984    
1985  /* Store match begin and end. */  /* Store match begin and end. */
1986  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));
1987  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));
1988    
1989    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
1990    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr + sizeof(sljit_sw), SLJIT_SAVED_REG1, 0);
1991    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1992    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
1993    #endif
1994    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
1995    JUMPHERE(jump);
1996    
1997  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);
1998  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);
1999  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
# Line 2055  else if (common->mode == JIT_PARTIAL_SOF Line 2170  else if (common->mode == JIT_PARTIAL_SOF
2170    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);
2171    
2172  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2173    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);
2174  else  else
2175    {    {
2176    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2068  if (jump != NULL) Line 2183  if (jump != NULL)
2183    JUMPHERE(jump);    JUMPHERE(jump);
2184  }  }
2185    
2186  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2187  {  {
2188  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2189  DEFINE_COMPILER;  DEFINE_COMPILER;
2190  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2191    
2192  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2193    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2194      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2195      return;
2196      }
2197    
2198  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2199  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2200    {    {
2201    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));
2202    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);
2203    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2204    }    }
2205  else  else
2206    {    {
2207    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));
2208    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2209      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2210    else    else
2211      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2212    }    }
2213  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2214  }  }
2215    
2216  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2115  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2229  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2229  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));
2230  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2231    {    {
2232    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);
2233    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2234    }    }
2235  else  else
# Line 2573  DEFINE_COMPILER; Line 2687  DEFINE_COMPILER;
2687  struct sljit_label *start;  struct sljit_label *start;
2688  struct sljit_jump *quit;  struct sljit_jump *quit;
2689  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
2690  pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2691  int location = 0;  int location = 0;
2692  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2693  int must_stop;  int must_stop;
# Line 2696  if (firstline) Line 2810  if (firstline)
2810    {    {
2811    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2812    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2813    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2814    }    }
2815  else  else
2816    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2817    
2818  start = LABEL();  start = LABEL();
2819  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
# Line 2728  JUMPHERE(quit); Line 2842  JUMPHERE(quit);
2842  if (firstline)  if (firstline)
2843    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2844  else  else
2845    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2846  return TRUE;  return TRUE;
2847  }  }
2848    
# Line 2877  if (firstline) Line 2991  if (firstline)
2991    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2992  }  }
2993    
2994    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
2995    
2996  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)
2997  {  {
2998  DEFINE_COMPILER;  DEFINE_COMPILER;
2999  struct sljit_label *start;  struct sljit_label *start;
3000  struct sljit_jump *quit;  struct sljit_jump *quit;
3001  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3002    jump_list *matches = NULL;
3003    pcre_uint8 inverted_start_bits[32];
3004    int i;
3005  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3006  struct sljit_jump *jump;  struct sljit_jump *jump;
3007  #endif  #endif
3008    
3009    for (i = 0; i < 32; ++i)
3010      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3011    
3012  if (firstline)  if (firstline)
3013    {    {
3014    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 2901  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3023  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3023  if (common->utf)  if (common->utf)
3024    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3025  #endif  #endif
3026    
3027    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3028      {
3029  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3030  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3031  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3032  JUMPHERE(jump);    JUMPHERE(jump);
3033  #endif  #endif
3034  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3035  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3036  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3037  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3038  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3039  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3040      }
3041    
3042  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3043  if (common->utf)  if (common->utf)
# Line 2939  if (common->utf) Line 3065  if (common->utf)
3065  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3066  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3067  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3068  JUMPHERE(found);  if (found != NULL)
3069      JUMPHERE(found);
3070    if (matches != NULL)
3071      set_jumps(matches, LABEL());
3072  JUMPHERE(quit);  JUMPHERE(quit);
3073    
3074  if (firstline)  if (firstline)
# Line 3022  GET_LOCAL_BASE(TMP3, 0, 0); Line 3151  GET_LOCAL_BASE(TMP3, 0, 0);
3151  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3152  mainloop = LABEL();  mainloop = LABEL();
3153  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3154  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);
3155    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3156    
3157  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3158  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));
3159  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 3030  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I Line 3161  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I
3161  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3162    
3163  JUMPHERE(jump);  JUMPHERE(jump);
3164  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3165  /* End of dropping frames. */  /* End of dropping frames. */
3166  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3167    
3168  JUMPHERE(jump);  JUMPHERE(jump);
3169  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3170  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3171  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. */  
3172  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));
3173  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3174  }  }
# Line 3063  static void check_wordboundary(compiler_ Line 3177  static void check_wordboundary(compiler_
3177  {  {
3178  DEFINE_COMPILER;  DEFINE_COMPILER;
3179  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3180    jump_list *skipread_list = NULL;
3181  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3182  struct sljit_jump *jump;  struct sljit_jump *jump;
3183  #endif  #endif
# Line 3120  else Line 3235  else
3235  JUMPHERE(skipread);  JUMPHERE(skipread);
3236    
3237  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3238  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3239  peek_char(common);  peek_char(common);
3240    
3241  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3161  else Line 3276  else
3276      JUMPHERE(jump);      JUMPHERE(jump);
3277  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3278    }    }
3279  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3280    
3281  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);
3282  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3481  sljit_emit_fast_return(compiler, RETURN_ Line 3596  sljit_emit_fast_return(compiler, RETURN_
3596    
3597  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3598    
3599  static const pcre_uchar *SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)  static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)
3600  {  {
3601  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3602  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3577  do Line 3692  do
3692  #endif  #endif
3693    
3694    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3695  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3696    
3697    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3698    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3594  do Line 3709  do
3709    
3710  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3711    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
3712  #elif defined COMPILE_PCRE16  #else
3713    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
 #elif defined COMPILE_PCRE32  
   if (1 /* context->ucharptr >= 1 || context->length == 0 */)  
3714  #endif  #endif
3715      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3716      if (context->length >= 4)      if (context->length >= 4)
3717        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 #if defined COMPILE_PCRE8  
3718      else if (context->length >= 2)      else if (context->length >= 2)
3719        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3720    #if defined COMPILE_PCRE8
3721      else if (context->length >= 1)      else if (context->length >= 1)
3722        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3723  #elif defined COMPILE_PCRE16  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif /* COMPILE_PCRE[8|16] */  
 #elif defined COMPILE_PCRE32  
     OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif /* COMPILE_PCRE[8|16|32] */  
3724      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3725    
3726      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3625  do Line 3731  do
3731        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));
3732        break;        break;
3733    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3734        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3735        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3736          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);
# Line 3640  do Line 3745  do
3745        break;        break;
3746  #endif  #endif
3747    
 #endif /* COMPILE_PCRE[8|16] */  
   
3748        default:        default:
3749        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3750        break;        break;
# Line 3651  do Line 3754  do
3754    
3755  #else  #else
3756    
3757    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3758    if (context->length > 0)    if (context->length >= 1)
3759      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3760    
3761    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3813  while (*cc != XCL_END) Line 3916  while (*cc != XCL_END)
3916        break;        break;
3917    
3918        case PT_CLIST:        case PT_CLIST:
3919          case PT_UCNC:
3920        needschar = TRUE;        needschar = TRUE;
3921        break;        break;
3922    
# Line 4014  while (*cc != XCL_END) Line 4118  while (*cc != XCL_END)
4118        case PT_WORD:        case PT_WORD:
4119        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);
4120        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4121        /* ... fall through */        /* Fall through. */
4122    
4123        case PT_ALNUM:        case PT_ALNUM:
4124        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
# Line 4078  while (*cc != XCL_END) Line 4182  while (*cc != XCL_END)
4182          }          }
4183        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4184        break;        break;
4185    
4186          case PT_UCNC:
4187          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4188          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4189          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4190          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4191          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4192          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4193    
4194          SET_CHAR_OFFSET(0xa0);
4195          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4196          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4197          SET_CHAR_OFFSET(0);
4198          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4199          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4200          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4201          break;
4202        }        }
4203      cc += 2;      cc += 2;
4204      }      }
# Line 4103  int length; Line 4224  int length;
4224  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4225  compare_context context;  compare_context context;
4226  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4227    jump_list *end_list;
4228  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4229  struct sljit_label *label;  struct sljit_label *label;
4230  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4171  switch(type) Line 4293  switch(type)
4293    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4294      {      {
4295      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);
4296        end_list = NULL;
4297      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4298        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));
4299      else      else
4300        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4301    
4302      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4303      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));
4304      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4305      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4306      }      }
4307    else    else
# Line 4238  switch(type) Line 4360  switch(type)
4360    read_char(common);    read_char(common);
4361    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);
4362    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4363      end_list = NULL;
4364    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4365      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));
4366    else    else
4367      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4368    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4369    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);
4370    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));
4371    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4372    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4373    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4374      set_jumps(end_list, LABEL());
4375    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4376    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4377    return cc;    return cc;
4378    
4379    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 5001  backtrack_common *backtrack; Line 5124  backtrack_common *backtrack;
5124  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5125  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5126  int start = GET(cc, 1);  int start = GET(cc, 1);
5127    pcre_uchar *start_cc;
5128    
5129  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5130    
5131    /* Inlining simple patterns. */
5132    if (get_framesize(common, common->start + start, TRUE) == no_stack)
5133      {
5134      start_cc = common->start + start;
5135      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5136      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5137      return cc + 1 + LINK_SIZE;
5138      }
5139    
5140  while (entry != NULL)  while (entry != NULL)
5141    {    {
5142    if (entry->start == start)    if (entry->start == start)
# Line 5051  add_jump(compiler, &backtrack->topbacktr Line 5185  add_jump(compiler, &backtrack->topbacktr
5185  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5186  }  }
5187    
5188    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5189    {
5190    const pcre_uchar *begin = arguments->begin;
5191    int *offset_vector = arguments->offsets;
5192    int offset_count = arguments->offset_count;
5193    int i;
5194    
5195    if (PUBL(callout) == NULL)
5196      return 0;
5197    
5198    callout_block->version = 2;
5199    callout_block->callout_data = arguments->callout_data;
5200    
5201    /* Offsets in subject. */
5202    callout_block->subject_length = arguments->end - arguments->begin;
5203    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5204    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5205    #if defined COMPILE_PCRE8
5206    callout_block->subject = (PCRE_SPTR)begin;
5207    #elif defined COMPILE_PCRE16
5208    callout_block->subject = (PCRE_SPTR16)begin;
5209    #elif defined COMPILE_PCRE32
5210    callout_block->subject = (PCRE_SPTR32)begin;
5211    #endif
5212    
5213    /* Convert and copy the JIT offset vector to the offset_vector array. */
5214    callout_block->capture_top = 0;
5215    callout_block->offset_vector = offset_vector;
5216    for (i = 2; i < offset_count; i += 2)
5217      {
5218      offset_vector[i] = jit_ovector[i] - begin;
5219      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5220      if (jit_ovector[i] >= begin)
5221        callout_block->capture_top = i;
5222      }
5223    
5224    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5225    if (offset_count > 0)
5226      offset_vector[0] = -1;
5227    if (offset_count > 1)
5228      offset_vector[1] = -1;
5229    return (*PUBL(callout))(callout_block);
5230    }
5231    
5232    /* Aligning to 8 byte. */
5233    #define CALLOUT_ARG_SIZE \
5234        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5235    
5236    #define CALLOUT_ARG_OFFSET(arg) \
5237        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5238    
5239    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5240    {
5241    DEFINE_COMPILER;
5242    backtrack_common *backtrack;
5243    
5244    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5245    
5246    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5247    
5248    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5249    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5250    SLJIT_ASSERT(common->capture_last_ptr != 0);
5251    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5252    OP1(SLJIT_MOV_UI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5253    
5254    /* These pointer sized fields temporarly stores internal variables. */
5255    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5256    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5257    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5258    
5259    if (common->mark_ptr != 0)
5260      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5261    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5262    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5263    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5264    
5265    /* Needed to save important temporary registers. */
5266    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5267    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5268    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5269    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5270    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5271    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5272    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5273    
5274    /* Check return value. */
5275    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5276    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5277    if (common->forced_quit_label == NULL)
5278      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5279    else
5280      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5281    return cc + 2 + 2 * LINK_SIZE;
5282    }
5283    
5284    #undef CALLOUT_ARG_SIZE
5285    #undef CALLOUT_ARG_OFFSET
5286    
5287  static pcre_uchar *compile_assert_matchingpath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)  static pcre_uchar *compile_assert_matchingpath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)
5288  {  {
5289  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 5064  jump_list *tmp = NULL; Line 5297  jump_list *tmp = NULL;
5297  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5298  jump_list **found;  jump_list **found;
5299  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5300  struct sljit_label *save_quitlabel = common->quitlabel;  struct sljit_label *save_quit_label = common->quit_label;
5301  struct sljit_label *save_acceptlabel = common->acceptlabel;  struct sljit_label *save_accept_label = common->accept_label;
5302  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5303  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5304  struct sljit_jump *jump;  struct sljit_jump *jump;
# Line 5114  else Line 5347  else
5347    }    }
5348    
5349  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5350  common->quitlabel = NULL;  common->quit_label = NULL;
5351  common->quit = NULL;  common->quit = NULL;
5352  while (1)  while (1)
5353    {    {
5354    common->acceptlabel = NULL;    common->accept_label = NULL;
5355    common->accept = NULL;    common->accept = NULL;
5356    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5357    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5130  while (1) Line 5363  while (1)
5363    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5364    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5365      {      {
5366      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
5367      common->acceptlabel = save_acceptlabel;      common->accept_label = save_accept_label;
5368      common->quit = save_quit;      common->quit = save_quit;
5369      common->accept = save_accept;      common->accept = save_accept;
5370      return NULL;      return NULL;
5371      }      }
5372    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5373    if (common->accept != NULL)    if (common->accept != NULL)
5374      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5375    
5376    /* Reset stack. */    /* Reset stack. */
5377    if (framesize < 0)    if (framesize < 0)
# Line 5185  while (1) Line 5418  while (1)
5418    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5419    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5420      {      {
5421      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
5422      common->acceptlabel = save_acceptlabel;      common->accept_label = save_accept_label;
5423      common->quit = save_quit;      common->quit = save_quit;
5424      common->accept = save_accept;      common->accept = save_accept;
5425      return NULL;      return NULL;
# Line 5269  if (opcode == OP_ASSERT || opcode == OP_ Line 5502  if (opcode == OP_ASSERT || opcode == OP_
5502    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5503      {      {
5504      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
5505      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
5506      }      }
5507    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5508      {      {
# Line 5326  else Line 5559  else
5559      }      }
5560    }    }
5561    
5562  common->quitlabel = save_quitlabel;  common->quit_label = save_quit_label;
5563  common->acceptlabel = save_acceptlabel;  common->accept_label = save_accept_label;
5564  common->quit = save_quit;  common->quit = save_quit;
5565  common->accept = save_accept;  common->accept = save_accept;
5566  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
# Line 5709  if (opcode == OP_ONCE) Line 5942  if (opcode == OP_ONCE)
5942  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
5943    {    {
5944    /* Saving the previous values. */    /* Saving the previous values. */
5945    if (common->optimized_cbracket[offset >> 1] == 0)    if (common->optimized_cbracket[offset >> 1] != 0)
     {  
     allocate_stack(common, 3);  
     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(0), TMP1, 0);  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);  
     }  
   else  
5946      {      {
5947      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));
5948      allocate_stack(common, 2);      allocate_stack(common, 2);
# Line 5730  else if (opcode == OP_CBRA || opcode == Line 5952  else if (opcode == OP_CBRA || opcode ==
5952      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
5953      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5954      }      }
5955      else
5956        {
5957        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5958        allocate_stack(common, 1);
5959        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);
5960        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
5961        }
5962    }    }
5963  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
5964    {    {
# Line 5871  if (opcode == OP_ONCE) Line 6100  if (opcode == OP_ONCE)
6100  stacksize = 0;  stacksize = 0;
6101  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6102    stacksize++;    stacksize++;
6103    if (offset != 0)
6104      {
6105      if (common->capture_last_ptr != 0)
6106        stacksize++;
6107      if (common->optimized_cbracket[offset >> 1] == 0)
6108        stacksize += 2;
6109      }
6110  if (has_alternatives && opcode != OP_ONCE)  if (has_alternatives && opcode != OP_ONCE)
6111    stacksize++;    stacksize++;
6112    
# Line 5878  if (stacksize > 0) Line 6114  if (stacksize > 0)
6114    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6115    
6116  stacksize = 0;  stacksize = 0;
6117  if (ket != OP_KET)  if (ket != OP_KET || bra != OP_BRA)
6118    {    {
6119    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);    if (ket != OP_KET)
6120        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6121      else
6122        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6123    stacksize++;    stacksize++;
6124    }    }
6125  else if (bra != OP_BRA)  
6126    if (offset != 0)
6127    {    {
6128    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    if (common->capture_last_ptr != 0)
6129    stacksize++;      {
6130        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6131        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6132        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0);
6133        stacksize++;
6134        }
6135      if (common->optimized_cbracket[offset >> 1] == 0)
6136        {
6137        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6138        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6139        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6140        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6141        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6142        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6143        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6144        stacksize += 2;
6145        }
6146    }    }
6147    
6148  if (has_alternatives)  if (has_alternatives)
# Line 5898  if (has_alternatives) Line 6154  if (has_alternatives)
6154    }    }
6155    
6156  /* Must be after the matchingpath label. */  /* Must be after the matchingpath label. */
6157  if (offset != 0)  if (offset != 0 && common->optimized_cbracket[offset >> 1] != 0)
6158    {    {
6159    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
6160    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);
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 0), TMP1, 0);  
6161    }    }
6162    
6163  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
# Line 6016  framesize = get_framesize(common, cc, FA Line 6271  framesize = get_framesize(common, cc, FA
6271  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6272  if (framesize < 0)  if (framesize < 0)
6273    {    {
6274    stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;    if (offset != 0)
6275        {
6276        stacksize = 2;
6277        if (common->capture_last_ptr != 0)
6278          stacksize++;
6279        }
6280      else
6281        stacksize = 1;
6282    
6283    if (!zero)    if (!zero)
6284      stacksize++;      stacksize++;
6285    
6286    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
6287    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6288    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    if (framesize == no_frame)
6289        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6290    
6291    if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)    if (offset != 0)
6292      {      {
6293      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6294      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));
6295      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6296        if (common->capture_last_ptr != 0)
6297          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6298      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6299        if (common->capture_last_ptr != 0)
6300          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6301      }      }
6302    else    else
6303      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 6044  else Line 6313  else
6313    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)
6314      stacksize++;      stacksize++;
6315    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
   allocate_stack(common, stacksize);  
6316    
6317      allocate_stack(common, stacksize);
6318    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);
6319    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));
6320    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);
6321    
6322    stack = 0;    stack = 0;
6323    if (!zero)    if (!zero)
6324      {      {
# Line 6064  else Line 6334  else
6334    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);
6335    }    }
6336    
6337  if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)  if (offset != 0)
6338    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6339    
6340  loop = LABEL();  loop = LABEL();
# Line 6080  while (*cc != OP_KETRPOS) Line 6350  while (*cc != OP_KETRPOS)
6350    
6351    if (framesize < 0)    if (framesize < 0)
6352      {      {
6353      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      if (framesize == no_frame)
6354          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6355    
6356      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6357        {        {
6358        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6359        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);
6360        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6361          if (common->capture_last_ptr != 0)
6362            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6363        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6364        }        }
6365      else      else
# Line 6104  while (*cc != OP_KETRPOS) Line 6377  while (*cc != OP_KETRPOS)
6377      }      }
6378    else    else
6379      {      {
6380      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6381        {        {
6382        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));
6383        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6384        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);
6385        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6386          if (common->capture_last_ptr != 0)
6387            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6388        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6389        }        }
6390      else      else
# Line 6142  while (*cc != OP_KETRPOS) Line 6417  while (*cc != OP_KETRPOS)
6417    
6418    if (framesize < 0)    if (framesize < 0)
6419      {      {
6420      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6421        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6422      else      else
6423        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6424      }      }
6425    else    else
6426      {      {
6427      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6428        {        {
6429        /* Last alternative. */        /* Last alternative. */
6430        if (*cc == OP_KETRPOS)        if (*cc == OP_KETRPOS)
# Line 6296  PUSH_BACKTRACK(sizeof(iterator_backtrack Line 6571  PUSH_BACKTRACK(sizeof(iterator_backtrack
6571    
6572  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);
6573    
6574  switch (type)  switch(type)
6575    {    {
6576    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
6577    case OP_DIGIT:    case OP_DIGIT:
# Line 6498  static SLJIT_INLINE pcre_uchar *compile_ Line 6773  static SLJIT_INLINE pcre_uchar *compile_
6773  DEFINE_COMPILER;  DEFINE_COMPILER;
6774  backtrack_common *backtrack;  backtrack_common *backtrack;
6775    
6776  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
6777    
6778  if (*cc == OP_FAIL)  if (*cc == OP_FAIL)
6779    {    {
# Line 6509  if (*cc == OP_FAIL) Line 6784  if (*cc == OP_FAIL)
6784  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)
6785    {    {
6786    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
6787    if (common->acceptlabel == NULL)    if (common->accept_label == NULL)
6788      add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));
6789    else    else
6790      JUMPTO(SLJIT_JUMP, common->acceptlabel);      JUMPTO(SLJIT_JUMP, common->accept_label);
6791    return cc + 1;    return cc + 1;
6792    }    }
6793    
6794  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
6795    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)));    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)));
6796  else  else
6797    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), common->acceptlabel);    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), common->accept_label);
6798  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
6799  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));
6800  add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));  add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
6801  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));
6802  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
6803    add_jump(compiler, &common->accept, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, &common->accept, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0));
6804  else  else
6805    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, common->acceptlabel);    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, common->accept_label);
6806  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));
6807  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
6808    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0));    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0));
6809  else  else
6810    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, common->acceptlabel);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, common->accept_label);
6811  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));
6812  return cc + 1;  return cc + 1;
6813  }  }
# Line 6712  while (cc < ccend) Line 6987  while (cc < ccend)
6987      cc = compile_recurse_matchingpath(common, cc, parent);      cc = compile_recurse_matchingpath(common, cc, parent);
6988      break;      break;
6989    
6990        case OP_CALLOUT:
6991        cc = compile_callout_matchingpath(common, cc, parent);
6992        break;
6993    
6994      case OP_ASSERT:      case OP_ASSERT:
6995      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
6996      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 6994  static void compile_recurse_backtracking Line 7273  static void compile_recurse_backtracking
7273  {  {
7274  DEFINE_COMPILER;  DEFINE_COMPILER;
7275    
7276    if (CURRENT_AS(recurse_backtrack)->inlined_pattern)
7277      compile_backtrackingpath(common, current->top);
7278  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
7279    if (CURRENT_AS(recurse_backtrack)->inlined_pattern)
7280      return;
7281    
7282  if (common->has_set_som && common->mark_ptr != 0)  if (common->has_set_som && common->mark_ptr != 0)
7283    {    {
# Line 7160  else if (bra == OP_BRAZERO) Line 7443  else if (bra == OP_BRAZERO)
7443    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);
7444    }    }
7445    
7446    if (offset != 0)
7447      {
7448      if (common->capture_last_ptr != 0)
7449        {
7450        SLJIT_ASSERT(common->optimized_cbracket[offset >> 1] == 0);
7451        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7452        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7453        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);
7454        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
7455        free_stack(common, 3);
7456        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP2, 0);
7457        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
7458        }
7459      else if (common->optimized_cbracket[offset >> 1] == 0)
7460        {
7461        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7462        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7463        free_stack(common, 2);
7464        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
7465        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);
7466        }
7467      }
7468    
7469  if (SLJIT_UNLIKELY(opcode == OP_ONCE))  if (SLJIT_UNLIKELY(opcode == OP_ONCE))
7470    {    {
7471    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
# Line 7299  if (has_alternatives) Line 7605  if (has_alternatives)
7605        }        }
7606    
7607      stacksize = 0;      stacksize = 0;
     if (opcode != OP_ONCE)  
       stacksize++;  
7608      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
7609        stacksize++;        stacksize++;
7610        if (offset != 0)
7611          {
7612          if (common->capture_last_ptr != 0)
7613            stacksize++;
7614          if (common->optimized_cbracket[offset >> 1] == 0)
7615            stacksize += 2;
7616          }
7617        if (opcode != OP_ONCE)
7618          stacksize++;
7619    
7620      if (stacksize > 0) {      if (stacksize > 0) {
7621        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
# Line 7325  if (has_alternatives) Line 7638  if (has_alternatives)
7638        stacksize++;        stacksize++;
7639        }        }
7640    
7641        if (offset != 0)
7642          {
7643          if (common->capture_last_ptr != 0)
7644            {
7645            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
7646            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
7647            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
7648            stacksize++;
7649            }
7650          if (common->optimized_cbracket[offset >> 1] == 0)
7651            {
7652            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
7653            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
7654            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
7655            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
7656            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
7657            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
7658            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
7659            stacksize += 2;
7660            }
7661          }
7662    
7663      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
7664        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);
7665    
7666      if (offset != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
7667        {        {
7668        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        /* If ket is not OP_KETRMAX, this code path is executed after the jump to alternative_matchingpath. */
7669          SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
7670        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);
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 0), TMP1, 0);  
7671        }        }
7672    
7673      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath);
# Line 7374  if (has_alternatives) Line 7709  if (has_alternatives)
7709  if (offset != 0)  if (offset != 0)
7710    {    {
7711    /* Using both tmp register is better for instruction scheduling. */    /* Using both tmp register is better for instruction scheduling. */
7712    if (common->optimized_cbracket[offset >> 1] == 0)    if (common->optimized_cbracket[offset >> 1] != 0)
7713      {      {
7714      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7715      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7716        free_stack(common, 2);
7717      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));  
     free_stack(common, 3);  
7718      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);
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);  
7719      }      }
7720    else    else
7721      {      {
7722      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7723      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      free_stack(common, 1);
7724      free_stack(common, 2);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);  
7725      }      }
7726    }    }
7727  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
# Line 7477  if (CURRENT_AS(bracketpos_backtrack)->fr Line 7808  if (CURRENT_AS(bracketpos_backtrack)->fr
7808      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7809      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7810      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
7811        if (common->capture_last_ptr != 0)
7812          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
7813      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);
7814        if (common->capture_last_ptr != 0)
7815          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);
7816      }      }
7817    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7818    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);
# Line 7665  while (current) Line 8000  while (current)
8000    
8001      case OP_COMMIT:      case OP_COMMIT:
8002      OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);      OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
8003      if (common->quitlabel == NULL)      if (common->quit_label == NULL)
8004        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8005      else      else
8006        JUMPTO(SLJIT_JUMP, common->quitlabel);        JUMPTO(SLJIT_JUMP, common->quit_label);
8007      break;      break;
8008    
8009        case OP_CALLOUT:
8010      case OP_FAIL:      case OP_FAIL:
8011      case OP_ACCEPT:      case OP_ACCEPT:
8012      case OP_ASSERT_ACCEPT:      case OP_ASSERT_ACCEPT:
# Line 7696  int framesize = get_framesize(common, cc Line 8032  int framesize = get_framesize(common, cc
8032  int alternativesize;  int alternativesize;
8033  BOOL needsframe;  BOOL needsframe;
8034  backtrack_common altbacktrack;  backtrack_common altbacktrack;
8035  struct sljit_label *save_quitlabel = common->quitlabel;  struct sljit_label *save_quit_label = common->quit_label;
8036  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
8037  struct sljit_jump *jump;  struct sljit_jump *jump;
8038    
# Line 7706  if (!needsframe) Line 8042  if (!needsframe)
8042    framesize = 0;    framesize = 0;
8043  alternativesize = *(cc + GET(cc, 1)) == OP_ALT ? 1 : 0;  alternativesize = *(cc + GET(cc, 1)) == OP_ALT ? 1 : 0;
8044    
8045  SLJIT_ASSERT(common->currententry->entry == NULL && common->recursive_head != 0);  SLJIT_ASSERT(common->currententry->entry == NULL && common->recursive_head_ptr != 0);
8046  common->currententry->entry = LABEL();  common->currententry->entry = LABEL();
8047  set_jumps(common->currententry->calls, common->currententry->entry);  set_jumps(common->currententry->calls, common->currententry->entry);
8048    
# Line 7714  sljit_emit_fast_enter(compiler, TMP2, 0) Line 8050  sljit_emit_fast_enter(compiler, TMP2, 0)
8050  allocate_stack(common, private_data_size + framesize + alternativesize);  allocate_stack(common, private_data_size + framesize + alternativesize);
8051  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);
8052  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);
8053  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head, STACK_TOP, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, STACK_TOP, 0);
8054  if (needsframe)  if (needsframe)
8055    init_frame(common, cc, framesize + alternativesize - 1, alternativesize, TRUE);    init_frame(common, cc, framesize + alternativesize - 1, alternativesize, TRUE);
8056    
# Line 7722  if (alternativesize > 0) Line 8058  if (alternativesize > 0)
8058    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
8059    
8060  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
8061  common->quitlabel = NULL;  common->quit_label = NULL;
8062  common->acceptlabel = NULL;  common->accept_label = NULL;
8063  common->quit = NULL;  common->quit = NULL;
8064  common->accept = NULL;  common->accept = NULL;
8065  altbacktrack.cc = ccbegin;  altbacktrack.cc = ccbegin;
# Line 7739  while (1) Line 8075  while (1)
8075    compile_matchingpath(common, altbacktrack.cc, cc, &altbacktrack);    compile_matchingpath(common, altbacktrack.cc, cc, &altbacktrack);
8076    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
8077      {      {
8078      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
8079      common->quit = save_quit;      common->quit = save_quit;
8080      return;      return;
8081      }      }
# Line 7749  while (1) Line 8085  while (1)
8085    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
8086    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
8087      {      {
8088      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
8089      common->quit = save_quit;      common->quit = save_quit;
8090      return;      return;
8091      }      }
# Line 7769  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0); Line 8105  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0);
8105  jump = JUMP(SLJIT_JUMP);  jump = JUMP(SLJIT_JUMP);
8106    
8107  set_jumps(common->accept, LABEL());  set_jumps(common->accept, LABEL());
8108  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head);  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr);
8109  if (needsframe)  if (needsframe)
8110    {    {
8111    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));
# Line 7783  copy_private_data(common, ccbegin, ccend Line 8119  copy_private_data(common, ccbegin, ccend
8119  free_stack(common, private_data_size + framesize + alternativesize);  free_stack(common, private_data_size + framesize + alternativesize);
8120  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));
8121  OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);  OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
8122  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head, TMP2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, TMP2, 0);
8123  sljit_emit_fast_return(compiler, SLJIT_MEM1(STACK_TOP), 0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(STACK_TOP), 0);
8124    
8125  common->quitlabel = save_quitlabel;  common->quit_label = save_quit_label;
8126  common->quit = save_quit;  common->quit = save_quit;
8127  }  }
8128    
# Line 7811  struct sljit_label *mainloop = NULL; Line 8147  struct sljit_label *mainloop = NULL;
8147  struct sljit_label *empty_match_found;  struct sljit_label *empty_match_found;
8148  struct sljit_label *empty_match_backtrack;  struct sljit_label *empty_match_backtrack;
8149  struct sljit_jump *jump;  struct sljit_jump *jump;
8150    struct sljit_jump *minlength_check_failed = NULL;
8151  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
8152  struct sljit_jump *empty_match;  struct sljit_jump *empty_match;
8153    
# Line 7881  common->ovector_start = CALL_LIMIT + siz Line 8218  common->ovector_start = CALL_LIMIT + siz
8218  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);
8219  if (!common->optimized_cbracket)  if (!common->optimized_cbracket)
8220    return;    return;
8221    #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 1
8222    memset(common->optimized_cbracket, 0, re->top_bracket + 1);
8223    #else
8224  memset(common->optimized_cbracket, 1, re->top_bracket + 1);  memset(common->optimized_cbracket, 1, re->top_bracket + 1);
8225    #endif
8226    
8227  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
8228    #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2
8229    common->capture_last_ptr = common->ovector_start;
8230    common->ovector_start += sizeof(sljit_sw);
8231    #endif
8232  private_data_size = get_private_data_length(common, rootbacktrack.cc, ccend);  private_data_size = get_private_data_length(common, rootbacktrack.cc, ccend);
8233  if (private_data_size < 0)  if (private_data_size < 0)
8234    {    {
# Line 7900  if (mode == JIT_COMPILE && (re->flags & Line 8245  if (mode == JIT_COMPILE && (re->flags &
8245  if (mode != JIT_COMPILE)  if (mode != JIT_COMPILE)
8246    {    {
8247    common->start_used_ptr = common->ovector_start;    common->start_used_ptr = common->ovector_start;
8248    common->ovector_start += sizeof(sljit_sw);    common->ovector_start += 2 * sizeof(sljit_sw);
8249    if (mode == JIT_PARTIAL_SOFT_COMPILE)    if (mode == JIT_PARTIAL_SOFT_COMPILE)
8250      {      {
8251      common->hit_start = common->ovector_start;      common->hit_start = common->ovector_start;
# Line 7917  if ((re->options & PCRE_FIRSTLINE) != 0) Line 8262  if ((re->options & PCRE_FIRSTLINE) != 0)
8262  if ((common->ovector_start & sizeof(sljit_sw)) != 0)  if ((common->ovector_start & sizeof(sljit_sw)) != 0)
8263    common->ovector_start += sizeof(sljit_sw);    common->ovector_start += sizeof(sljit_sw);
8264    
8265    /* Capturing brackets cannot be optimized if callouts are allowed. */
8266    if (common->capture_last_ptr != 0)
8267      memset(common->optimized_cbracket, 0, re->top_bracket + 1);
8268    
8269  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
8270  common->cbraptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);  common->cbraptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);
8271  private_data_size += common->cbraptr + (re->top_bracket + 1) * sizeof(sljit_sw);  private_data_size += common->cbraptr + (re->top_bracket + 1) * sizeof(sljit_sw);
# Line 7956  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1 Line 8305  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1
8305  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
8306  OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end));  OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end));
8307  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack));
8308  OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, calllimit));  OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, call_limit));
8309  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base));
8310  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit));  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit));
8311  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);
8312    
8313  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8314    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);
8315    
8316  /* Main part of the matching */  /* Main part of the matching */
8317  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
# Line 7981  if ((re->options & PCRE_ANCHORED) == 0) Line 8330  if ((re->options & PCRE_ANCHORED) == 0)
8330        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);
8331      }      }
8332    }    }
8333    if (mode == JIT_COMPILE && study->minlength > 0 && (re->options & PCRE_NO_START_OPTIMIZE) == 0)
8334      {
8335      OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
8336      OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(study->minlength));
8337      minlength_check_failed = CMP(SLJIT_C_GREATER, TMP2, 0, STR_END, 0);
8338      }
8339  if (common->req_char_ptr != 0)  if (common->req_char_ptr != 0)
8340    reqbyte_notfound = search_requested_char(common, (pcre_uchar)re->req_char, (re->flags & PCRE_RCH_CASELESS) != 0, (re->flags & PCRE_FIRSTSET) != 0);    reqbyte_notfound = search_requested_char(common, (pcre_uchar)re->req_char, (re->flags & PCRE_RCH_CASELESS) != 0, (re->flags & PCRE_FIRSTSET) != 0);
8341    
# Line 7990  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R Line 8345  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R
8345  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);
8346  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
8347    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
8348    if (common->capture_last_ptr != 0)
8349      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, -1);
8350  /* Copy the beginning of the string. */  /* Copy the beginning of the string. */
8351  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8352    {    {
8353    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);
8354    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);
8355      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr + sizeof(sljit_sw), STR_PTR, 0);
8356    JUMPHERE(jump);    JUMPHERE(jump);
8357    }    }
8358  else if (mode == JIT_PARTIAL_HARD_COMPILE)  else if (mode == JIT_PARTIAL_HARD_COMPILE)
8359      {
8360    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);
8361      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr + sizeof(sljit_sw), STR_PTR, 0);
8362      }
8363    
8364  compile_matchingpath(common, rootbacktrack.cc, ccend, &rootbacktrack);  compile_matchingpath(common, rootbacktrack.cc, ccend, &rootbacktrack);
8365  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
# Line 8012  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 8373  if (SLJIT_UNLIKELY(sljit_get_compiler_er
8373  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));
8374  empty_match_found = LABEL();  empty_match_found = LABEL();
8375    
8376  common->acceptlabel = LABEL();  common->accept_label = LABEL();
8377  if (common->accept != NULL)  if (common->accept != NULL)
8378    set_jumps(common->accept, common->acceptlabel);    set_jumps(common->accept, common->accept_label);
8379    
8380  /* This means we have a match. Update the ovector. */  /* This means we have a match. Update the ovector. */
8381  copy_ovector(common, re->top_bracket + 1);  copy_ovector(common, re->top_bracket + 1);
8382  common->quitlabel = LABEL();  common->quit_label = common->forced_quit_label = LABEL();
8383  if (common->quit != NULL)  if (common->quit != NULL)
8384    set_jumps(common->quit, common->quitlabel);    set_jumps(common->quit, common->quit_label);
8385    if (common->forced_quit != NULL)
8386      set_jumps(common->forced_quit, common->forced_quit_label);
8387    if (minlength_check_failed != NULL)
8388      SET_LABEL(minlength_check_failed, common->forced_quit_label);
8389  sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);  sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
8390    
8391  if (mode != JIT_COMPILE)  if (mode != JIT_COMPILE)
8392    {    {
8393    common->partialmatchlabel = LABEL();    common->partialmatchlabel = LABEL();
8394    set_jumps(common->partialmatch, common->partialmatchlabel);    set_jumps(common->partialmatch, common->partialmatchlabel);
8395    return_with_partial_match(common, common->quitlabel);    return_with_partial_match(common, common->quit_label);
8396    }    }
8397    
8398  empty_match_backtrack = LABEL();  empty_match_backtrack = LABEL();
# Line 8045  SLJIT_ASSERT(rootbacktrack.prev == NULL) Line 8410  SLJIT_ASSERT(rootbacktrack.prev == NULL)
8410  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8411    {    {
8412    /* Update hit_start only in the first time. */    /* Update hit_start only in the first time. */
8413    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);
8414    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);
8415    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);
8416    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 8053  if (mode == JIT_PARTIAL_SOFT_COMPILE) Line 8418  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8418    }    }
8419    
8420  /* Check we have remaining characters. */  /* Check we have remaining characters. */
8421    if ((re->options & PCRE_ANCHORED) == 0 && (re->options & PCRE_FIRSTLINE) != 0)
8422      {
8423      SLJIT_ASSERT(common->first_line_end != 0);
8424      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
8425      }
8426  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
8427    
8428  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
8429    {    {
8430    if ((re->options & PCRE_FIRSTLINE) == 0)    if ((re->options & PCRE_FIRSTLINE) == 0)
8431      {      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
     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);  
     }  
8432    else    else
8433      {      CMPTO(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0, mainloop);
     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);  
     }  
8434    }    }
8435    
8436  /* No more remaining characters. */  /* No more remaining characters. */
# Line 8089  if (reqbyte_notfound != NULL) Line 8438  if (reqbyte_notfound != NULL)
8438    JUMPHERE(reqbyte_notfound);    JUMPHERE(reqbyte_notfound);
8439    
8440  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8441    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);
8442    
8443  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
8444  JUMPTO(SLJIT_JUMP, common->quitlabel);  JUMPTO(SLJIT_JUMP, common->quit_label);
8445    
8446  flush_stubs(common);  flush_stubs(common);
8447    
# Line 8146  sljit_emit_fast_return(compiler, SLJIT_M Line 8495  sljit_emit_fast_return(compiler, SLJIT_M
8495  JUMPHERE(jump);  JUMPHERE(jump);
8496  /* We break the return address cache here, but this is a really rare case. */  /* We break the return address cache here, but this is a really rare case. */
8497  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_JIT_STACKLIMIT);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_JIT_STACKLIMIT);
8498  JUMPTO(SLJIT_JUMP, common->quitlabel);  JUMPTO(SLJIT_JUMP, common->quit_label);
8499    
8500  /* Call limit reached. */  /* Call limit reached. */
8501  set_jumps(common->calllimit, LABEL());  set_jumps(common->calllimit, LABEL());
8502  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_MATCHLIMIT);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_MATCHLIMIT);
8503  JUMPTO(SLJIT_JUMP, common->quitlabel);  JUMPTO(SLJIT_JUMP, common->quit_label);
8504    
8505  if (common->revertframes != NULL)  if (common->revertframes != NULL)
8506    {    {
# Line 8272  return convert_executable_func.call_exec Line 8621  return convert_executable_func.call_exec
8621    
8622  int  int
8623  PRIV(jit_exec)(const PUBL(extra) *extra_data, const pcre_uchar *subject,  PRIV(jit_exec)(const PUBL(extra) *extra_data, const pcre_uchar *subject,
8624    int length, int start_offset, int options, int *offsets, int offsetcount)    int length, int start_offset, int options, int *offsets, int offset_count)
8625  {  {
8626  executable_functions *functions = (executable_functions *)extra_data->executable_jit;  executable_functions *functions = (executable_functions *)extra_data->executable_jit;
8627  union {  union {
# Line 8280  union { Line 8629  union {
8629     jit_function call_executable_func;     jit_function call_executable_func;
8630  } convert_executable_func;  } convert_executable_func;
8631  jit_arguments arguments;  jit_arguments arguments;
8632  int maxoffsetcount;  int max_offset_count;
8633  int retval;  int retval;
8634  int mode = JIT_COMPILE;  int mode = JIT_COMPILE;
8635    
# Line 8298  arguments.begin = subject; Line 8647  arguments.begin = subject;
8647  arguments.end = subject + length;  arguments.end = subject + length;
8648  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
8649  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
8650  arguments.calllimit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;  arguments.call_limit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;
8651  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
8652  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
8653  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
8654  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
8655  arguments.offsets = offsets;  arguments.offsets = offsets;
8656    arguments.callout_data = (extra_data->flags & PCRE_EXTRA_CALLOUT_DATA) != 0 ? extra_data->callout_data : NULL;
8657    arguments.real_offset_count = offset_count;
8658    
8659  /* pcre_exec() rounds offsetcount 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
8660  the output vector for storing captured strings, with the remainder used as  the output vector for storing captured strings, with the remainder used as
8661  workspace. We don't need the workspace here. For compatibility, we limit the  workspace. We don't need the workspace here. For compatibility, we limit the
8662  number of captured strings in the same way as pcre_exec(), so that the user  number of captured strings in the same way as pcre_exec(), so that the user
8663  gets the same result with and without JIT. */  gets the same result with and without JIT. */
8664    
8665  if (offsetcount != 2)  if (offset_count != 2)
8666    offsetcount = ((offsetcount - (offsetcount % 3)) * 2) / 3;    offset_count = ((offset_count - (offset_count % 3)) * 2) / 3;
8667  maxoffsetcount = functions->top_bracket;  max_offset_count = functions->top_bracket;
8668  if (offsetcount > maxoffsetcount)  if (offset_count > max_offset_count)
8669    offsetcount = maxoffsetcount;    offset_count = max_offset_count;
8670  arguments.offsetcount = offsetcount;  arguments.offset_count = offset_count;
8671    
8672  if (functions->callback)  if (functions->callback)
8673    arguments.stack = (struct sljit_stack *)functions->callback(functions->userdata);    arguments.stack = (struct sljit_stack *)functions->callback(functions->userdata);
# Line 8331  else Line 8682  else
8682    retval = convert_executable_func.call_executable_func(&arguments);    retval = convert_executable_func.call_executable_func(&arguments);
8683    }    }
8684    
8685  if (retval * 2 > offsetcount)  if (retval * 2 > offset_count)
8686    retval = 0;    retval = 0;
8687  if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)  if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)
8688    *(extra_data->mark) = arguments.mark_ptr;    *(extra_data->mark) = arguments.mark_ptr;
# Line 8343  return retval; Line 8694  return retval;
8694  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
8695  pcre_jit_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_jit_exec(const pcre *argument_re, const pcre_extra *extra_data,
8696    PCRE_SPTR subject, int length, int start_offset, int options,    PCRE_SPTR subject, int length, int start_offset, int options,
8697    int *offsets, int offsetcount, pcre_jit_stack *stack)    int *offsets, int offset_count, pcre_jit_stack *stack)
8698  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
8699  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
8700  pcre16_jit_exec(const pcre16 *argument_re, const pcre16_extra *extra_data,  pcre16_jit_exec(const pcre16 *argument_re, const pcre16_extra *extra_data,
8701    PCRE_SPTR16 subject, int length, int start_offset, int options,    PCRE_SPTR16 subject, int length, int start_offset, int options,
8702    int *offsets, int offsetcount, pcre16_jit_stack *stack)    int *offsets, int offset_count, pcre16_jit_stack *stack)
8703  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
8704  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
8705  pcre32_jit_exec(const pcre32 *argument_re, const pcre32_extra *extra_data,  pcre32_jit_exec(const pcre32 *argument_re, const pcre32_extra *extra_data,
8706    PCRE_SPTR32 subject, int length, int start_offset, int options,    PCRE_SPTR32 subject, int length, int start_offset, int options,
8707    int *offsets, int offsetcount, pcre32_jit_stack *stack)    int *offsets, int offset_count, pcre32_jit_stack *stack)
8708  #endif  #endif
8709  {  {
8710  pcre_uchar *subject_ptr = (pcre_uchar *)subject;  pcre_uchar *subject_ptr = (pcre_uchar *)subject;
# Line 8363  union { Line 8714  union {
8714     jit_function call_executable_func;     jit_function call_executable_func;
8715  } convert_executable_func;  } convert_executable_func;
8716  jit_arguments arguments;  jit_arguments arguments;
8717  int maxoffsetcount;  int max_offset_count;
8718  int retval;  int retval;
8719  int mode = JIT_COMPILE;  int mode = JIT_COMPILE;
8720    
# Line 8387  arguments.begin = subject_ptr; Line 8738  arguments.begin = subject_ptr;
8738  arguments.end = subject_ptr + length;  arguments.end = subject_ptr + length;
8739  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
8740  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
8741  arguments.calllimit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;  arguments.call_limit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;
8742  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
8743  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
8744  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
8745  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
8746  arguments.offsets = offsets;  arguments.offsets = offsets;
8747    arguments.callout_data = (extra_data->flags & PCRE_EXTRA_CALLOUT_DATA) != 0 ? extra_data->callout_data : NULL;
8748    arguments.real_offset_count = offset_count;
8749    
8750  /* pcre_exec() rounds offsetcount 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
8751  the output vector for storing captured strings, with the remainder used as  the output vector for storing captured strings, with the remainder used as
8752  workspace. We don't need the workspace here. For compatibility, we limit the  workspace. We don't need the workspace here. For compatibility, we limit the
8753  number of captured strings in the same way as pcre_exec(), so that the user  number of captured strings in the same way as pcre_exec(), so that the user
8754  gets the same result with and without JIT. */  gets the same result with and without JIT. */
8755    
8756  if (offsetcount != 2)  if (offset_count != 2)
8757    offsetcount = ((offsetcount - (offsetcount % 3)) * 2) / 3;    offset_count = ((offset_count - (offset_count % 3)) * 2) / 3;
8758  maxoffsetcount = functions->top_bracket;  max_offset_count = functions->top_bracket;
8759  if (offsetcount > maxoffsetcount)  if (offset_count > max_offset_count)
8760    offsetcount = maxoffsetcount;    offset_count = max_offset_count;
8761  arguments.offsetcount = offsetcount;  arguments.offset_count = offset_count;
8762    
8763  convert_executable_func.executable_func = functions->executable_funcs[mode];  convert_executable_func.executable_func = functions->executable_funcs[mode];
8764  retval = convert_executable_func.call_executable_func(&arguments);  retval = convert_executable_func.call_executable_func(&arguments);
8765    
8766  if (retval * 2 > offsetcount)  if (retval * 2 > offset_count)
8767    retval = 0;    retval = 0;
8768  if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)  if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)
8769    *(extra_data->mark) = arguments.mark_ptr;    *(extra_data->mark) = arguments.mark_ptr;

Legend:
Removed from v.1221  
changed lines
  Added in v.1269

  ViewVC Help
Powered by ViewVC 1.1.5