/[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 687 by ph10, Thu Aug 25 16:06:03 2011 UTC revision 688 by ph10, Fri Sep 9 09:35:48 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)  
   {  
   study->flags |= PCRE_STUDY_MAPPED;  
   memcpy(study->start_bits, start_bits, sizeof(start_bits));  
   }  
   
 if (min >= 0)  
1314    {    {
1315    study->flags |= PCRE_STUDY_MINLEN;    extra = (pcre_extra *)(pcre_malloc)
1316    study->minlength = min;      (sizeof(pcre_extra) + sizeof(pcre_study_data));
1317    }    if (extra == NULL)
1318        {
1319  /* If JIT support was compiled and requested, attempt the JIT compilation. */      *errorptr = "failed to get memory";
1320        return NULL;
1321  extra->executable_jit = NULL;      }
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      if (min > 0)
1337        {
1338        study->flags |= PCRE_STUDY_MINLEN;
1339        study->minlength = min;
1340        }
1341    
1342      /* If JIT support was compiled and requested, attempt the JIT compilation.
1343      If no starting bytes were found, and the minimum length is zero, and JIT
1344      compilation fails, no flags will be set, so abandon the extra block and
1345      return NULL. */
1346    
1347  #ifdef SUPPORT_JIT  #ifdef SUPPORT_JIT
1348  if ((options & PCRE_STUDY_JIT_COMPILE) != 0) _pcre_jit_compile(re, extra);    extra->executable_jit = NULL;
1349      if ((options & PCRE_STUDY_JIT_COMPILE) != 0) _pcre_jit_compile(re, extra);
1350      if (study->flags == 0)
1351        {
1352        pcre_free_study(extra);
1353        extra = NULL;
1354        }
1355  #endif  #endif
1356      }
1357    
1358  return extra;  return extra;
1359  }  }

Legend:
Removed from v.687  
changed lines
  Added in v.688

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12