[glib/no-more-regex] Deprecate GRegex
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/no-more-regex] Deprecate GRegex
- Date: Tue, 14 Apr 2020 19:27:25 +0000 (UTC)
commit 40553217de3a661ed6097c4204173c5b41aad9fa
Author: Emmanuele Bassi <ebassi gnome org>
Date: Tue Apr 14 20:18:51 2020 +0100
Deprecate GRegex
GRegex is based off of PCRE1, and cannot be moved to PCRE2 without
breaking its API contract. PCRE1 is in maintenance mode, and will not
see any new feature.
GRegex made sense back in the day when we embedded a copy of PCRE, but:
- the maintenance burden required to update the copy of PCRE to keep up
with upstream, coupled with the lack of synchronisation between GLib
and PCRE releases, has become too high
- downstream distributors try very hard to not rely on vendored
dependencies, which meant that GLib depended on a system copy of PCRE
anyway, except on certain platforms, which made for interesting bugs
- regular expressions are a niche use case, and PCRE is already
portable to all the platforms GLib cares about
Thus, we recommend users to migrate their code from GRegex to PCRE2.
Fixes: #1085
gio/gsettingsschema.c | 4 ++
glib/gregex.c | 10 +++--
glib/gregex.h | 107 +++++++++++++++++++++++++++++---------------------
glib/tests/autoptr.c | 4 ++
glib/tests/regex.c | 2 +
5 files changed, 79 insertions(+), 48 deletions(-)
---
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index 0b94f76f6..781111cea 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -547,6 +547,8 @@ start_element (GMarkupParseContext *context,
static gchar *
normalise_whitespace (const gchar *orig)
{
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
/* We normalise by the same rules as in intltool:
*
* sub cleanup {
@@ -595,6 +597,8 @@ normalise_whitespace (const gchar *orig)
lines[i] = c;
}
+ G_GNUC_END_IGNORE_DEPRECATIONS
+
result = g_strjoinv ("\n\n", lines);
g_strfreev (lines);
diff --git a/glib/gregex.c b/glib/gregex.c
index cef091ed9..f4823907e 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -18,6 +18,9 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
+/* Yes, we're using deprecated API */
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
#include "config.h"
#include <string.h>
@@ -105,9 +108,10 @@
* is not threadsafe.
*
* The regular expressions low-level functionalities are obtained through
- * the excellent
- * [PCRE](http://www.pcre.org/)
- * library written by Philip Hazel.
+ * the excellent [PCRE](http://www.pcre.org/) library written by Philip Hazel.
+ *
+ * The GRegex API is deprecated since GLib 2.66, as it wraps the old PCRE 1
+ * API; newly written code should use the PCRE 2 API.
*/
/* Mask of all the possible values for GRegexCompileFlags. */
diff --git a/glib/gregex.h b/glib/gregex.h
index 45e198df6..5dcd54e0b 100644
--- a/glib/gregex.h
+++ b/glib/gregex.h
@@ -136,6 +136,7 @@ G_BEGIN_DECLS
* Error codes returned by regular expressions functions.
*
* Since: 2.14
+ * Deprecated: 2.66: Use pcre2 instead
*/
typedef enum
{
@@ -198,7 +199,7 @@ typedef enum
G_REGEX_ERROR_TOO_MANY_FORWARD_REFERENCES = 172,
G_REGEX_ERROR_NAME_TOO_LONG = 175,
G_REGEX_ERROR_CHARACTER_VALUE_TOO_LARGE = 176
-} GRegexError;
+} GRegexError GLIB_DEPRECATED_TYPE_IN_2_66;
/**
* G_REGEX_ERROR:
@@ -211,7 +212,7 @@ typedef enum
*/
#define G_REGEX_ERROR g_regex_error_quark ()
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
GQuark g_regex_error_quark (void);
/**
@@ -289,6 +290,8 @@ GQuark g_regex_error_quark (void);
* Flags specifying compile-time options.
*
* Since: 2.14
+ *
+ * Deprecated: 2.66: Use pcre2 instead
*/
/* Remember to update G_REGEX_COMPILE_MASK in gregex.c after
* adding a new flag.
@@ -313,7 +316,7 @@ typedef enum
G_REGEX_NEWLINE_ANYCRLF = G_REGEX_NEWLINE_CR | 1 << 22,
G_REGEX_BSR_ANYCRLF = 1 << 23,
G_REGEX_JAVASCRIPT_COMPAT = 1 << 25
-} GRegexCompileFlags;
+} GRegexCompileFlags GLIB_DEPRECATED_TYPE_IN_2_66;
/**
* GRegexMatchFlags:
@@ -380,6 +383,8 @@ typedef enum
* Flags specifying match-time options.
*
* Since: 2.14
+ *
+ * Deprecated: 2.66: Use pcre2 instead
*/
/* Remember to update G_REGEX_MATCH_MASK in gregex.c after
* adding a new flag. */
@@ -400,7 +405,7 @@ typedef enum
G_REGEX_MATCH_PARTIAL_SOFT = G_REGEX_MATCH_PARTIAL,
G_REGEX_MATCH_PARTIAL_HARD = 1 << 27,
G_REGEX_MATCH_NOTEMPTY_ATSTART = 1 << 28
-} GRegexMatchFlags;
+} GRegexMatchFlags GLIB_DEPRECATED_TYPE_IN_2_66;
/**
* GRegex:
@@ -409,8 +414,10 @@ typedef enum
* This structure is opaque and its fields cannot be accessed directly.
*
* Since: 2.14
+ *
+ * Deprecated: 2.66: Use pcre2 instead
*/
-typedef struct _GRegex GRegex;
+typedef struct _GRegex GRegex GLIB_DEPRECATED_TYPE_IN_2_66;
/**
@@ -418,8 +425,14 @@ typedef struct _GRegex GRegex;
*
* A GMatchInfo is an opaque struct used to return information about
* matches.
+ *
+ * Since: 2.14
+ *
+ * Deprecated: 2.66: Use pcre2 instead
*/
-typedef struct _GMatchInfo GMatchInfo;
+typedef struct _GMatchInfo GMatchInfo GLIB_DEPRECATED_TYPE_IN_2_66;
+
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GRegexEvalCallback:
@@ -437,58 +450,60 @@ typedef struct _GMatchInfo GMatchInfo;
* Returns: %FALSE to continue the replacement process, %TRUE to stop it
*
* Since: 2.14
+ *
+ * Deprecated: 2.66: Use pcre2 instead
*/
typedef gboolean (*GRegexEvalCallback) (const GMatchInfo *match_info,
GString *result,
gpointer user_data);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
GRegex *g_regex_new (const gchar *pattern,
GRegexCompileFlags compile_options,
GRegexMatchFlags match_options,
GError **error);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
GRegex *g_regex_ref (GRegex *regex);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
void g_regex_unref (GRegex *regex);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
const gchar *g_regex_get_pattern (const GRegex *regex);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gint g_regex_get_max_backref (const GRegex *regex);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gint g_regex_get_capture_count (const GRegex *regex);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_regex_get_has_cr_or_lf (const GRegex *regex);
GLIB_AVAILABLE_IN_2_38
gint g_regex_get_max_lookbehind (const GRegex *regex);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gint g_regex_get_string_number (const GRegex *regex,
const gchar *name);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar *g_regex_escape_string (const gchar *string,
gint length);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar *g_regex_escape_nul (const gchar *string,
gint length);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
GRegexCompileFlags g_regex_get_compile_flags (const GRegex *regex);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
GRegexMatchFlags g_regex_get_match_flags (const GRegex *regex);
/* Matching. */
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_regex_match_simple (const gchar *pattern,
const gchar *string,
GRegexCompileFlags compile_options,
GRegexMatchFlags match_options);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_regex_match (const GRegex *regex,
const gchar *string,
GRegexMatchFlags match_options,
GMatchInfo **match_info);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_regex_match_full (const GRegex *regex,
const gchar *string,
gssize string_len,
@@ -496,12 +511,12 @@ gboolean g_regex_match_full (const GRegex *regex,
GRegexMatchFlags match_options,
GMatchInfo **match_info,
GError **error);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_regex_match_all (const GRegex *regex,
const gchar *string,
GRegexMatchFlags match_options,
GMatchInfo **match_info);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_regex_match_all_full (const GRegex *regex,
const gchar *string,
gssize string_len,
@@ -511,16 +526,16 @@ gboolean g_regex_match_all_full (const GRegex *regex,
GError **error);
/* String splitting. */
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar **g_regex_split_simple (const gchar *pattern,
const gchar *string,
GRegexCompileFlags compile_options,
GRegexMatchFlags match_options);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar **g_regex_split (const GRegex *regex,
const gchar *string,
GRegexMatchFlags match_options);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar **g_regex_split_full (const GRegex *regex,
const gchar *string,
gssize string_len,
@@ -530,7 +545,7 @@ gchar **g_regex_split_full (const GRegex *regex,
GError **error);
/* String replacement. */
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar *g_regex_replace (const GRegex *regex,
const gchar *string,
gssize string_len,
@@ -538,7 +553,7 @@ gchar *g_regex_replace (const GRegex *regex,
const gchar *replacement,
GRegexMatchFlags match_options,
GError **error);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar *g_regex_replace_literal (const GRegex *regex,
const gchar *string,
gssize string_len,
@@ -546,7 +561,7 @@ gchar *g_regex_replace_literal (const GRegex *regex,
const gchar *replacement,
GRegexMatchFlags match_options,
GError **error);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar *g_regex_replace_eval (const GRegex *regex,
const gchar *string,
gssize string_len,
@@ -555,55 +570,57 @@ gchar *g_regex_replace_eval (const GRegex *regex,
GRegexEvalCallback eval,
gpointer user_data,
GError **error);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_regex_check_replacement (const gchar *replacement,
gboolean *has_references,
GError **error);
/* Match info */
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
GRegex *g_match_info_get_regex (const GMatchInfo *match_info);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
const gchar *g_match_info_get_string (const GMatchInfo *match_info);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
GMatchInfo *g_match_info_ref (GMatchInfo *match_info);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
void g_match_info_unref (GMatchInfo *match_info);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
void g_match_info_free (GMatchInfo *match_info);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_match_info_next (GMatchInfo *match_info,
GError **error);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_match_info_matches (const GMatchInfo *match_info);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gint g_match_info_get_match_count (const GMatchInfo *match_info);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_match_info_is_partial_match (const GMatchInfo *match_info);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar *g_match_info_expand_references(const GMatchInfo *match_info,
const gchar *string_to_expand,
GError **error);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar *g_match_info_fetch (const GMatchInfo *match_info,
gint match_num);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_match_info_fetch_pos (const GMatchInfo *match_info,
gint match_num,
gint *start_pos,
gint *end_pos);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar *g_match_info_fetch_named (const GMatchInfo *match_info,
const gchar *name);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gboolean g_match_info_fetch_named_pos (const GMatchInfo *match_info,
const gchar *name,
gint *start_pos,
gint *end_pos);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_66
gchar **g_match_info_fetch_all (const GMatchInfo *match_info);
+G_GNUC_END_IGNORE_DEPRECATIONS
+
G_END_DECLS
#endif /* __G_REGEX_H__ */
diff --git a/glib/tests/autoptr.c b/glib/tests/autoptr.c
index cd510ed16..169fcec12 100644
--- a/glib/tests/autoptr.c
+++ b/glib/tests/autoptr.c
@@ -291,18 +291,22 @@ test_g_rand (void)
static void
test_g_regex (void)
{
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_autoptr(GRegex) val = g_regex_new (".*", 0, 0, NULL);
g_assert_nonnull (val);
+ G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
test_g_match_info (void)
{
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_autoptr(GRegex) regex = g_regex_new (".*", 0, 0, NULL);
g_autoptr(GMatchInfo) match = NULL;
if (!g_regex_match (regex, "hello", 0, &match))
g_assert_not_reached ();
+ G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index 56bd2d5eb..cd038e657 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -19,6 +19,8 @@
#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
#include "config.h"
#include <string.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]