This is slightly more tidy, but more importantly it allows for re-use
of this code in n_d_create_with_config
---
lib/open.cc | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/lib/open.cc b/lib/open.cc
index 09fec6e4..ff298030 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -200,6 +200,22 @@ notmuch_database_t * _alloc_notmuch() {
return notmuch;
}
+static void _init_libs () {
+
+ static int initialized = 0;
+
+ /* Initialize the GLib type system and threads */
+#if ! GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+
+ /* Initialize gmime */
+ if (! initialized) {
+ g_mime_init ();
+ initialized = 1;
+ }
+}
+
notmuch_status_t
notmuch_database_open_with_config (const char *database_path,
notmuch_database_mode_t mode,
@@ -219,6 +235,8 @@ notmuch_database_open_with_config (const char *database_path,
GKeyFile *key_file = NULL;
static int initialized = 0;
+ _init_libs ();
+
notmuch = _alloc_notmuch ();
if (!notmuch) {
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
@@ -251,17 +269,6 @@ notmuch_database_open_with_config (const char *database_path,
goto DONE;
}
- /* Initialize the GLib type system and threads */
-#if ! GLIB_CHECK_VERSION (2, 35, 1)
- g_type_init ();
-#endif
-
- /* Initialize gmime */
- if (! initialized) {
- g_mime_init ();
- initialized = 1;
- }
-
try {
std::string last_thread_id;
std::string last_mod;
--
2.30.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org