/[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 657 by ph10, Mon Aug 15 17:39:09 2011 UTC revision 688 by ph10, Fri Sep 9 09:35:48 2011 UTC
# Line 794  do Line 794  do
794        return SSB_FAIL;        return SSB_FAIL;
795    
796        /* We can ignore word boundary tests. */        /* We can ignore word boundary tests. */
797    
798        case OP_WORD_BOUNDARY:        case OP_WORD_BOUNDARY:
799        case OP_NOT_WORD_BOUNDARY:        case OP_NOT_WORD_BOUNDARY:
800        tcode++;        tcode++;
801        break;        break;
802    
803        /* If we hit a bracket or a positive lookahead assertion, recurse to set        /* If we hit a bracket or a positive lookahead assertion, recurse to set
804        bits from within the subpattern. If it can't find anything, we have to        bits from within the subpattern. If it can't find anything, we have to
# 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 error or if no optimization is possible. */  /* If a set of starting bytes has been identified, or if the minimum length is
1301    greater than zero, or if JIT optimization has been requested, get a pcre_extra
1302  if (*errorptr != NULL || (!bits_set && min < 0)) return NULL;  block and a pcre_study_data block. The study data is put in the latter, which
1303    is pointed to by the former, which may also get additional data set later by
1304  /* Get a pcre_extra block and a pcre_study_data block. The study data is put in  the calling program. At the moment, the size of pcre_study_data is fixed. We
1305  the latter, which is pointed to by the former, which may also get additional  nevertheless save it in a field for returning via the pcre_fullinfo() function
1306  data set later by the calling program. At the moment, the size of  so that if it becomes variable in the future, we don't have to change that
1307  pcre_study_data is fixed. We nevertheless save it in a field for returning via  code. */
1308  the pcre_fullinfo() function so that if it becomes variable in the future, we  
1309  don't have to change that code. */  if (bits_set || min > 0
1310    #ifdef SUPPORT_JIT
1311  extra = (pcre_extra *)(pcre_malloc)      || (options & PCRE_STUDY_JIT_COMPILE) != 0
1312    (sizeof(pcre_extra) + sizeof(pcre_study_data));  #endif
1313      )
 if (extra == NULL)  
1314    {    {
1315    *errorptr = "failed to get memory";    extra = (pcre_extra *)(pcre_malloc)
1316    return NULL;      (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      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
1348      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
1356    }    }
1357    
1358  study = (pcre_study_data *)((char *)extra + sizeof(pcre_extra));  return extra;
1359  extra->flags = PCRE_EXTRA_STUDY_DATA;  }
 extra->study_data = study;  
1360    
 study->size = sizeof(pcre_study_data);  
 study->flags = 0;  
1361    
1362  if (bits_set)  /*************************************************
1363    {  *          Free the study data                   *
1364    study->flags |= PCRE_STUDY_MAPPED;  *************************************************/
   memcpy(study->start_bits, start_bits, sizeof(start_bits));  
   }  
1365    
1366  if (min >= 0)  /* This function frees the memory that was obtained by pcre_study().
   {  
   study->flags |= PCRE_STUDY_MINLEN;  
   study->minlength = min;  
   }  
1367    
1368  return extra;  Argument:   a pointer to the pcre_extra block
1369    Returns:    nothing
1370    */
1371    
1372    PCRE_EXP_DEFN void
1373    pcre_free_study(pcre_extra *extra)
1374    {
1375    #ifdef SUPPORT_JIT
1376    if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 &&
1377         extra->executable_jit != NULL)
1378      _pcre_jit_free(extra->executable_jit);
1379    #endif
1380    pcre_free(extra);
1381  }  }
1382    
1383  /* End of pcre_study.c */  /* End of pcre_study.c */

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

  ViewVC Help
Powered by ViewVC 1.1.5