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

Diff of /code/trunk/pcretest.c

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

revision 689 by ph10, Fri Sep 9 10:34:57 2011 UTC revision 788 by ph10, Tue Dec 6 15:38:01 2011 UTC
# Line 191  static int locale_set = 0; Line 191  static int locale_set = 0;
191  static int show_malloc;  static int show_malloc;
192  static int use_utf8;  static int use_utf8;
193  static size_t gotten_store;  static size_t gotten_store;
194    static size_t first_gotten_store = 0;
195  static const unsigned char *last_callout_mark = NULL;  static const unsigned char *last_callout_mark = NULL;
196    
197  /* The buffers grow automatically if very long input lines are encountered. */  /* The buffers grow automatically if very long input lines are encountered. */
# Line 230  static const char *errtexts[] = { Line 231  static const char *errtexts[] = {
231    "bad offset value",    "bad offset value",
232    NULL,  /* SHORTUTF8 is handled specially */    NULL,  /* SHORTUTF8 is handled specially */
233    "nested recursion at the same subject position",    "nested recursion at the same subject position",
234    "JIT stack limit reached"    "JIT stack limit reached"
235  };  };
236    
237    
# Line 999  return (cb->callout_number != callout_fa Line 1000  return (cb->callout_number != callout_fa
1000  *************************************************/  *************************************************/
1001    
1002  /* Alternative malloc function, to test functionality and save the size of a  /* Alternative malloc function, to test functionality and save the size of a
1003  compiled re. The show_malloc variable is set only during matching. */  compiled re, which is the first store request that pcre_compile() makes. The
1004    show_malloc variable is set only during matching. */
1005    
1006  static void *new_malloc(size_t size)  static void *new_malloc(size_t size)
1007  {  {
1008  void *block = malloc(size);  void *block = malloc(size);
1009  gotten_store = size;  gotten_store = size;
1010    if (first_gotten_store == 0) first_gotten_store = size;
1011  if (show_malloc)  if (show_malloc)
1012    fprintf(outfile, "malloc       %3d %p\n", (int)size, block);    fprintf(outfile, "malloc       %3d %p\n", (int)size, block);
1013  return block;  return block;
# Line 1289  while (argc > 1 && argv[op][0] == '-') Line 1292  while (argc > 1 && argv[op][0] == '-')
1292    
1293    if (strcmp(argv[op], "-m") == 0) showstore = 1;    if (strcmp(argv[op], "-m") == 0) showstore = 1;
1294    else if (strcmp(argv[op], "-s") == 0) force_study = 0;    else if (strcmp(argv[op], "-s") == 0) force_study = 0;
1295    else if (strcmp(argv[op], "-s+") == 0)    else if (strcmp(argv[op], "-s+") == 0)
1296      {      {
1297      force_study = 1;      force_study = 1;
1298      force_study_options = PCRE_STUDY_JIT_COMPILE;      force_study_options = PCRE_STUDY_JIT_COMPILE;
1299      }      }
1300    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(argv[op], "-q") == 0) quiet = 1;
1301    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strcmp(argv[op], "-b") == 0) debug = 1;
1302    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
# Line 1520  while (!done) Line 1523  while (!done)
1523        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
1524    
1525      re = (real_pcre *)new_malloc(true_size);      re = (real_pcre *)new_malloc(true_size);
1526      regex_gotten_store = gotten_store;      regex_gotten_store = first_gotten_store;
1527    
1528      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
1529    
# Line 1629  while (!done) Line 1632  while (!done)
1632    /* Look for options after final delimiter */    /* Look for options after final delimiter */
1633    
1634    options = 0;    options = 0;
1635      study_options = 0;
1636    log_store = showstore;  /* default from command line */    log_store = showstore;  /* default from command line */
1637    
1638    while (*pp != 0)    while (*pp != 0)
# Line 1665  while (!done) Line 1669  while (!done)
1669  #endif  #endif
1670    
1671        case 'S':        case 'S':
1672        if (do_study == 0)        if (do_study == 0)
1673          {          {
1674          do_study = 1;          do_study = 1;
1675          if (*pp == '+')          if (*pp == '+')
1676            {            {
1677            study_options |= PCRE_STUDY_JIT_COMPILE;            study_options |= PCRE_STUDY_JIT_COMPILE;
1678            pp++;            pp++;
1679            }            }
1680          }          }
1681        else        else
1682          {          {
1683          do_study = 0;          do_study = 0;
# Line 1777  while (!done) Line 1781  while (!done)
1781      if ((options & PCRE_UCP) != 0) cflags |= REG_UCP;      if ((options & PCRE_UCP) != 0) cflags |= REG_UCP;
1782      if ((options & PCRE_UNGREEDY) != 0) cflags |= REG_UNGREEDY;      if ((options & PCRE_UNGREEDY) != 0) cflags |= REG_UNGREEDY;
1783    
1784        first_gotten_store = 0;
1785      rc = regcomp(&preg, (char *)p, cflags);      rc = regcomp(&preg, (char *)p, cflags);
1786    
1787      /* Compilation failed; go back for another re, skipping to blank line      /* Compilation failed; go back for another re, skipping to blank line
# Line 1814  while (!done) Line 1819  while (!done)
1819            (double)CLOCKS_PER_SEC);            (double)CLOCKS_PER_SEC);
1820        }        }
1821    
1822        first_gotten_store = 0;
1823      re = pcre_compile((char *)p, options, &error, &erroroffset, tables);      re = pcre_compile((char *)p, options, &error, &erroroffset, tables);
1824    
1825      /* Compilation failed; go back for another re, skipping to blank line      /* Compilation failed; go back for another re, skipping to blank line
# Line 1848  while (!done) Line 1854  while (!done)
1854      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1855      if ((get_options & PCRE_UTF8) != 0) use_utf8 = 1;      if ((get_options & PCRE_UTF8) != 0) use_utf8 = 1;
1856    
1857      /* Print information if required. There are now two info-returning      /* Extract the size for possible writing before possibly flipping it,
1858      functions. The old one has a limited interface and returns only limited      and remember the store that was got. */
1859      data. Check that it agrees with the newer one. */  
1860        true_size = ((real_pcre *)re)->size;
1861        regex_gotten_store = first_gotten_store;
1862    
1863        /* Output code size information if requested */
1864    
1865      if (log_store)      if (log_store)
1866        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
1867          (int)(gotten_store -          (int)(first_gotten_store -
1868                sizeof(real_pcre) -                sizeof(real_pcre) -
1869                ((real_pcre *)re)->name_count * ((real_pcre *)re)->name_entry_size));                ((real_pcre *)re)->name_count * ((real_pcre *)re)->name_entry_size));
1870    
     /* Extract the size for possible writing before possibly flipping it,  
     and remember the store that was got. */  
   
     true_size = ((real_pcre *)re)->size;  
     regex_gotten_store = gotten_store;  
   
1871      /* If -s or /S was present, study the regex to generate additional info to      /* If -s or /S was present, study the regex to generate additional info to
1872      help with the matching, unless the pattern has the SS option, which      help with the matching, unless the pattern has the SS option, which
1873      suppresses the effect of /S (used for a few test patterns where studying is      suppresses the effect of /S (used for a few test patterns where studying is
# Line 1888  while (!done) Line 1892  while (!done)
1892        if (error != NULL)        if (error != NULL)
1893          fprintf(outfile, "Failed to study: %s\n", error);          fprintf(outfile, "Failed to study: %s\n", error);
1894        else if (extra != NULL)        else if (extra != NULL)
1895            {
1896          true_study_size = ((pcre_study_data *)(extra->study_data))->size;          true_study_size = ((pcre_study_data *)(extra->study_data))->size;
1897            if (log_store)
1898              {
1899              size_t jitsize;
1900              new_info(re, extra, PCRE_INFO_JITSIZE, &jitsize);
1901              if (jitsize != 0)
1902                fprintf(outfile, "Memory allocation (JIT code): %d\n", jitsize);
1903              }
1904            }
1905        }        }
1906    
1907      /* If /K was present, we set up for handling MARK data. */      /* If /K was present, we set up for handling MARK data. */
# Line 1941  while (!done) Line 1954  while (!done)
1954          }          }
1955        }        }
1956    
1957      /* Extract information from the compiled data if required */      /* Extract information from the compiled data if required. There are now
1958        two info-returning functions. The old one has a limited interface and
1959        returns only limited data. Check that it agrees with the newer one. */
1960    
1961      SHOW_INFO:      SHOW_INFO:
1962    
# Line 2156  while (!done) Line 2171  while (!done)
2171              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2172              }              }
2173            }            }
2174    
2175          /* Show this only if the JIT was set by /S, not by -s. */          /* Show this only if the JIT was set by /S, not by -s. */
2176    
2177          if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)          if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)
2178            {            {
2179            int jit;            int jit;
2180            new_info(re, extra, PCRE_INFO_JIT, &jit);            new_info(re, extra, PCRE_INFO_JIT, &jit);
2181            if (jit)            if (jit)
2182              fprintf(outfile, "JIT study was successful\n");              fprintf(outfile, "JIT study was successful\n");
2183            else            else
2184  #ifdef SUPPORT_JIT  #ifdef SUPPORT_JIT
2185              fprintf(outfile, "JIT study was not successful\n");              fprintf(outfile, "JIT study was not successful\n");
2186  #else  #else
2187              fprintf(outfile, "JIT support is not available in this version of PCRE\n");              fprintf(outfile, "JIT support is not available in this version of PCRE\n");
2188  #endif  #endif
2189            }            }
2190          }          }
2191        }        }
2192    
# Line 2346  while (!done) Line 2361  while (!done)
2361            {            {
2362            unsigned char *pt = p;            unsigned char *pt = p;
2363            c = 0;            c = 0;
2364            while (isxdigit(*(++pt)))  
2365              c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'W');            /* We used to have "while (isxdigit(*(++pt)))" here, but it fails
2366              when isxdigit() is a macro that refers to its argument more than
2367              once. This is banned by the C Standard, but apparently happens in at
2368              least one MacOS environment. */
2369    
2370              for (pt++; isxdigit(*pt); pt++)
2371                c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);
2372            if (*pt == '}')            if (*pt == '}')
2373              {              {
2374              unsigned char buff8[8];              unsigned char buff8[8];
# Line 2377  while (!done) Line 2398  while (!done)
2398          c = 0;          c = 0;
2399          while (i++ < 2 && isxdigit(*p))          while (i++ < 2 && isxdigit(*p))
2400            {            {
2401            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'W');            c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
2402            p++;            p++;
2403            }            }
2404          break;          break;
# Line 2492  while (!done) Line 2513  while (!done)
2513            getnamesptr = npp;            getnamesptr = npp;
2514            }            }
2515          continue;          continue;
2516    
2517          case 'J':          case 'J':
2518          while(isdigit(*p)) n = n * 10 + *p++ - '0';          while(isdigit(*p)) n = n * 10 + *p++ - '0';
2519          if (extra != NULL          if (extra != NULL
2520              && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0              && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0
2521              && extra->executable_jit != NULL)              && extra->executable_jit != NULL)
2522            {            {
2523            if (jit_stack != NULL) pcre_jit_stack_free(jit_stack);            if (jit_stack != NULL) pcre_jit_stack_free(jit_stack);
2524            jit_stack = pcre_jit_stack_alloc(1, n * 1024);            jit_stack = pcre_jit_stack_alloc(1, n * 1024);
2525            pcre_assign_jit_stack(extra, jit_callback, jit_stack);            pcre_assign_jit_stack(extra, jit_callback, jit_stack);
2526            }            }
2527          continue;          continue;
2528    
2529          case 'L':          case 'L':
# Line 2728  while (!done) Line 2749  while (!done)
2749            extra->flags = 0;            extra->flags = 0;
2750            }            }
2751          else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;          else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;
2752    
2753          (void)check_match_limit(re, extra, bptr, len, start_offset,          (void)check_match_limit(re, extra, bptr, len, start_offset,
2754            options|g_notempty, use_offsets, use_size_offsets,            options|g_notempty, use_offsets, use_size_offsets,
2755            PCRE_EXTRA_MATCH_LIMIT, &(extra->match_limit),            PCRE_EXTRA_MATCH_LIMIT, &(extra->match_limit),
# Line 3083  while (!done) Line 3104  while (!done)
3104      setlocale(LC_CTYPE, "C");      setlocale(LC_CTYPE, "C");
3105      locale_set = 0;      locale_set = 0;
3106      }      }
3107    if (jit_stack != NULL)    if (jit_stack != NULL)
3108      {      {
3109      pcre_jit_stack_free(jit_stack);      pcre_jit_stack_free(jit_stack);
3110      jit_stack = NULL;      jit_stack = NULL;
3111      }      }
3112    }    }
3113    
3114  if (infile == stdin) fprintf(outfile, "\n");  if (infile == stdin) fprintf(outfile, "\n");

Legend:
Removed from v.689  
changed lines
  Added in v.788

  ViewVC Help
Powered by ViewVC 1.1.5