/[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 659 by ph10, Tue Aug 16 09:48:29 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 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    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    the calling program. At the moment, the size of pcre_study_data is fixed. We
1305    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    code. */
1308    
1309    if (bits_set || min > 0
1310    #ifdef SUPPORT_JIT
1311        || (options & PCRE_STUDY_JIT_COMPILE) != 0
1312    #endif
1313      )
1314      {
1315      extra = (pcre_extra *)(pcre_malloc)
1316        (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    
1341  if (*errorptr != NULL || (!bits_set && min < 0)) return NULL;    study->minlength = min;
1342      if (min > 0) study->flags |= PCRE_STUDY_MINLEN;
 /* Get a pcre_extra block and a pcre_study_data block. The study data is put in  
 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. */  
   
 extra = (pcre_extra *)(pcre_malloc)  
   (sizeof(pcre_extra) + sizeof(pcre_study_data));  
1343    
1344  if (extra == NULL)    /* 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    *errorptr = "failed to get memory";    compilation fails, abandon the extra block and return NULL. */
1347    return NULL;  
1348    #ifdef SUPPORT_JIT
1349      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
1357    }    }
1358    
1359  study = (pcre_study_data *)((char *)extra + sizeof(pcre_extra));  return extra;
1360  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));  
   }  
1361    
 if (min >= 0)  
   {  
   study->flags |= PCRE_STUDY_MINLEN;  
   study->minlength = min;  
   }  
1362    
1363  return extra;  /*************************************************
1364    *          Free the study data                   *
1365    *************************************************/
1366    
1367    /* This function frees the memory that was obtained by pcre_study().
1368    
1369    Argument:   a pointer to the pcre_extra block
1370    Returns:    nothing
1371    */
1372    
1373    PCRE_EXP_DEFN void
1374    pcre_free_study(pcre_extra *extra)
1375    {
1376    #ifdef SUPPORT_JIT
1377    if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 &&
1378         extra->executable_jit != NULL)
1379      _pcre_jit_free(extra->executable_jit);
1380    #endif
1381    pcre_free(extra);
1382  }  }
1383    
1384  /* End of pcre_study.c */  /* End of pcre_study.c */

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

  ViewVC Help
Powered by ViewVC 1.1.5