Bug 677933 - imapx_utils_init() called too early
authorMatthew Barnes <mbarnes@redhat.com>
Tue, 12 Jun 2012 11:50:05 +0000 (07:50 -0400)
committerMatthew Barnes <mbarnes@redhat.com>
Tue, 12 Jun 2012 11:51:15 +0000 (07:51 -0400)
camel/camel-imapx-store.c
camel/camel-imapx-utils.c
camel/providers/imapx/camel-imapx-provider.c

index da71fda..e847402 100644 (file)
@@ -1771,5 +1771,7 @@ camel_imapx_store_init (CamelIMAPXStore *istore)
        istore->last_refresh_time = time (NULL) - (FINFO_REFRESH_INTERVAL + 10);
        istore->dir_sep = '/';
        istore->con_man = camel_imapx_conn_manager_new (CAMEL_STORE (istore));
+
+       imapx_utils_init ();
 }
 
index 0b50d5d..856600a 100644 (file)
@@ -1964,34 +1964,43 @@ guchar imapx_specials[256] = {
 #define token_specials "\n*()[]+"
 #define notid_specials "\x20\r\n()[]+"
 
-void imapx_utils_init (void)
+void
+imapx_utils_init (void)
 {
-       gint i;
-       guchar v;
-
-       for (i = 0; i < 128; i++) {
-               v = 0;
-               if (i >= 1 && i <= 0x7f) {
-                       v |= IMAPX_TYPE_CHAR;
-                       if (i != 0x0a && i != 0x0d) {
-                               v |= IMAPX_TYPE_TEXT_CHAR;
-                               if (i != '"' && i != '\\')
-                                       v |= IMAPX_TYPE_QUOTED_CHAR;
+       static gsize imapx_utils_initialized = 0;
+
+       if (g_once_init_enter (&imapx_utils_initialized)) {
+               gint i;
+               guchar v;
+
+               for (i = 0; i < 128; i++) {
+                       v = 0;
+                       if (i >= 1 && i <= 0x7f) {
+                               v |= IMAPX_TYPE_CHAR;
+                               if (i != 0x0a && i != 0x0d) {
+                                       v |= IMAPX_TYPE_TEXT_CHAR;
+                                       if (i != '"' && i != '\\')
+                                               v |= IMAPX_TYPE_QUOTED_CHAR;
+                               }
+                               if (i> 0x20 && i <0x7f && strchr (atom_specials, i) == NULL)
+                                       v |= IMAPX_TYPE_ATOM_CHAR;
+                               if (strchr (token_specials, i) != NULL)
+                                       v |= IMAPX_TYPE_TOKEN_CHAR;
+                               if (strchr (notid_specials, i) != NULL)
+                                       v |= IMAPX_TYPE_NOTID_CHAR;
                        }
-                       if (i> 0x20 && i <0x7f && strchr (atom_specials, i) == NULL)
-                               v |= IMAPX_TYPE_ATOM_CHAR;
-                       if (strchr (token_specials, i) != NULL)
-                               v |= IMAPX_TYPE_TOKEN_CHAR;
-                       if (strchr (notid_specials, i) != NULL)
-                               v |= IMAPX_TYPE_NOTID_CHAR;
+
+                       imapx_specials[i] = v;
                }
 
-               imapx_specials[i] = v;
+               camel_imapx_set_debug_flags ();
+
+               g_once_init_leave (&imapx_utils_initialized, 1);
        }
-       camel_imapx_set_debug_flags ();
 }
 
-guchar imapx_is_mask (const gchar *p)
+guchar
+imapx_is_mask (const gchar *p)
 {
        guchar v = 0xff;
 
index 649c346..427197b 100644 (file)
@@ -115,9 +115,6 @@ camel_imapx_module_init (void)
        imapx_provider.authtypes = g_list_prepend (imapx_provider.authtypes, &camel_imapx_password_authtype);
        imapx_provider.translation_domain = GETTEXT_PACKAGE;
 
-       /* TEMPORARY */
-       imapx_utils_init ();
-
        camel_provider_register (&imapx_provider);
 }