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

Diff of /code/trunk/pcre_study.c

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

revision 673 by ph10, Thu Aug 25 16:06:03 2011 UTC revision 691 by ph10, Sun Sep 11 14:31:21 2011 UTC
# Line 1230  int min; Line 1230  int min;
1230  BOOL bits_set = FALSE;  BOOL bits_set = FALSE;
1231  BOOL had_accept = FALSE;  BOOL had_accept = FALSE;
1232  uschar start_bits[32];  uschar start_bits[32];
1233  pcre_extra *extra;  pcre_extra *extra = NULL;
1234  pcre_study_data *study;  pcre_study_data *study;
1235  const uschar *tables;  const uschar *tables;
1236  uschar *code;  uschar *code;
# Line 1281  if ((re->options & PCRE_ANCHORED) == 0 & Line 1281  if ((re->options & PCRE_ANCHORED) == 0 &
1281    rc = set_start_bits(code, start_bits, (re->options & PCRE_UTF8) != 0,    rc = set_start_bits(code, start_bits, (re->options & PCRE_UTF8) != 0,
1282      &compile_block);      &compile_block);
1283    bits_set = rc == SSB_DONE;    bits_set = rc == SSB_DONE;
1284    if (rc == SSB_UNKNOWN) *errorptr = "internal error: opcode not recognized";    if (rc == SSB_UNKNOWN)
1285        {
1286        *errorptr = "internal error: opcode not recognized";
1287        return NULL;
1288        }
1289    }    }
1290    
1291  /* Find the minimum length of subject string. */  /* Find the minimum length of subject string. */
1292    
1293  switch(min = find_minlength(code, code, re->options, &had_accept, 0))  switch(min = find_minlength(code, code, re->options, &had_accept, 0))
1294    {    {
1295    case -2: *errorptr = "internal error: missing capturing bracket"; break;    case -2: *errorptr = "internal error: missing capturing bracket"; return NULL;
1296    case -3: *errorptr = "internal error: opcode not recognized"; break;    case -3: *errorptr = "internal error: opcode not recognized"; return NULL;
1297    default: break;    default: break;
1298    }    }
1299    
1300  /* Return NULL if there's been an (internal) error or if no optimization is  /* If a set of starting bytes has been identified, or if the minimum length is
1301  possible. A FALSE setting for bits_set is common when there are no obvious  greater than zero, or if JIT optimization has been requested, get a pcre_extra
1302  starting bytes. However a negative value of min occurs only when the pattern  block and a pcre_study_data block. The study data is put in the latter, which
1303  contains \C, in other words, it's an exceptional case nowadays. */  is pointed to by the former, which may also get additional data set later by
1304    the calling program. At the moment, the size of pcre_study_data is fixed. We
1305  if (*errorptr != NULL || (!bits_set && min < 0)) return NULL;  nevertheless save it in a field for returning via the pcre_fullinfo() function
1306    so that if it becomes variable in the future, we don't have to change that
1307  /* Get a pcre_extra block and a pcre_study_data block. The study data is put in  code. */
 the latter, which is pointed to by the former, which may also get additional  
 data set later by the calling program. At the moment, the size of  
 pcre_study_data is fixed. We nevertheless save it in a field for returning via  
 the pcre_fullinfo() function so that if it becomes variable in the future, we  
 don't have to change that code. */  
1308    
1309  extra = (pcre_extra *)(pcre_malloc)  if (bits_set || min > 0
1310    (sizeof(pcre_extra) + sizeof(pcre_study_data));  #ifdef SUPPORT_JIT
1311        || (options & PCRE_STUDY_JIT_COMPILE) != 0
1312  if (extra == NULL)  #endif
1313    {    )
   *errorptr = "failed to get memory";  
   return NULL;  
   }  
   
 study = (pcre_study_data *)((char *)extra + sizeof(pcre_extra));  
 extra->flags = PCRE_EXTRA_STUDY_DATA;  
 extra->study_data = study;  
   
 study->size = sizeof(pcre_study_data);  
 study->flags = 0;  
   
 if (bits_set)  
1314    {    {
1315    study->flags |= PCRE_STUDY_MAPPED;    extra = (pcre_extra *)(pcre_malloc)
1316    memcpy(study->start_bits, start_bits, sizeof(start_bits));      (sizeof(pcre_extra) + sizeof(pcre_study_data));
1317    }    if (extra == NULL)
1318        {
1319        *errorptr = "failed to get memory";
1320        return NULL;
1321        }
1322    
1323      study = (pcre_study_data *)((char *)extra + sizeof(pcre_extra));
1324      extra->flags = PCRE_EXTRA_STUDY_DATA;
1325      extra->study_data = study;
1326    
1327      study->size = sizeof(pcre_study_data);
1328      study->flags = 0;
1329    
1330      if (bits_set)
1331        {
1332        study->flags |= PCRE_STUDY_MAPPED;
1333        memcpy(study->start_bits, start_bits, sizeof(start_bits));
1334        }
1335    
1336      /* Always set the minlength value in the block, because the JIT compiler
1337      makes use of it. However, don't set the bit unless the length is greater than
1338      zero - the interpretive pcre_exec() and pcre_dfa_exec() needn't waste time
1339      checking this case. */
1340    
 if (min >= 0)  
   {  
   study->flags |= PCRE_STUDY_MINLEN;  
1341    study->minlength = min;    study->minlength = min;
1342    }    if (min > 0) study->flags |= PCRE_STUDY_MINLEN;
1343    
1344  /* If JIT support was compiled and requested, attempt the JIT compilation. */    /* If JIT support was compiled and requested, attempt the JIT compilation.
1345      If no starting bytes were found, and the minimum length is zero, and JIT
1346      compilation fails, abandon the extra block and return NULL. */
1347    
 extra->executable_jit = NULL;  
1348  #ifdef SUPPORT_JIT  #ifdef SUPPORT_JIT
1349  if ((options & PCRE_STUDY_JIT_COMPILE) != 0) _pcre_jit_compile(re, extra);    extra->executable_jit = NULL;
1350      if ((options & PCRE_STUDY_JIT_COMPILE) != 0) _pcre_jit_compile(re, extra);
1351      if (study->flags == 0 && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) == 0)
1352        {
1353        pcre_free_study(extra);
1354        extra = NULL;
1355        }
1356  #endif  #endif
1357      }
1358    
1359  return extra;  return extra;
1360  }  }
# Line 1360  PCRE_EXP_DEFN void Line 1374  PCRE_EXP_DEFN void
1374  pcre_free_study(pcre_extra *extra)  pcre_free_study(pcre_extra *extra)
1375  {  {
1376  #ifdef SUPPORT_JIT  #ifdef SUPPORT_JIT
1377  if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 &&  if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 &&
1378       extra->executable_jit != NULL)       extra->executable_jit != NULL)
1379    _pcre_jit_free(extra->executable_jit);    _pcre_jit_free(extra->executable_jit);
1380  #endif  #endif

Legend:
Removed from v.673  
changed lines
  Added in v.691

  ViewVC Help
Powered by ViewVC 1.1.5