[vte] regex: Check whether PCRE2 was compiled with JIT support
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] regex: Check whether PCRE2 was compiled with JIT support
- Date: Fri, 2 Nov 2018 19:28:10 +0000 (UTC)
commit ad078eb4fec6ba5ec7c2c220fe987b45f87798eb
Author: Christian Persch <chpe src gnome org>
Date: Fri Nov 2 20:27:20 2018 +0100
regex: Check whether PCRE2 was compiled with JIT support
... and only warn once if it was not.
src/vteregex.cc | 48 ++++++++++++++++++++++++++++++++++++++----------
1 file changed, 38 insertions(+), 10 deletions(-)
---
diff --git a/src/vteregex.cc b/src/vteregex.cc
index 7f6fb904..01ccfb99 100644
--- a/src/vteregex.cc
+++ b/src/vteregex.cc
@@ -152,6 +152,36 @@ vte_regex_unref(VteRegex *regex)
return NULL;
}
+static gboolean
+check_pcre_config_unicode(GError** error)
+{
+ /* Check library compatibility */
+ guint32 v;
+ int r = pcre2_config_8(PCRE2_CONFIG_UNICODE, &v);
+ if (r != 0 || v != 1) {
+ g_set_error(error, VTE_REGEX_ERROR, VTE_REGEX_ERROR_INCOMPATIBLE,
+ "PCRE2 library was built without unicode support");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+check_pcre_config_jit(void)
+{
+ static gboolean warned = FALSE;
+
+ char s[256];
+ int r = pcre2_config_8(PCRE2_CONFIG_JITTARGET, &s);
+ if (r == PCRE2_ERROR_BADOPTION && !warned) {
+ g_printerr("PCRE2 library was built without JIT support\n");
+ warned = TRUE;
+ }
+
+ return r >= 1;
+}
+
static VteRegex *
vte_regex_new(VteRegexPurpose purpose,
const char *pattern,
@@ -160,21 +190,15 @@ vte_regex_new(VteRegexPurpose purpose,
GError **error)
{
pcre2_code_8 *code;
- int r, errcode;
- guint32 v;
+ int errcode;
PCRE2_SIZE erroffset;
g_return_val_if_fail(pattern != NULL, NULL);
g_return_val_if_fail(pattern_length >= -1, NULL);
g_return_val_if_fail(error == NULL || *error == NULL, NULL);
- /* Check library compatibility */
- r = pcre2_config_8(PCRE2_CONFIG_UNICODE, &v);
- if (r != 0 || v != 1) {
- g_set_error(error, VTE_REGEX_ERROR, VTE_REGEX_ERROR_INCOMPATIBLE,
- "PCRE2 library was built without unicode support");
- return NULL;
- }
+ if (!check_pcre_config_unicode(error))
+ return FALSE;
code = pcre2_compile_8((PCRE2_SPTR8)pattern,
pattern_length >= 0 ? pattern_length : PCRE2_ZERO_TERMINATED,
@@ -375,7 +399,8 @@ _vte_regex_get_pcre(VteRegex *regex)
*
* If the platform supports JITing, JIT compiles @regex.
*
- * Returns: %TRUE if JITing succeeded, or %FALSE with @error filled in
+ * Returns: %TRUE if JITing succeeded (or PCRE2 was built without
+ * JIT support), or %FALSE with @error filled in
*/
gboolean
vte_regex_jit(VteRegex *regex,
@@ -386,6 +411,9 @@ vte_regex_jit(VteRegex *regex,
g_return_val_if_fail(regex != NULL, FALSE);
+ if (!check_pcre_config_jit())
+ return TRUE;
+
r = pcre2_jit_compile_8(regex->code, flags);
if (r < 0)
return set_gerror_from_pcre_error(r, error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]