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-priv.h" /* include before mu-msg.h */
|
||||||
#include "mu-msg.h"
|
#include "mu-msg.h"
|
||||||
|
|
||||||
|
|
||||||
static guint _refcount = 0;
|
|
||||||
|
|
||||||
/* note, we do the gmime initialization here rather than in
|
/* note, we do the gmime initialization here rather than in
|
||||||
* mu-runtime, because this way we don't need mu-runtime for simple
|
* mu-runtime, because this way we don't need mu-runtime for simple
|
||||||
* cases -- such as our unit tests */
|
* cases -- such as our unit tests */
|
||||||
|
static gboolean _gmime_initialized = FALSE;
|
||||||
|
|
||||||
static void
|
void
|
||||||
ref_gmime (void)
|
mu_msg_gmime_init (void)
|
||||||
{
|
{
|
||||||
if (G_UNLIKELY(_refcount == 0)) {
|
g_return_if_fail (!_gmime_initialized);
|
||||||
srandom ((unsigned)(getpid()*time(NULL)));
|
|
||||||
#ifdef GMIME_ENABLE_RFC2047_WORKAROUNDS
|
#ifdef GMIME_ENABLE_RFC2047_WORKAROUNDS
|
||||||
g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);
|
g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);
|
||||||
#else
|
#else
|
||||||
g_mime_init(0);
|
g_mime_init(0);
|
||||||
#endif /* GMIME_ENABLE_RFC2047_WORKAROUNDS */
|
#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;
|
g_mime_shutdown();
|
||||||
if (G_UNLIKELY(_refcount == 0))
|
_gmime_initialized = FALSE;
|
||||||
g_mime_shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mu_msg_destroy (MuMsg *msg)
|
mu_msg_destroy (MuMsg *msg)
|
||||||
{
|
{
|
||||||
|
@ -80,7 +79,6 @@ mu_msg_destroy (MuMsg *msg)
|
||||||
g_free (msg->_fields[i]);
|
g_free (msg->_fields[i]);
|
||||||
|
|
||||||
g_slice_free (MuMsg, msg);
|
g_slice_free (MuMsg, msg);
|
||||||
unref_gmime ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,9 +185,8 @@ mu_msg_new (const char* filepath, const gchar* mdir, GError **err)
|
||||||
{
|
{
|
||||||
MuMsg *msg;
|
MuMsg *msg;
|
||||||
|
|
||||||
g_return_val_if_fail (filepath, NULL);
|
g_return_val_if_fail (filepath, NULL);
|
||||||
|
g_return_val_if_fail (_gmime_initialized, NULL);
|
||||||
ref_gmime ();
|
|
||||||
|
|
||||||
msg = g_slice_new0 (MuMsg);
|
msg = g_slice_new0 (MuMsg);
|
||||||
msg->_prio = MU_MSG_PRIO_NONE;
|
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;
|
struct _MuMsg;
|
||||||
typedef struct _MuMsg 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
|
* create a new MuMsg* instance which parses a message and provides
|
||||||
* read access to its properties; call mu_msg_destroy when done with it.
|
* read access to its properties; call mu_msg_destroy when done with it.
|
||||||
|
|
|
@ -22,6 +22,11 @@
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <locale.h> /* for setlocale() */
|
#include <locale.h> /* for setlocale() */
|
||||||
#include <stdio.h> /* for fileno() */
|
#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-config.h"
|
||||||
#include "mu-log.h"
|
#include "mu-log.h"
|
||||||
|
@ -51,6 +56,10 @@ init_system (void)
|
||||||
* terms) won't work */
|
* terms) won't work */
|
||||||
setlocale (LC_ALL, "");
|
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
|
/* on FreeBSD, it seems g_slice_new and friends lead to
|
||||||
* segfaults. So we shut if off */
|
* segfaults. So we shut if off */
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
|
@ -89,6 +98,8 @@ mu_runtime_init (const char* muhome_arg)
|
||||||
|
|
||||||
_data = g_new0 (MuRuntimeData, 1);
|
_data = g_new0 (MuRuntimeData, 1);
|
||||||
_data->_muhome = muhome;
|
_data->_muhome = muhome;
|
||||||
|
|
||||||
|
mu_msg_gmime_init ();
|
||||||
|
|
||||||
return _initialized = TRUE;
|
return _initialized = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -127,6 +138,8 @@ mu_runtime_init_from_cmdline (int *pargc, char ***pargv)
|
||||||
}
|
}
|
||||||
|
|
||||||
_data->_muhome = g_strdup (_data->_config->muhome);
|
_data->_muhome = g_strdup (_data->_config->muhome);
|
||||||
|
|
||||||
|
mu_msg_gmime_init ();
|
||||||
|
|
||||||
return _initialized = TRUE;
|
return _initialized = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -153,8 +166,10 @@ mu_runtime_uninit (void)
|
||||||
{
|
{
|
||||||
g_return_if_fail (_initialized);
|
g_return_if_fail (_initialized);
|
||||||
|
|
||||||
runtime_free ();
|
mu_msg_gmime_uninit ();
|
||||||
|
|
||||||
|
runtime_free ();
|
||||||
|
|
||||||
_initialized = FALSE;
|
_initialized = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue