mirror of https://github.com/djcb/mu.git
* mu-msg, mu-runtime: make g_mime_init explicit, mu-runtime can do it.
This commit is contained in:
parent
66203c290f
commit
9916bb3ecc
35
src/mu-msg.c
35
src/mu-msg.c
|
@ -32,37 +32,36 @@
|
|||
#include "mu-msg-priv.h" /* include before mu-msg.h */
|
||||
#include "mu-msg.h"
|
||||
|
||||
|
||||
static guint _refcount = 0;
|
||||
|
||||
/* note, we do the gmime initialization here rather than in
|
||||
* mu-runtime, because this way we don't need mu-runtime for simple
|
||||
* cases -- such as our unit tests */
|
||||
static gboolean _gmime_initialized = FALSE;
|
||||
|
||||
static void
|
||||
ref_gmime (void)
|
||||
void
|
||||
mu_msg_gmime_init (void)
|
||||
{
|
||||
if (G_UNLIKELY(_refcount == 0)) {
|
||||
srandom ((unsigned)(getpid()*time(NULL)));
|
||||
g_return_if_fail (!_gmime_initialized);
|
||||
|
||||
#ifdef GMIME_ENABLE_RFC2047_WORKAROUNDS
|
||||
g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);
|
||||
#else
|
||||
g_mime_init(0);
|
||||
#endif /* GMIME_ENABLE_RFC2047_WORKAROUNDS */
|
||||
}
|
||||
++_refcount;
|
||||
|
||||
_gmime_initialized = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
unref_gmime (void)
|
||||
|
||||
void
|
||||
mu_msg_gmime_uninit (void)
|
||||
{
|
||||
g_return_if_fail (_refcount > 0);
|
||||
g_return_if_fail (_gmime_initialized);
|
||||
|
||||
--_refcount;
|
||||
if (G_UNLIKELY(_refcount == 0))
|
||||
g_mime_shutdown();
|
||||
g_mime_shutdown();
|
||||
_gmime_initialized = FALSE;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mu_msg_destroy (MuMsg *msg)
|
||||
{
|
||||
|
@ -80,7 +79,6 @@ mu_msg_destroy (MuMsg *msg)
|
|||
g_free (msg->_fields[i]);
|
||||
|
||||
g_slice_free (MuMsg, msg);
|
||||
unref_gmime ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -187,9 +185,8 @@ mu_msg_new (const char* filepath, const gchar* mdir, GError **err)
|
|||
{
|
||||
MuMsg *msg;
|
||||
|
||||
g_return_val_if_fail (filepath, NULL);
|
||||
|
||||
ref_gmime ();
|
||||
g_return_val_if_fail (filepath, NULL);
|
||||
g_return_val_if_fail (_gmime_initialized, NULL);
|
||||
|
||||
msg = g_slice_new0 (MuMsg);
|
||||
msg->_prio = MU_MSG_PRIO_NONE;
|
||||
|
|
18
src/mu-msg.h
18
src/mu-msg.h
|
@ -31,6 +31,24 @@ G_BEGIN_DECLS
|
|||
struct _MuMsg;
|
||||
typedef struct _MuMsg MuMsg;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* initialize the GMime-system; this function needs to be called
|
||||
* before doing anything else with MuMsg. mu_runtime_init will call
|
||||
* this function, so if you use that, you should not call this
|
||||
* function.
|
||||
*/
|
||||
void mu_msg_gmime_init (void);
|
||||
|
||||
/**
|
||||
* uninitialize the GMime-system; this function needs to be called
|
||||
* after you're done with MuMsg. mu_runtime_uninit will call this
|
||||
* function, so if you use that, you should not call this function.
|
||||
*/
|
||||
void mu_msg_gmime_uninit (void);
|
||||
|
||||
|
||||
/**
|
||||
* create a new MuMsg* instance which parses a message and provides
|
||||
* read access to its properties; call mu_msg_destroy when done with it.
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
#include <glib-object.h>
|
||||
#include <locale.h> /* for setlocale() */
|
||||
#include <stdio.h> /* for fileno() */
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <mu-msg.h>
|
||||
|
||||
|
||||
#include "mu-config.h"
|
||||
#include "mu-log.h"
|
||||
|
@ -51,6 +56,10 @@ init_system (void)
|
|||
* terms) won't work */
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
/* init the random number generator; this is not really *that*
|
||||
* random, but good enough for our humble needs... */
|
||||
srandom ((unsigned)(getpid()*time(NULL)));
|
||||
|
||||
/* on FreeBSD, it seems g_slice_new and friends lead to
|
||||
* segfaults. So we shut if off */
|
||||
#ifdef __FreeBSD__
|
||||
|
@ -89,6 +98,8 @@ mu_runtime_init (const char* muhome_arg)
|
|||
|
||||
_data = g_new0 (MuRuntimeData, 1);
|
||||
_data->_muhome = muhome;
|
||||
|
||||
mu_msg_gmime_init ();
|
||||
|
||||
return _initialized = TRUE;
|
||||
}
|
||||
|
@ -127,6 +138,8 @@ mu_runtime_init_from_cmdline (int *pargc, char ***pargv)
|
|||
}
|
||||
|
||||
_data->_muhome = g_strdup (_data->_config->muhome);
|
||||
|
||||
mu_msg_gmime_init ();
|
||||
|
||||
return _initialized = TRUE;
|
||||
}
|
||||
|
@ -153,8 +166,10 @@ mu_runtime_uninit (void)
|
|||
{
|
||||
g_return_if_fail (_initialized);
|
||||
|
||||
runtime_free ();
|
||||
mu_msg_gmime_uninit ();
|
||||
|
||||
runtime_free ();
|
||||
|
||||
_initialized = FALSE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue