/[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 1426 by zherczeg, Wed Jan 1 13:14:19 2014 UTC revision 1452 by zherczeg, Tue Jan 28 16:07:52 2014 UTC
# Line 179  typedef struct jit_arguments { Line 179  typedef struct jit_arguments {
179    
180  typedef struct executable_functions {  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182      sljit_uw *read_only_data[JIT_NUMBER_OF_COMPILE_MODES];
183      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
184    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
185    void *userdata;    void *userdata;
186    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
187    pcre_uint32 limit_match;    pcre_uint32 limit_match;
   sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];  
188  } executable_functions;  } executable_functions;
189    
190  typedef struct jump_list {  typedef struct jump_list {
# Line 197  typedef struct stub_list { Line 198  typedef struct stub_list {
198    struct stub_list *next;    struct stub_list *next;
199  } stub_list;  } stub_list;
200    
201    typedef struct label_addr_list {
202      struct sljit_label *label;
203      sljit_uw *addr;
204      struct label_addr_list *next;
205    } label_addr_list;
206    
207  enum frame_types {  enum frame_types {
208    no_frame = -1,    no_frame = -1,
209    no_stack = -2    no_stack = -2
# Line 315  typedef struct compiler_common { Line 322  typedef struct compiler_common {
322    pcre_uchar *start;    pcre_uchar *start;
323    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
324    sljit_si *private_data_ptrs;    sljit_si *private_data_ptrs;
325      /* This read-only data is available during runtime. */
326      sljit_uw *read_only_data;
327      /* The total size of the read-only data. */
328      sljit_uw read_only_data_size;
329      /* The next free entry of the read_only_data. */
330      sljit_uw *read_only_data_ptr;
331    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
332    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
333    /* Tells whether the starting offset is a target of then. */    /* Tells whether the starting offset is a target of then. */
# Line 349  typedef struct compiler_common { Line 362  typedef struct compiler_common {
362    sljit_sw lcc;    sljit_sw lcc;
363    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
364    int mode;    int mode;
365      /* TRUE, when minlength is greater than 0. */
366      BOOL might_be_empty;
367    /* \K is found in the pattern. */    /* \K is found in the pattern. */
368    BOOL has_set_som;    BOOL has_set_som;
369    /* (*SKIP:arg) is found in the pattern. */    /* (*SKIP:arg) is found in the pattern. */
# Line 383  typedef struct compiler_common { Line 398  typedef struct compiler_common {
398    struct sljit_label *quit_label;    struct sljit_label *quit_label;
399    struct sljit_label *forced_quit_label;    struct sljit_label *forced_quit_label;
400    struct sljit_label *accept_label;    struct sljit_label *accept_label;
401      struct sljit_label *ff_newline_shortcut;
402    stub_list *stubs;    stub_list *stubs;
403      label_addr_list *label_addrs;
404    recurse_entry *entries;    recurse_entry *entries;
405    recurse_entry *currententry;    recurse_entry *currententry;
406    jump_list *partialmatch;    jump_list *partialmatch;
# Line 537  cc += 1 + LINK_SIZE; Line 554  cc += 1 + LINK_SIZE;
554  return cc;  return cc;
555  }  }
556    
557    static int no_alternatives(pcre_uchar* cc)
558    {
559    int count = 0;
560    SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
561    do
562      {
563      cc += GET(cc, 1);
564      count++;
565      }
566    while (*cc == OP_ALT);
567    SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS);
568    return count;
569    }
570    
571  static int ones_in_half_byte[16] = {  static int ones_in_half_byte[16] = {
572    /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,    /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
573    /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4    /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
# Line 761  while (cc < ccend) Line 792  while (cc < ccend)
792      {      {
793      case OP_SET_SOM:      case OP_SET_SOM:
794      common->has_set_som = TRUE;      common->has_set_som = TRUE;
795        common->might_be_empty = TRUE;
796      cc += 1;      cc += 1;
797      break;      break;
798    
# Line 770  while (cc < ccend) Line 802  while (cc < ccend)
802      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
803      break;      break;
804    
805        case OP_BRA:
806        case OP_CBRA:
807        case OP_SBRA:
808        case OP_SCBRA:
809        count = no_alternatives(cc);
810        if (count > 4)
811          common->read_only_data_size += count * sizeof(sljit_uw);
812        cc += 1 + LINK_SIZE + (*cc == OP_CBRA || *cc == OP_SCBRA ? IMM2_SIZE : 0);
813        break;
814    
815      case OP_CBRAPOS:      case OP_CBRAPOS:
816      case OP_SCBRAPOS:      case OP_SCBRAPOS:
817      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
# Line 2028  while (list_item) Line 2070  while (list_item)
2070  common->stubs = NULL;  common->stubs = NULL;
2071  }  }
2072    
2073    static void add_label_addr(compiler_common *common)
2074    {
2075    DEFINE_COMPILER;
2076    label_addr_list *label_addr;
2077    
2078    label_addr = sljit_alloc_memory(compiler, sizeof(label_addr_list));
2079    if (label_addr == NULL)
2080      return;
2081    label_addr->label = LABEL();
2082    label_addr->addr = common->read_only_data_ptr;
2083    label_addr->next = common->label_addrs;
2084    common->label_addrs = label_addr;
2085    common->read_only_data_ptr++;
2086    }
2087    
2088  static SLJIT_INLINE void count_match(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2089  {  {
2090  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2511  if (common->utf) Line 2568  if (common->utf)
2568    
2569  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2570    
2571  static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)  static BOOL is_char7_bitset(const pcre_uint8 *bitset, BOOL nclass)
2572  {  {
2573  /* Tells whether the character codes below 128 are enough  /* Tells whether the character codes below 128 are enough
2574  to determine a match. */  to determine a match. */
# Line 2563  DEFINE_COMPILER; Line 2620  DEFINE_COMPILER;
2620  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2621  struct sljit_jump *jump;  struct sljit_jump *jump;
2622  #endif  #endif
2623    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2624    struct sljit_jump *jump2;
2625    #endif
2626    
2627  SLJIT_UNUSED_ARG(update_str_ptr);  SLJIT_UNUSED_ARG(update_str_ptr);
2628  SLJIT_UNUSED_ARG(min);  SLJIT_UNUSED_ARG(min);
2629  SLJIT_UNUSED_ARG(max);  SLJIT_UNUSED_ARG(max);
2630  SLJIT_ASSERT(min <= max);  SLJIT_ASSERT(min <= max);
2631    
2632  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2633  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));
2634    
2635  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
# Line 2578  if (common->utf) Line 2638  if (common->utf)
2638    if (max < 128 && !update_str_ptr) return;    if (max < 128 && !update_str_ptr) return;
2639    
2640    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2641    if (max >= 0x800)    if (min >= 0x10000)
2642        {
2643        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2644        if (update_str_ptr)
2645          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2646        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2647        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2648        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2649        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2650        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2651        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2652        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2653        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2654        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2655        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2656        if (!update_str_ptr)
2657          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2658        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2659        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2660        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2661        JUMPHERE(jump2);
2662        if (update_str_ptr)
2663          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2664        }
2665      else if (min >= 0x800 && max <= 0xffff)
2666        {
2667        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2668        if (update_str_ptr)
2669          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2670        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2671        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2672        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2673        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2674        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2675        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2676        if (!update_str_ptr)
2677          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2678        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2679        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2680        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2681        JUMPHERE(jump2);
2682        if (update_str_ptr)
2683          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2684        }
2685      else if (max >= 0x800)
2686      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2687    else if (max < 128)    else if (max < 128)
2688      {      {
# Line 3046  if (newlinecheck) Line 3150  if (newlinecheck)
3150  return mainloop;  return mainloop;
3151  }  }
3152    
3153  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)  #define MAX_N_CHARS 16
3154    #define MAX_N_BYTES 8
3155    
3156    static SLJIT_INLINE void add_prefix_byte(pcre_uint8 byte, pcre_uint8 *bytes)
3157    {
3158    pcre_uint8 len = bytes[0];
3159    int i;
3160    
3161    if (len == 255)
3162      return;
3163    
3164    if (len == 0)
3165      {
3166      bytes[0] = 1;
3167      bytes[1] = byte;
3168      return;
3169      }
3170    
3171    for (i = len; i > 0; i--)
3172      if (bytes[i] == byte)
3173        return;
3174    
3175    if (len >= MAX_N_BYTES - 1)
3176      {
3177      bytes[0] = 255;
3178      return;
3179      }
3180    
3181    len++;
3182    bytes[len] = byte;
3183    bytes[0] = len;
3184    }
3185    
3186    static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, pcre_uint8 *bytes, int max_chars)
3187  {  {
3188  /* Recursive function, which scans prefix literals. */  /* Recursive function, which scans prefix literals. */
3189    BOOL last, any, caseless;
3190  int len, repeat, len_save, consumed = 0;  int len, repeat, len_save, consumed = 0;
3191  pcre_uint32 caseless, chr, mask;  pcre_uint32 chr, mask;
3192  pcre_uchar *alternative, *cc_save;  pcre_uchar *alternative, *cc_save, *oc;
3193  BOOL last, any;  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3194    pcre_uchar othercase[8];
3195    #elif defined SUPPORT_UTF && defined COMPILE_PCRE16
3196    pcre_uchar othercase[2];
3197    #else
3198    pcre_uchar othercase[1];
3199    #endif
3200    
3201  repeat = 1;  repeat = 1;
3202  while (TRUE)  while (TRUE)
3203    {    {
3204    last = TRUE;    last = TRUE;
3205    any = FALSE;    any = FALSE;
3206    caseless = 0;    caseless = FALSE;
3207    switch (*cc)    switch (*cc)
3208      {      {
3209      case OP_CHARI:      case OP_CHARI:
3210      caseless = 1;      caseless = TRUE;
3211      case OP_CHAR:      case OP_CHAR:
3212      last = FALSE;      last = FALSE;
3213      cc++;      cc++;
# Line 3084  while (TRUE) Line 3228  while (TRUE)
3228      cc++;      cc++;
3229      continue;      continue;
3230    
3231        case OP_ASSERT:
3232        case OP_ASSERT_NOT:
3233        case OP_ASSERTBACK:
3234        case OP_ASSERTBACK_NOT:
3235        cc = bracketend(cc);
3236        continue;
3237    
3238        case OP_PLUSI:
3239        case OP_MINPLUSI:
3240        case OP_POSPLUSI:
3241        caseless = TRUE;
3242      case OP_PLUS:      case OP_PLUS:
3243      case OP_MINPLUS:      case OP_MINPLUS:
3244      case OP_POSPLUS:      case OP_POSPLUS:
# Line 3091  while (TRUE) Line 3246  while (TRUE)
3246      break;      break;
3247    
3248      case OP_EXACTI:      case OP_EXACTI:
3249      caseless = 1;      caseless = TRUE;
3250      case OP_EXACT:      case OP_EXACT:
3251      repeat = GET2(cc, 1);      repeat = GET2(cc, 1);
3252      last = FALSE;      last = FALSE;
3253      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3254      break;      break;
3255    
3256      case OP_PLUSI:      case OP_QUERYI:
3257      case OP_MINPLUSI:      case OP_MINQUERYI:
3258      case OP_POSPLUSI:      case OP_POSQUERYI:
3259      caseless = 1;      caseless = TRUE;
3260        case OP_QUERY:
3261        case OP_MINQUERY:
3262        case OP_POSQUERY:
3263        len = 1;
3264      cc++;      cc++;
3265    #ifdef SUPPORT_UTF
3266        if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3267    #endif
3268        max_chars = scan_prefix(common, cc + len, chars, bytes, max_chars);
3269        if (max_chars == 0)
3270          return consumed;
3271        last = FALSE;
3272      break;      break;
3273    
3274      case OP_KET:      case OP_KET:
# Line 3122  while (TRUE) Line 3288  while (TRUE)
3288      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
3289      while (*alternative == OP_ALT)      while (*alternative == OP_ALT)
3290        {        {
3291        max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);        max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, bytes, max_chars);
3292        if (max_chars == 0)        if (max_chars == 0)
3293          return consumed;          return consumed;
3294        alternative += GET(alternative, 1);        alternative += GET(alternative, 1);
# Line 3134  while (TRUE) Line 3300  while (TRUE)
3300      continue;      continue;
3301    
3302      case OP_CLASS:      case OP_CLASS:
3303    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3304        if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed;
3305    #endif
3306        any = TRUE;
3307        cc += 1 + 32 / sizeof(pcre_uchar);
3308        break;
3309    
3310      case OP_NCLASS:      case OP_NCLASS:
3311    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3312        if (common->utf) return consumed;
3313    #endif
3314      any = TRUE;      any = TRUE;
3315      cc += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + 32 / sizeof(pcre_uchar);
3316      break;      break;
3317    
3318  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3319      case OP_XCLASS:      case OP_XCLASS:
3320    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3321        if (common->utf) return consumed;
3322    #endif
3323      any = TRUE;      any = TRUE;
3324      cc += GET(cc, 1);      cc += GET(cc, 1);
3325      break;      break;
3326  #endif  #endif
3327    
     case OP_NOT_DIGIT:  
3328      case OP_DIGIT:      case OP_DIGIT:
3329      case OP_NOT_WHITESPACE:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3330        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE))
3331          return consumed;
3332    #endif
3333        any = TRUE;
3334        cc++;
3335        break;
3336    
3337      case OP_WHITESPACE:      case OP_WHITESPACE:
3338      case OP_NOT_WORDCHAR:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3339        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE))
3340          return consumed;
3341    #endif
3342        any = TRUE;
3343        cc++;
3344        break;
3345    
3346      case OP_WORDCHAR:      case OP_WORDCHAR:
3347    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3348        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE))
3349          return consumed;
3350    #endif
3351        any = TRUE;
3352        cc++;
3353        break;
3354    
3355        case OP_NOT:
3356        case OP_NOTI:
3357        cc++;
3358        /* Fall through. */
3359        case OP_NOT_DIGIT:
3360        case OP_NOT_WHITESPACE:
3361        case OP_NOT_WORDCHAR:
3362      case OP_ANY:      case OP_ANY:
3363      case OP_ALLANY:      case OP_ALLANY:
3364    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3365        if (common->utf) return consumed;
3366    #endif
3367      any = TRUE;      any = TRUE;
3368      cc++;      cc++;
3369      break;      break;
# Line 3161  while (TRUE) Line 3371  while (TRUE)
3371  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3372      case OP_NOTPROP:      case OP_NOTPROP:
3373      case OP_PROP:      case OP_PROP:
3374    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3375        if (common->utf) return consumed;
3376    #endif
3377      any = TRUE;      any = TRUE;
3378      cc += 1 + 2;      cc += 1 + 2;
3379      break;      break;
# Line 3171  while (TRUE) Line 3384  while (TRUE)
3384      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3385      continue;      continue;
3386    
3387        case OP_NOTEXACT:
3388        case OP_NOTEXACTI:
3389    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3390        if (common->utf) return consumed;
3391    #endif
3392        any = TRUE;
3393        repeat = GET2(cc, 1);
3394        cc += 1 + IMM2_SIZE + 1;
3395        break;
3396    
3397      default:      default:
3398      return consumed;      return consumed;
3399      }      }
3400    
3401    if (any)    if (any)
3402      {      {
 #ifdef SUPPORT_UTF  
     if (common->utf) return consumed;  
 #endif  
3403  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3404      mask = 0xff;      mask = 0xff;
3405  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 3194  while (TRUE) Line 3414  while (TRUE)
3414        {        {
3415        chars[0] = mask;        chars[0] = mask;
3416        chars[1] = mask;        chars[1] = mask;
3417          bytes[0] = 255;
3418    
3419          consumed++;
3420        if (--max_chars == 0)        if (--max_chars == 0)
3421          return consumed;          return consumed;
       consumed++;  
3422        chars += 2;        chars += 2;
3423          bytes += MAX_N_BYTES;
3424        }        }
3425      while (--repeat > 0);      while (--repeat > 0);
3426    
# Line 3211  while (TRUE) Line 3433  while (TRUE)
3433    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3434  #endif  #endif
3435    
3436    if (caseless != 0 && char_has_othercase(common, cc))    if (caseless && char_has_othercase(common, cc))
3437      {      {
3438      caseless = char_get_othercase_bit(common, cc);  #ifdef SUPPORT_UTF
3439      if (caseless == 0)      if (common->utf)
3440        return consumed;        {
3441  #ifdef COMPILE_PCRE8        GETCHAR(chr, cc);
3442      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));        if ((int)PRIV(ord2utf)(char_othercase(common, chr), othercase) != len)
3443  #else          return consumed;
3444      if ((caseless & 0x100) != 0)        }
       caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));  
3445      else      else
       caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));  
3446  #endif  #endif
3447          {
3448          chr = *cc;
3449          othercase[0] = TABLE_GET(chr, common->fcc, chr);
3450          }
3451      }      }
3452    else    else
3453      caseless = 0;      caseless = FALSE;
3454    
3455    len_save = len;    len_save = len;
3456    cc_save = cc;    cc_save = cc;
3457    while (TRUE)    while (TRUE)
3458      {      {
3459        oc = othercase;
3460      do      do
3461        {        {
3462        chr = *cc;        chr = *cc;
# Line 3239  while (TRUE) Line 3464  while (TRUE)
3464        if (SLJIT_UNLIKELY(chr == NOTACHAR))        if (SLJIT_UNLIKELY(chr == NOTACHAR))
3465          return consumed;          return consumed;
3466  #endif  #endif
3467          add_prefix_byte((pcre_uint8)chr, bytes);
3468    
3469        mask = 0;        mask = 0;
3470        if ((pcre_uint32)len == (caseless & 0xff))        if (caseless)
3471          {          {
3472          mask = caseless >> 8;          add_prefix_byte((pcre_uint8)*oc, bytes);
3473            mask = *cc ^ *oc;
3474          chr |= mask;          chr |= mask;
3475          }          }
3476    
3477    #ifdef COMPILE_PCRE32
3478          if (chars[0] == NOTACHAR && chars[1] == 0)
3479    #else
3480        if (chars[0] == NOTACHAR)        if (chars[0] == NOTACHAR)
3481    #endif
3482          {          {
3483          chars[0] = chr;          chars[0] = chr;
3484          chars[1] = mask;          chars[1] = mask;
# Line 3260  while (TRUE) Line 3492  while (TRUE)
3492          }          }
3493    
3494        len--;        len--;
3495          consumed++;
3496        if (--max_chars == 0)        if (--max_chars == 0)
3497          return consumed;          return consumed;
       consumed++;  
3498        chars += 2;        chars += 2;
3499          bytes += MAX_N_BYTES;
3500        cc++;        cc++;
3501          oc++;
3502        }        }
3503      while (len > 0);      while (len > 0);
3504    
# Line 3281  while (TRUE) Line 3515  while (TRUE)
3515    }    }
3516  }  }
3517    
 #define MAX_N_CHARS 16  
   
3518  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3519  {  {
3520  DEFINE_COMPILER;  DEFINE_COMPILER;
3521  struct sljit_label *start;  struct sljit_label *start;
3522  struct sljit_jump *quit;  struct sljit_jump *quit;
3523  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
3524    pcre_uint8 bytes[MAX_N_CHARS * MAX_N_BYTES];
3525  pcre_uint8 ones[MAX_N_CHARS];  pcre_uint8 ones[MAX_N_CHARS];
 pcre_uint32 mask;  
 int i, max;  
3526  int offsets[3];  int offsets[3];
3527    pcre_uint32 mask;
3528    pcre_uint8 *byte_set, *byte_set_end;
3529    int i, max, from;
3530    int range_right = -1, range_len = 3 - 1;
3531    sljit_ub *update_table = NULL;
3532    BOOL in_range;
3533    
3534    /* This is even TRUE, if both are NULL. */
3535    SLJIT_ASSERT(common->read_only_data_ptr == common->read_only_data);
3536    
3537  for (i = 0; i < MAX_N_CHARS; i++)  for (i = 0; i < MAX_N_CHARS; i++)
3538    {    {
3539    chars[i << 1] = NOTACHAR;    chars[i << 1] = NOTACHAR;
3540    chars[(i << 1) + 1] = 0;    chars[(i << 1) + 1] = 0;
3541      bytes[i * MAX_N_BYTES] = 0;
3542    }    }
3543    
3544  max = scan_prefix(common, common->start, chars, MAX_N_CHARS);  max = scan_prefix(common, common->start, chars, bytes, MAX_N_CHARS);
3545    
3546  if (max <= 1)  if (max <= 1)
3547    return FALSE;    return FALSE;
# Line 3317  for (i = 0; i < max; i++) Line 3558  for (i = 0; i < max; i++)
3558      }      }
3559    }    }
3560    
3561    in_range = FALSE;
3562    for (i = 0; i <= max; i++)
3563      {
3564      if (in_range && (i - from) > range_len && (bytes[(i - 1) * MAX_N_BYTES] <= 4))
3565        {
3566        range_len = i - from;
3567        range_right = i - 1;
3568        }
3569    
3570      if (i < max && bytes[i * MAX_N_BYTES] < 255)
3571        {
3572        if (!in_range)
3573          {
3574          in_range = TRUE;
3575          from = i;
3576          }
3577        }
3578      else if (in_range)
3579        in_range = FALSE;
3580      }
3581    
3582    if (range_right >= 0)
3583      {
3584      /* Since no data is consumed (see the assert in the beginning
3585      of this function), this space can be reallocated. */
3586      if (common->read_only_data)
3587        SLJIT_FREE(common->read_only_data);
3588    
3589      common->read_only_data_size += 256;
3590      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
3591      if (common->read_only_data == NULL)
3592        return TRUE;
3593    
3594      update_table = (sljit_ub *)common->read_only_data;
3595      common->read_only_data_ptr = (sljit_uw *)(update_table + 256);
3596      memset(update_table, IN_UCHARS(range_len), 256);
3597    
3598      for (i = 0; i < range_len; i++)
3599        {
3600        byte_set = bytes + ((range_right - i) * MAX_N_BYTES);
3601        SLJIT_ASSERT(byte_set[0] > 0 && byte_set[0] < 255);
3602        byte_set_end = byte_set + byte_set[0];
3603        byte_set++;
3604        while (byte_set <= byte_set_end)
3605          {
3606          if (update_table[*byte_set] > IN_UCHARS(i))
3607            update_table[*byte_set] = IN_UCHARS(i);
3608          byte_set++;
3609          }
3610        }
3611      }
3612    
3613  offsets[0] = -1;  offsets[0] = -1;
3614  /* Scan forward. */  /* Scan forward. */
3615  for (i = 0; i < max; i++)  for (i = 0; i < max; i++)
# Line 3325  for (i = 0; i < max; i++) Line 3618  for (i = 0; i < max; i++)
3618      break;      break;
3619    }    }
3620    
3621  if (offsets[0] == -1)  if (offsets[0] < 0 && range_right < 0)
3622    return FALSE;    return FALSE;
3623    
3624  /* Scan backward. */  if (offsets[0] >= 0)
 offsets[1] = -1;  
 for (i = max - 1; i > offsets[0]; i--)  
   if (ones[i] <= 2) {  
     offsets[1] = i;  
     break;  
   }  
   
 offsets[2] = -1;  
 if (offsets[1] >= 0)  
3625    {    {
3626    /* Scan from middle. */    /* Scan backward. */
3627    for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)    offsets[1] = -1;
3628      if (ones[i] <= 2)    for (i = max - 1; i > offsets[0]; i--)
3629        if (ones[i] <= 2 && i != range_right)
3630        {        {
3631        offsets[2] = i;        offsets[1] = i;
3632        break;        break;
3633        }        }
3634    
3635    if (offsets[2] == -1)    /* This case is handled better by fast_forward_first_char. */
3636      if (offsets[1] == -1 && offsets[0] == 0 && range_right < 0)
3637        return FALSE;
3638    
3639      offsets[2] = -1;
3640      /* We only search for a middle character if there is no range check. */
3641      if (offsets[1] >= 0 && range_right == -1)
3642      {      {
3643      for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)      /* Scan from middle. */
3644        for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3645        if (ones[i] <= 2)        if (ones[i] <= 2)
3646          {          {
3647          offsets[2] = i;          offsets[2] = i;
3648          break;          break;
3649          }          }
3650    
3651        if (offsets[2] == -1)
3652          {
3653          for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3654            if (ones[i] <= 2)
3655              {
3656              offsets[2] = i;
3657              break;
3658              }
3659          }
3660      }      }
   }  
3661    
3662  SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3663  SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3664    
3665  chars[0] = chars[offsets[0] << 1];    chars[0] = chars[offsets[0] << 1];
3666  chars[1] = chars[(offsets[0] << 1) + 1];    chars[1] = chars[(offsets[0] << 1) + 1];
3667  if (offsets[2] >= 0)    if (offsets[2] >= 0)
3668    {      {
3669    chars[2] = chars[offsets[2] << 1];      chars[2] = chars[offsets[2] << 1];
3670    chars[3] = chars[(offsets[2] << 1) + 1];      chars[3] = chars[(offsets[2] << 1) + 1];
3671    }      }
3672  if (offsets[1] >= 0)    if (offsets[1] >= 0)
3673    {      {
3674    chars[4] = chars[offsets[1] << 1];      chars[4] = chars[offsets[1] << 1];
3675    chars[5] = chars[(offsets[1] << 1) + 1];      chars[5] = chars[(offsets[1] << 1) + 1];
3676        }
3677    }    }
3678    
3679  max -= 1;  max -= 1;
3680  if (firstline)  if (firstline)
3681    {    {
3682    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3683      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3684    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3685    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3686      quit = CMP(SLJIT_C_LESS_EQUAL, STR_END, 0, TMP1, 0);
3687      OP1(SLJIT_MOV, STR_END, 0, TMP1, 0);
3688      JUMPHERE(quit);
3689    }    }
3690  else  else
3691    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3692    
3693    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3694    if (range_right >= 0)
3695      OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table);
3696    #endif
3697    
3698  start = LABEL();  start = LABEL();
3699  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3700    
3701  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));  SLJIT_ASSERT(range_right >= 0 || offsets[0] >= 0);
 if (offsets[1] >= 0)  
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
3702    
3703  if (chars[1] != 0)  if (range_right >= 0)
   OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);  
 CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  
 if (offsets[2] >= 0)  
   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));  
   
 if (offsets[1] >= 0)  
3704    {    {
3705    if (chars[5] != 0)  #if defined COMPILE_PCRE8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
3706      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right));
3707    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);  #else
3708      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1);
3709    #endif
3710    
3711    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3712      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0);
3713    #else
3714      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table);
3715    #endif
3716      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3717      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start);
3718    }    }
3719    
3720  if (offsets[2] >= 0)  if (offsets[0] >= 0)
3721    {    {
3722    if (chars[3] != 0)    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3723      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);    if (offsets[1] >= 0)
3724    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3725      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3726    
3727      if (chars[1] != 0)
3728        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3729      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3730      if (offsets[2] >= 0)
3731        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3732    
3733      if (offsets[1] >= 0)
3734        {
3735        if (chars[5] != 0)
3736          OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3737        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3738        }
3739    
3740      if (offsets[2] >= 0)
3741        {
3742        if (chars[3] != 0)
3743          OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3744        CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3745        }
3746      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3747    }    }
 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
3748    
3749  JUMPHERE(quit);  JUMPHERE(quit);
3750    
3751  if (firstline)  if (firstline)
3752      {
3753      if (range_right >= 0)
3754        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3755    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3756      if (range_right >= 0)
3757        {
3758        quit = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3759        OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
3760        JUMPHERE(quit);
3761        }
3762      }
3763  else  else
3764    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3765  return TRUE;  return TRUE;
3766  }  }
3767    
3768  #undef MAX_N_CHARS  #undef MAX_N_CHARS
3769    #undef MAX_N_BYTES
3770    
3771  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
3772  {  {
# Line 3528  if (common->nltype == NLTYPE_FIXED && co Line 3872  if (common->nltype == NLTYPE_FIXED && co
3872    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3873    
3874    if (firstline)    if (firstline)
3875      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3876    return;    return;
3877    }    }
3878    
# Line 3538  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3882  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3882  skip_char_back(common);  skip_char_back(common);
3883    
3884  loop = LABEL();  loop = LABEL();
3885    common->ff_newline_shortcut = loop;
3886    
3887  read_char_range(common, common->nlmin, common->nlmax, TRUE);  read_char_range(common, common->nlmin, common->nlmax, TRUE);
3888  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3889  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
# Line 4502  while (*cc != XCL_END) Line 4848  while (*cc != XCL_END)
4848  /* We are not necessary in utf mode even in 8 bit mode. */  /* We are not necessary in utf mode even in 8 bit mode. */
4849  cc = ccbegin;  cc = ccbegin;
4850  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4851  read_char_range(common, min, max, (cc[0] & XCL_NOT) != 0);  read_char_range(common, min, max, (cc[-1] & XCL_NOT) != 0);
4852    
4853  if ((cc[-1] & XCL_HASPROP) == 0)  if ((cc[-1] & XCL_HASPROP) == 0)
4854    {    {
# Line 4525  if ((cc[-1] & XCL_HASPROP) == 0) Line 4871  if ((cc[-1] & XCL_HASPROP) == 0)
4871      cc += 32 / sizeof(pcre_uchar);      cc += 32 / sizeof(pcre_uchar);
4872      }      }
4873    else    else
4874      add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));      {
4875        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, min);
4876        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, max - min));
4877        }
4878    }    }
4879  else if ((cc[-1] & XCL_MAP) != 0)  else if ((cc[-1] & XCL_MAP) != 0)
4880    {    {
# Line 7750  if (*cc == OP_FAIL) Line 8099  if (*cc == OP_FAIL)
8099    return cc + 1;    return cc + 1;
8100    }    }
8101    
8102  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL || !common->might_be_empty)
8103    {    {
8104    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
8105    if (common->accept_label == NULL)    if (common->accept_label == NULL)
# Line 8452  if (bra == OP_BRAZERO) Line 8801  if (bra == OP_BRAZERO)
8801  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8802  {  {
8803  DEFINE_COMPILER;  DEFINE_COMPILER;
8804  int opcode, stacksize, count;  int opcode, stacksize, alt_count, alt_max;
8805  int offset = 0;  int offset = 0;
8806  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;
8807  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;
8808  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8809  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
8810  pcre_uchar *ccprev;  pcre_uchar *ccprev;
 jump_list *jumplist = NULL;  
 jump_list *jumplistitem = NULL;  
8811  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
8812  pcre_uchar ket;  pcre_uchar ket;
8813  assert_backtrack *assert;  assert_backtrack *assert;
8814  BOOL has_alternatives;  BOOL has_alternatives;
8815  BOOL needs_control_head = FALSE;  BOOL needs_control_head = FALSE;
8816  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
8817    struct sljit_jump *alt1 = NULL;
8818    struct sljit_jump *alt2 = NULL;
8819  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
8820  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
8821  struct sljit_label *rmin_label = NULL;  struct sljit_label *rmin_label = NULL;
# Line 8504  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 8853  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
8853  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
8854    opcode = OP_ONCE;    opcode = OP_ONCE;
8855    
8856    alt_max = has_alternatives ? no_alternatives(ccbegin) : 0;
8857    
8858  /* Decoding the needs_control_head in framesize. */  /* Decoding the needs_control_head in framesize. */
8859  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
8860    {    {
# Line 8617  else if (SLJIT_UNLIKELY(opcode == OP_CON Line 8968  else if (SLJIT_UNLIKELY(opcode == OP_CON
8968      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8969      free_stack(common, 1);      free_stack(common, 1);
8970    
8971      jumplistitem = sljit_alloc_memory(compiler, sizeof(jump_list));      alt_max = 2;
8972      if (SLJIT_UNLIKELY(!jumplistitem))      alt1 = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
       return;  
     jumplist = jumplistitem;  
     jumplistitem->next = NULL;  
     jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 1);  
8973      }      }
8974    }    }
8975  else if (*cc == OP_ALT)  else if (has_alternatives)
8976    {    {
   /* Build a jump list. Get the last successfully matched branch index. */  
8977    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8978    free_stack(common, 1);    free_stack(common, 1);
   count = 1;  
   do  
     {  
     /* Append as the last item. */  
     if (jumplist != NULL)  
       {  
       jumplistitem->next = sljit_alloc_memory(compiler, sizeof(jump_list));  
       jumplistitem = jumplistitem->next;  
       }  
     else  
       {  
       jumplistitem = sljit_alloc_memory(compiler, sizeof(jump_list));  
       jumplist = jumplistitem;  
       }  
   
     if (SLJIT_UNLIKELY(!jumplistitem))  
       return;  
8979    
8980      jumplistitem->next = NULL;    if (alt_max > 4)
8981      jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, count++);      {
8982      cc += GET(cc, 1);      /* Table jump if alt_max is greater than 4. */
8983        sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(TMP1), (sljit_sw)common->read_only_data_ptr);
8984        add_label_addr(common);
8985        }
8986      else
8987        {
8988        if (alt_max == 4)
8989          alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
8990        alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
8991      }      }
   while (*cc == OP_ALT);  
   
   cc = ccbegin + GET(ccbegin, 1);  
8992    }    }
8993    
8994  COMPILE_BACKTRACKINGPATH(current->top);  COMPILE_BACKTRACKINGPATH(current->top);
# Line 8689  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 9023  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
9023    
9024  if (has_alternatives)  if (has_alternatives)
9025    {    {
9026    count = 1;    alt_count = sizeof(sljit_uw);
9027    do    do
9028      {      {
9029      current->top = NULL;      current->top = NULL;
# Line 8765  if (has_alternatives) Line 9099  if (has_alternatives)
9099        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
9100    
9101      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9102        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, alt_count);
9103    
9104      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
9105        {        {
# Line 8778  if (has_alternatives) Line 9112  if (has_alternatives)
9112    
9113      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9114        {        {
9115        SLJIT_ASSERT(jumplist);        if (alt_max > 4)
9116        JUMPHERE(jumplist->jump);          add_label_addr(common);
9117        jumplist = jumplist->next;        else
9118            {
9119            if (alt_count != 2 * sizeof(sljit_uw))
9120              {
9121              JUMPHERE(alt1);
9122              if (alt_max == 3 && alt_count == sizeof(sljit_uw))
9123                alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
9124              }
9125            else
9126              {
9127              JUMPHERE(alt2);
9128              if (alt_max == 4)
9129                alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_uw));
9130              }
9131            }
9132          alt_count += sizeof(sljit_uw);
9133        }        }
9134    
9135      COMPILE_BACKTRACKINGPATH(current->top);      COMPILE_BACKTRACKINGPATH(current->top);
# Line 8789  if (has_alternatives) Line 9138  if (has_alternatives)
9138      SLJIT_ASSERT(!current->nextbacktracks);      SLJIT_ASSERT(!current->nextbacktracks);
9139      }      }
9140    while (*cc == OP_ALT);    while (*cc == OP_ALT);
   SLJIT_ASSERT(!jumplist);  
9141    
9142    if (cond != NULL)    if (cond != NULL)
9143      {      {
# Line 9390  pcre_uchar *ccend; Line 9738  pcre_uchar *ccend;
9738  executable_functions *functions;  executable_functions *functions;
9739  void *executable_func;  void *executable_func;
9740  sljit_uw executable_size;  sljit_uw executable_size;
9741    sljit_uw total_length;
9742    label_addr_list *label_addr;
9743  struct sljit_label *mainloop_label = NULL;  struct sljit_label *mainloop_label = NULL;
9744  struct sljit_label *continue_match_label;  struct sljit_label *continue_match_label;
9745  struct sljit_label *empty_match_found_label;  struct sljit_label *empty_match_found_label = NULL;
9746  struct sljit_label *empty_match_backtrack_label;  struct sljit_label *empty_match_backtrack_label = NULL;
9747  struct sljit_label *reset_match_label;  struct sljit_label *reset_match_label;
9748    struct sljit_label *quit_label;
9749  struct sljit_jump *jump;  struct sljit_jump *jump;
9750  struct sljit_jump *minlength_check_failed = NULL;  struct sljit_jump *minlength_check_failed = NULL;
9751  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
9752  struct sljit_jump *empty_match;  struct sljit_jump *empty_match = NULL;
 struct sljit_label *quit_label;  
9753    
9754  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);
9755  study = extra->study_data;  study = extra->study_data;
# Line 9412  memset(common, 0, sizeof(compiler_common Line 9762  memset(common, 0, sizeof(compiler_common
9762  rootbacktrack.cc = (pcre_uchar *)re + re->name_table_offset + re->name_count * re->name_entry_size;  rootbacktrack.cc = (pcre_uchar *)re + re->name_table_offset + re->name_count * re->name_entry_size;
9763    
9764  common->start = rootbacktrack.cc;  common->start = rootbacktrack.cc;
9765    common->read_only_data = NULL;
9766    common->read_only_data_size = 0;
9767    common->read_only_data_ptr = NULL;
9768  common->fcc = tables + fcc_offset;  common->fcc = tables + fcc_offset;
9769  common->lcc = (sljit_sw)(tables + lcc_offset);  common->lcc = (sljit_sw)(tables + lcc_offset);
9770  common->mode = mode;  common->mode = mode;
9771    common->might_be_empty = study->minlength == 0;
9772  common->nltype = NLTYPE_FIXED;  common->nltype = NLTYPE_FIXED;
9773  switch(re->options & PCRE_NEWLINE_BITS)  switch(re->options & PCRE_NEWLINE_BITS)
9774    {    {
# Line 9487  if (common->utf) Line 9841  if (common->utf)
9841    common->bsr_nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;    common->bsr_nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9842    }    }
9843  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
9844  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(common->start);
9845    
9846  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9847  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
# Line 9500  memset(common->optimized_cbracket, 0, re Line 9854  memset(common->optimized_cbracket, 0, re
9854  memset(common->optimized_cbracket, 1, re->top_bracket + 1);  memset(common->optimized_cbracket, 1, re->top_bracket + 1);
9855  #endif  #endif
9856    
9857  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*common->start == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
9858  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2
9859  common->capture_last_ptr = common->ovector_start;  common->capture_last_ptr = common->ovector_start;
9860  common->ovector_start += sizeof(sljit_sw);  common->ovector_start += sizeof(sljit_sw);
9861  #endif  #endif
9862  if (!check_opcode_types(common, rootbacktrack.cc, ccend))  if (!check_opcode_types(common, common->start, ccend))
9863    {    {
9864    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9865    return;    return;
# Line 9568  if (common->capture_last_ptr != 0) Line 9922  if (common->capture_last_ptr != 0)
9922  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
9923  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);
9924    
9925  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(sljit_si));  total_length = ccend - common->start;
9926    common->private_data_ptrs = (sljit_si *)SLJIT_MALLOC(total_length * (sizeof(sljit_si) + (common->has_then ? 1 : 0)));
9927  if (!common->private_data_ptrs)  if (!common->private_data_ptrs)
9928    {    {
9929    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9930    return;    return;
9931    }    }
9932  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, total_length * sizeof(sljit_si));
9933    
9934  private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);  private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);
9935  set_private_data_ptrs(common, &private_data_size, ccend);  set_private_data_ptrs(common, &private_data_size, ccend);
# Line 9587  if (private_data_size > SLJIT_MAX_LOCAL_ Line 9942  if (private_data_size > SLJIT_MAX_LOCAL_
9942    
9943  if (common->has_then)  if (common->has_then)
9944    {    {
9945    common->then_offsets = (pcre_uint8 *)SLJIT_MALLOC(ccend - rootbacktrack.cc);    common->then_offsets = (pcre_uint8 *)(common->private_data_ptrs + total_length);
9946    if (!common->then_offsets)    memset(common->then_offsets, 0, total_length);
9947      set_then_offsets(common, common->start, NULL);
9948      }
9949    
9950    if (common->read_only_data_size > 0)
9951      {
9952      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
9953      if (common->read_only_data == NULL)
9954      {      {
9955      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9956      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9957      return;      return;
9958      }      }
9959    memset(common->then_offsets, 0, ccend - rootbacktrack.cc);    common->read_only_data_ptr = common->read_only_data;
   set_then_offsets(common, rootbacktrack.cc, NULL);  
9960    }    }
9961    
9962  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
# Line 9603  if (!compiler) Line 9964  if (!compiler)
9964    {    {
9965    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9966    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9967    if (common->has_then)    if (common->read_only_data)
9968      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9969    return;    return;
9970    }    }
9971  common->compiler = compiler;  common->compiler = compiler;
# Line 9643  if ((re->options & PCRE_ANCHORED) == 0) Line 10004  if ((re->options & PCRE_ANCHORED) == 0)
10004    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)
10005      {      {
10006      if (mode == JIT_COMPILE && fast_forward_first_n_chars(common, (re->options & PCRE_FIRSTLINE) != 0))      if (mode == JIT_COMPILE && fast_forward_first_n_chars(common, (re->options & PCRE_FIRSTLINE) != 0))
10007        { /* Do nothing */ }        {
10008          /* If read_only_data is reallocated, we might have an allocation failure. */
10009          if (common->read_only_data_size > 0 && common->read_only_data == NULL)
10010            {
10011            sljit_free_compiler(compiler);
10012            SLJIT_FREE(common->optimized_cbracket);
10013            SLJIT_FREE(common->private_data_ptrs);
10014            return;
10015            }
10016          }
10017      else if ((re->flags & PCRE_FIRSTSET) != 0)      else if ((re->flags & PCRE_FIRSTSET) != 0)
10018        fast_forward_first_char(common, (pcre_uchar)re->first_char, (re->flags & PCRE_FCH_CASELESS) != 0, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_first_char(common, (pcre_uchar)re->first_char, (re->flags & PCRE_FCH_CASELESS) != 0, (re->options & PCRE_FIRSTLINE) != 0);
10019      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
# Line 9690  if (mode == JIT_PARTIAL_SOFT_COMPILE) Line 10060  if (mode == JIT_PARTIAL_SOFT_COMPILE)
10060  else if (mode == JIT_PARTIAL_HARD_COMPILE)  else if (mode == JIT_PARTIAL_HARD_COMPILE)
10061    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);
10062    
10063  compile_matchingpath(common, rootbacktrack.cc, ccend, &rootbacktrack);  compile_matchingpath(common, common->start, ccend, &rootbacktrack);
10064  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
10065    {    {
10066    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
10067    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
10068    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
10069    if (common->has_then)    if (common->read_only_data)
10070      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
10071    return;    return;
10072    }    }
10073    
10074  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  if (common->might_be_empty)
10075  empty_match_found_label = LABEL();    {
10076      empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
10077      empty_match_found_label = LABEL();
10078      }
10079    
10080  common->accept_label = LABEL();  common->accept_label = LABEL();
10081  if (common->accept != NULL)  if (common->accept != NULL)
# Line 9726  if (mode != JIT_COMPILE) Line 10099  if (mode != JIT_COMPILE)
10099    return_with_partial_match(common, common->quit_label);    return_with_partial_match(common, common->quit_label);
10100    }    }
10101    
10102  empty_match_backtrack_label = LABEL();  if (common->might_be_empty)
10103      empty_match_backtrack_label = LABEL();
10104  compile_backtrackingpath(common, rootbacktrack.top);  compile_backtrackingpath(common, rootbacktrack.top);
10105  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
10106    {    {
10107    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
10108    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
10109    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
10110    if (common->has_then)    if (common->read_only_data)
10111      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
10112    return;    return;
10113    }    }
10114    
# Line 9762  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SL Line 10136  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SL
10136    
10137  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
10138    {    {
10139    if ((re->options & PCRE_FIRSTLINE) == 0)    if (common->ff_newline_shortcut != NULL)
10140      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop_label);      {
10141        if ((re->options & PCRE_FIRSTLINE) == 0)
10142          CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, common->ff_newline_shortcut);
10143        /* There cannot be more newlines here. */
10144        }
10145    else    else
10146      CMPTO(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0, mainloop_label);      {
10147        if ((re->options & PCRE_FIRSTLINE) == 0)
10148          CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop_label);
10149        else
10150          CMPTO(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0, mainloop_label);
10151        }
10152    }    }
10153    
10154  /* No more remaining characters. */  /* No more remaining characters. */
# Line 9780  JUMPTO(SLJIT_JUMP, common->quit_label); Line 10163  JUMPTO(SLJIT_JUMP, common->quit_label);
10163    
10164  flush_stubs(common);  flush_stubs(common);
10165    
10166  JUMPHERE(empty_match);  if (common->might_be_empty)
10167  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    {
10168  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));    JUMPHERE(empty_match);
10169  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
10170  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));
10171  CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found_label);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);
10172  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));
10173  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found_label);
10174  JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
10175      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);
10176      JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);
10177      }
10178    
10179  common->currententry = common->entries;  common->currententry = common->entries;
10180  common->local_exit = TRUE;  common->local_exit = TRUE;
# Line 9802  while (common->currententry != NULL) Line 10188  while (common->currententry != NULL)
10188      sljit_free_compiler(compiler);      sljit_free_compiler(compiler);
10189      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
10190      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
10191      if (common->has_then)      if (common->read_only_data)
10192        SLJIT_FREE(common->then_offsets);        SLJIT_FREE(common->read_only_data);
10193      return;      return;
10194      }      }
10195    flush_stubs(common);    flush_stubs(common);
# Line 9913  if (common->getucd != NULL) Line 10299  if (common->getucd != NULL)
10299    }    }
10300  #endif  #endif
10301    
10302    SLJIT_ASSERT(common->read_only_data + (common->read_only_data_size >> SLJIT_WORD_SHIFT) == common->read_only_data_ptr);
10303  SLJIT_FREE(common->optimized_cbracket);  SLJIT_FREE(common->optimized_cbracket);
10304  SLJIT_FREE(common->private_data_ptrs);  SLJIT_FREE(common->private_data_ptrs);
 if (common->has_then)  
   SLJIT_FREE(common->then_offsets);  
10305    
10306  executable_func = sljit_generate_code(compiler);  executable_func = sljit_generate_code(compiler);
10307  executable_size = sljit_get_generated_code_size(compiler);  executable_size = sljit_get_generated_code_size(compiler);
10308    label_addr = common->label_addrs;
10309    while (label_addr != NULL)
10310      {
10311      *label_addr->addr = sljit_get_label_addr(label_addr->label);
10312      label_addr = label_addr->next;
10313      }
10314  sljit_free_compiler(compiler);  sljit_free_compiler(compiler);
10315  if (executable_func == NULL)  if (executable_func == NULL)
10316      {
10317      if (common->read_only_data)
10318        SLJIT_FREE(common->read_only_data);
10319    return;    return;
10320      }
10321    
10322  /* Reuse the function descriptor if possible. */  /* Reuse the function descriptor if possible. */
10323  if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && extra->executable_jit != NULL)  if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && extra->executable_jit != NULL)
# Line 9942  else Line 10337  else
10337    if (functions == NULL)    if (functions == NULL)
10338      {      {
10339      /* This case is highly unlikely since we just recently      /* This case is highly unlikely since we just recently
10340      freed a lot of memory. Although not impossible. */      freed a lot of memory. Not impossible though. */
10341      sljit_free_code(executable_func);      sljit_free_code(executable_func);
10342        if (common->read_only_data)
10343          SLJIT_FREE(common->read_only_data);
10344      return;      return;
10345      }      }
10346    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
# Line 9954  else Line 10351  else
10351    }    }
10352    
10353  functions->executable_funcs[mode] = executable_func;  functions->executable_funcs[mode] = executable_func;
10354    functions->read_only_data[mode] = common->read_only_data;
10355  functions->executable_sizes[mode] = executable_size;  functions->executable_sizes[mode] = executable_size;
10356  }  }
10357    
# Line 10140  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO Line 10538  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO
10538    {    {
10539    if (functions->executable_funcs[i] != NULL)    if (functions->executable_funcs[i] != NULL)
10540      sljit_free_code(functions->executable_funcs[i]);      sljit_free_code(functions->executable_funcs[i]);
10541      if (functions->read_only_data[i] != NULL)
10542        SLJIT_FREE(functions->read_only_data[i]);
10543    }    }
10544  SLJIT_FREE(functions);  SLJIT_FREE(functions);
10545  }  }

Legend:
Removed from v.1426  
changed lines
  Added in v.1452

  ViewVC Help
Powered by ViewVC 1.1.5