[Pcre-svn] [688] code/trunk: Tidy up interface from pcre_stu…

トップ ページ
このメッセージを削除
著者: Subversion repository
日付:  
To: pcre-svn
題目: [Pcre-svn] [688] code/trunk: Tidy up interface from pcre_study() to JIT, and ignore a minimum length of 0.
Revision: 688
          http://vcs.pcre.org/viewvc?view=rev&revision=688
Author:   ph10
Date:     2011-09-09 10:35:48 +0100 (Fri, 09 Sep 2011)


Log Message:
-----------
Tidy up interface from pcre_study() to JIT, and ignore a minimum length of 0.

Modified Paths:
--------------
    code/trunk/pcre_jit_compile.c
    code/trunk/pcre_study.c
    code/trunk/testdata/testoutput13


Modified: code/trunk/pcre_jit_compile.c
===================================================================
--- code/trunk/pcre_jit_compile.c    2011-09-06 16:09:43 UTC (rev 687)
+++ code/trunk/pcre_jit_compile.c    2011-09-09 09:35:48 UTC (rev 688)
@@ -5940,7 +5940,7 @@
 compiler_common common_data;
 compiler_common *common = &common_data;
 const unsigned char *tables = re->tables;
-pcre_study_data *study = (extra->flags & PCRE_EXTRA_STUDY_DATA) != 0 ? extra->study_data : NULL;
+pcre_study_data *study;
 uschar *ccend;
 executable_function *function;
 void *executable_func;
@@ -5952,6 +5952,9 @@
 struct sljit_jump *reqbyte_notfound = NULL;
 struct sljit_jump *empty_match;


+SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);
+study = extra->study_data;
+
if (!tables)
tables = _pcre_default_tables;


Modified: code/trunk/pcre_study.c
===================================================================
--- code/trunk/pcre_study.c    2011-09-06 16:09:43 UTC (rev 687)
+++ code/trunk/pcre_study.c    2011-09-09 09:35:48 UTC (rev 688)
@@ -1230,7 +1230,7 @@
 BOOL bits_set = FALSE;
 BOOL had_accept = FALSE;
 uschar start_bits[32];
-pcre_extra *extra;
+pcre_extra *extra = NULL;
 pcre_study_data *study;
 const uschar *tables;
 uschar *code;
@@ -1281,66 +1281,79 @@
   rc = set_start_bits(code, start_bits, (re->options & PCRE_UTF8) != 0,
     &compile_block);
   bits_set = rc == SSB_DONE;
-  if (rc == SSB_UNKNOWN) *errorptr = "internal error: opcode not recognized";
+  if (rc == SSB_UNKNOWN) 
+    {
+    *errorptr = "internal error: opcode not recognized";
+    return NULL;
+    }  
   }


/* Find the minimum length of subject string. */

switch(min = find_minlength(code, code, re->options, &had_accept, 0))
{
- case -2: *errorptr = "internal error: missing capturing bracket"; break;
- case -3: *errorptr = "internal error: opcode not recognized"; break;
+ case -2: *errorptr = "internal error: missing capturing bracket"; return NULL;
+ case -3: *errorptr = "internal error: opcode not recognized"; return NULL;
default: break;
}

-/* Return NULL if there's been an (internal) error or if no optimization is
-possible. A FALSE setting for bits_set is common when there are no obvious
-starting bytes. However a negative value of min occurs only when the pattern
-contains \C, in other words, it's an exceptional case nowadays. */
+/* If a set of starting bytes has been identified, or if the minimum length is
+greater than zero, or if JIT optimization has been requested, 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. */

-if (*errorptr != NULL || (!bits_set && min < 0)) return NULL;
-
-/* 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));
-
-if (extra == NULL)
+if (bits_set || min > 0 
+#ifdef SUPPORT_JIT
+    || (options & PCRE_STUDY_JIT_COMPILE) != 0
+#endif
+  )
   {
-  *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)
-  {
-  study->flags |= PCRE_STUDY_MINLEN;
-  study->minlength = min;
-  }
-
-/* If JIT support was compiled and requested, attempt the JIT compilation. */
-
-extra->executable_jit = NULL;
+  extra = (pcre_extra *)(pcre_malloc)
+    (sizeof(pcre_extra) + sizeof(pcre_study_data));
+  if (extra == NULL)
+    {
+    *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)
+    {
+    study->flags |= PCRE_STUDY_MINLEN;
+    study->minlength = min;
+    }
+  
+  /* If JIT support was compiled and requested, attempt the JIT compilation.
+  If no starting bytes were found, and the minimum length is zero, and JIT
+  compilation fails, no flags will be set, so abandon the extra block and 
+  return NULL. */
+  
 #ifdef SUPPORT_JIT
-if ((options & PCRE_STUDY_JIT_COMPILE) != 0) _pcre_jit_compile(re, extra);
+  extra->executable_jit = NULL;
+  if ((options & PCRE_STUDY_JIT_COMPILE) != 0) _pcre_jit_compile(re, extra);
+  if (study->flags == 0)
+    {
+    pcre_free_study(extra);
+    extra = NULL;
+    }     
 #endif
+  }


return extra;
}

Modified: code/trunk/testdata/testoutput13
===================================================================
--- code/trunk/testdata/testoutput13    2011-09-06 16:09:43 UTC (rev 687)
+++ code/trunk/testdata/testoutput13    2011-09-09 09:35:48 UTC (rev 688)
@@ -1064,8 +1064,7 @@
 No options
 No first char
 No need char
-Subject length lower bound = 0
-No set of starting bytes
+Study returned NULL


/\p{Lu}+9\p{Lu}+B\p{Lu}+b/BZ
------------------------------------------------------------------