[glib/wip/pcre-update: 15/20] regex: Don't leak internal PCRE options



commit 407d5787ea4e3c6867ab6c1f6ba6efa6588e6810
Author: Christian Persch <chpe gnome org>
Date:   Thu Jun 7 18:11:49 2012 +0200

    regex: Don't leak internal PCRE options
    
    g_regex_get_compile_get_compile_flags() and g_regex_get_match_flags()
    were leaking PCRE flags that don't exist in the corresponding
    public GRegexCompileFlags and GRegexMatchFlags; this change masks
    these internal flags.

 glib/gregex.c      |   17 +++++++++--------
 glib/tests/regex.c |   10 ++--------
 2 files changed, 11 insertions(+), 16 deletions(-)
---
diff --git a/glib/gregex.c b/glib/gregex.c
index a0aee80..dcecc5d 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -161,12 +161,12 @@ G_STATIC_ASSERT (G_REGEX_MATCH_BSR_ANY         == PCRE_BSR_UNICODE);
 
 /* if the string is in UTF-8 use g_utf8_ functions, else use
  * use just +/- 1. */
-#define NEXT_CHAR(re, s) (((re)->compile_opts & PCRE_UTF8) ? \
-                                g_utf8_next_char (s) : \
-                                ((s) + 1))
-#define PREV_CHAR(re, s) (((re)->compile_opts & PCRE_UTF8) ? \
-                                g_utf8_prev_char (s) : \
-                                ((s) - 1))
+#define NEXT_CHAR(re, s) (((re)->compile_opts & G_REGEX_RAW) ? \
+                                ((s) + 1) : \
+                                g_utf8_next_char (s))
+#define PREV_CHAR(re, s) (((re)->compile_opts & G_REGEX_RAW) ? \
+                                ((s) - 1) : \
+                                g_utf8_prev_char (s))
 
 struct _GMatchInfo
 {
@@ -1269,6 +1269,7 @@ g_regex_new (const gchar         *pattern,
   gboolean optimize = FALSE;
   static volatile gsize initialised = 0;
   unsigned long int pcre_compile_options;
+  GRegexCompileFlags original_compile_options = compile_options;
 
   g_return_val_if_fail (pattern != NULL, NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -1362,7 +1363,7 @@ g_regex_new (const gchar         *pattern,
    * compile options, e.g. "(?i)foo" will make the pcre structure store
    * PCRE_CASELESS even though it wasn't explicitly given for compilation. */
   pcre_fullinfo (re, NULL, PCRE_INFO_OPTIONS, &pcre_compile_options);
-  compile_options = pcre_compile_options;
+  compile_options = original_compile_options;
 
   if (!(compile_options & G_REGEX_DUPNAMES))
     {
@@ -1517,7 +1518,7 @@ g_regex_get_match_flags (const GRegex *regex)
 {
   g_return_val_if_fail (regex != NULL, 0);
 
-  return regex->match_opts;
+  return regex->match_opts & G_REGEX_MATCH_MASK;
 }
 
 /**
diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index ea178a5..598aebf 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -1362,12 +1362,6 @@ test_match_all (gconstpointer d)
   }                                                                     \
 }
 
-#define PCRE_UTF8               0x00000800
-#define PCRE_NO_UTF8_CHECK      0x00002000
-#define PCRE_NEWLINE_ANY        0x00400000
-#define PCRE_UCP                0x20000000
-#define PCRE_BSR_UNICODE        0x01000000
-
 static void
 test_basic (void)
 {
@@ -1378,8 +1372,8 @@ test_basic (void)
   regex = g_regex_new ("[A-Z]+", cflags, mflags, NULL);
 
   g_assert (regex != NULL);
-  g_assert_cmpint (g_regex_get_compile_flags (regex), ==, cflags|PCRE_UTF8|PCRE_NO_UTF8_CHECK|PCRE_NEWLINE_ANY|PCRE_UCP|PCRE_BSR_UNICODE);
-  g_assert_cmpint (g_regex_get_match_flags (regex), ==, mflags|PCRE_NO_UTF8_CHECK);
+  g_assert_cmphex (g_regex_get_compile_flags (regex), ==, cflags);
+  g_assert_cmphex (g_regex_get_match_flags (regex), ==, mflags);
 
   g_regex_unref (regex);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]