Commit ad078eb4 authored by Christian Persch's avatar Christian Persch

regex: Check whether PCRE2 was compiled with JIT support

... and only warn once if it was not.
parent 8717ef9d
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment