regex: Don't return from inside a g_once_init_enter/leave block

When using the system PCRE, and it was compiled with incompatible options,
the code was returning from inside a g_once_init_enter/leave block without
calling g_once_init_leave().
This commit is contained in:
Christian Persch 2012-06-07 16:07:04 +02:00
parent 591d41ef1f
commit 93a7867879

View File

@ -1261,7 +1261,7 @@ g_regex_new (const gchar *pattern,
gint erroffset; gint erroffset;
gint errcode; gint errcode;
gboolean optimize = FALSE; gboolean optimize = FALSE;
static gsize initialised; static volatile gsize initialised = 0;
unsigned long int pcre_compile_options; unsigned long int pcre_compile_options;
g_return_val_if_fail (pattern != NULL, NULL); g_return_val_if_fail (pattern != NULL, NULL);
@ -1271,30 +1271,26 @@ g_regex_new (const gchar *pattern,
if (g_once_init_enter (&initialised)) if (g_once_init_enter (&initialised))
{ {
gint support; int supports_utf8, supports_ucp;
const gchar *msg;
pcre_config (PCRE_CONFIG_UTF8, &support); pcre_config (PCRE_CONFIG_UTF8, &supports_utf8);
if (!support) if (!supports_utf8)
{ g_critical (_("PCRE library is compiled without UTF8 support"));
msg = N_("PCRE library is compiled without UTF8 support");
g_critical ("%s", msg); pcre_config (PCRE_CONFIG_UNICODE_PROPERTIES, &supports_ucp);
g_set_error_literal (error, G_REGEX_ERROR, G_REGEX_ERROR_COMPILE, gettext (msg)); if (!supports_ucp)
return NULL; g_critical (_("PCRE library is compiled without UTF8 properties support"));
g_once_init_leave (&initialised, supports_utf8 && supports_ucp ? 1 : 2);
} }
pcre_config (PCRE_CONFIG_UNICODE_PROPERTIES, &support); if (G_UNLIKELY (initialised != 1))
if (!support)
{ {
msg = N_("PCRE library is compiled without UTF8 properties support"); g_set_error_literal (error, G_REGEX_ERROR, G_REGEX_ERROR_COMPILE,
g_critical ("%s", msg); _("PCRE library is compiled with incompatible options"));
g_set_error_literal (error, G_REGEX_ERROR, G_REGEX_ERROR_COMPILE, gettext (msg));
return NULL; return NULL;
} }
g_once_init_leave (&initialised, TRUE);
}
/* G_REGEX_OPTIMIZE has the same numeric value of PCRE_NO_UTF8_CHECK, /* G_REGEX_OPTIMIZE has the same numeric value of PCRE_NO_UTF8_CHECK,
* as we do not need to wrap PCRE_NO_UTF8_CHECK. */ * as we do not need to wrap PCRE_NO_UTF8_CHECK. */
if (compile_options & G_REGEX_OPTIMIZE) if (compile_options & G_REGEX_OPTIMIZE)