* <many>: make gmime initialization/de-initialization implicit (remove mu_msg_init/mu_msg_uninit)
This commit is contained in:
@ -211,8 +211,6 @@ mu_cmd_extract (MuConfigOptions *opts)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
mu_msg_init();
|
|
||||||
|
|
||||||
if (!opts->parts &&
|
if (!opts->parts &&
|
||||||
!opts->save_attachments &&
|
!opts->save_attachments &&
|
||||||
!opts->save_all) /* show, don't save */
|
!opts->save_all) /* show, don't save */
|
||||||
@ -220,7 +218,5 @@ mu_cmd_extract (MuConfigOptions *opts)
|
|||||||
else
|
else
|
||||||
rv = save_parts (opts->params[1], opts); /* save */
|
rv = save_parts (opts->params[1], opts); /* save */
|
||||||
|
|
||||||
mu_msg_uninit();
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -344,19 +344,15 @@ mu_cmd_find (MuConfigOptions *opts)
|
|||||||
/* first param is 'query', search params are after that */
|
/* first param is 'query', search params are after that */
|
||||||
params = (const gchar**)&opts->params[1];
|
params = (const gchar**)&opts->params[1];
|
||||||
|
|
||||||
mu_msg_init();
|
|
||||||
|
|
||||||
xapian = mu_query_new (opts->xpath);
|
xapian = mu_query_new (opts->xpath);
|
||||||
if (!xapian) {
|
if (!xapian) {
|
||||||
g_printerr ("Failed to create a Xapian query\n");
|
g_printerr ("Failed to create a Xapian query\n");
|
||||||
mu_msg_uninit ();
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = do_output (xapian, opts, params);
|
rv = do_output (xapian, opts, params);
|
||||||
|
|
||||||
mu_query_destroy (xapian);
|
mu_query_destroy (xapian);
|
||||||
mu_msg_uninit();
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -208,14 +208,9 @@ run_index (MuIndex *midx, const char* maildir, MuIndexStats *stats,
|
|||||||
MuResult rv;
|
MuResult rv;
|
||||||
|
|
||||||
mu_index_stats_clear (stats);
|
mu_index_stats_clear (stats);
|
||||||
mu_msg_init ();
|
|
||||||
|
|
||||||
rv = mu_index_run (midx, maildir, reindex, stats,
|
rv = mu_index_run (midx, maildir, reindex, stats,
|
||||||
quiet ? index_msg_silent_cb :index_msg_cb,
|
quiet ? index_msg_silent_cb :index_msg_cb,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
mu_msg_init ();
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -87,14 +87,10 @@ mu_cmd_view (MuConfigOptions *opts)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
mu_msg_init();
|
|
||||||
|
|
||||||
rv = TRUE;
|
rv = TRUE;
|
||||||
for (i = 1; opts->params[i] && rv; ++i)
|
for (i = 1; opts->params[i] && rv; ++i)
|
||||||
rv = view_file (opts->params[i], NULL,
|
rv = view_file (opts->params[i], NULL,
|
||||||
opts->summary_len);
|
opts->summary_len);
|
||||||
|
|
||||||
mu_msg_uninit();
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|||||||
53
src/mu-msg.c
53
src/mu-msg.c
@ -32,6 +32,28 @@
|
|||||||
#include "mu-msg.h"
|
#include "mu-msg.h"
|
||||||
|
|
||||||
|
|
||||||
|
static guint _refcount = 0;
|
||||||
|
|
||||||
|
static void
|
||||||
|
ref_gmime (void)
|
||||||
|
{
|
||||||
|
if (G_UNLIKELY(_refcount == 0)) {
|
||||||
|
srandom (getpid()*time(NULL));
|
||||||
|
g_mime_init(0);
|
||||||
|
}
|
||||||
|
++_refcount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
unref_gmime (void)
|
||||||
|
{
|
||||||
|
g_return_if_fail (_refcount > 0);
|
||||||
|
|
||||||
|
--_refcount;
|
||||||
|
if (G_UNLIKELY(_refcount == 0))
|
||||||
|
g_mime_shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mu_msg_destroy (MuMsg *msg)
|
mu_msg_destroy (MuMsg *msg)
|
||||||
@ -50,6 +72,7 @@ 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 ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -135,9 +158,9 @@ mu_msg_new (const char* filepath, const gchar* mdir)
|
|||||||
|
|
||||||
g_return_val_if_fail (filepath, NULL);
|
g_return_val_if_fail (filepath, NULL);
|
||||||
|
|
||||||
|
ref_gmime ();
|
||||||
|
|
||||||
msg = g_slice_new0 (MuMsg);
|
msg = g_slice_new0 (MuMsg);
|
||||||
if (!msg)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!init_file_metadata(msg, filepath, mdir)) {
|
if (!init_file_metadata(msg, filepath, mdir)) {
|
||||||
mu_msg_destroy (msg);
|
mu_msg_destroy (msg);
|
||||||
@ -794,29 +817,3 @@ mu_msg_get_field_numeric (MuMsg *msg, const MuMsgField* field)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean _initialized = FALSE;
|
|
||||||
|
|
||||||
void
|
|
||||||
mu_msg_init (void)
|
|
||||||
{
|
|
||||||
if (!_initialized) {
|
|
||||||
|
|
||||||
srandom (getpid()*time(NULL));
|
|
||||||
|
|
||||||
g_mime_init(0);
|
|
||||||
_initialized = TRUE;
|
|
||||||
g_debug ("%s", __FUNCTION__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
mu_msg_uninit (void)
|
|
||||||
{
|
|
||||||
if (_initialized) {
|
|
||||||
g_mime_shutdown();
|
|
||||||
_initialized = FALSE;
|
|
||||||
g_debug ("%s", __FUNCTION__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
19
src/mu-msg.h
19
src/mu-msg.h
@ -30,25 +30,6 @@ G_BEGIN_DECLS
|
|||||||
struct _MuMsg;
|
struct _MuMsg;
|
||||||
typedef struct _MuMsg MuMsg;
|
typedef struct _MuMsg MuMsg;
|
||||||
|
|
||||||
/**
|
|
||||||
* initialize the message parsing system; this function must be called
|
|
||||||
* before doing any message parsing (ie., any of the other
|
|
||||||
* mu_msg functions). when done with the message parsing system,
|
|
||||||
* call mu_msg_uninit. Note: calling this function on an already
|
|
||||||
* initialized system has no effect
|
|
||||||
*/
|
|
||||||
void mu_msg_init (void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* uninitialize the messge parsing system that has previously been
|
|
||||||
* initialized with mu_msg_init. not calling mu_msg_uninit after
|
|
||||||
* mu_msg_init has been called will lead to memory leakage. Note:
|
|
||||||
* calling mu_msg_uninit on an uninitialized system has no
|
|
||||||
* effect
|
|
||||||
*/
|
|
||||||
void mu_msg_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.
|
||||||
|
|||||||
@ -84,7 +84,6 @@ test_mu_msg_01 (void)
|
|||||||
MuMsg *msg;
|
MuMsg *msg;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
mu_msg_init ();
|
|
||||||
mfile = get_mailpath (1);
|
mfile = get_mailpath (1);
|
||||||
|
|
||||||
msg = mu_msg_new (mfile, NULL);
|
msg = mu_msg_new (mfile, NULL);
|
||||||
@ -113,7 +112,6 @@ test_mu_msg_01 (void)
|
|||||||
mu_msg_destroy (msg);
|
mu_msg_destroy (msg);
|
||||||
|
|
||||||
g_free (mfile);
|
g_free (mfile);
|
||||||
mu_msg_uninit ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -151,7 +149,6 @@ test_mu_msg_02 (void)
|
|||||||
MuMsg *msg;
|
MuMsg *msg;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
mu_msg_init ();
|
|
||||||
mfile = get_mailpath (2);
|
mfile = get_mailpath (2);
|
||||||
|
|
||||||
msg = mu_msg_new (mfile, NULL);
|
msg = mu_msg_new (mfile, NULL);
|
||||||
@ -179,7 +176,6 @@ test_mu_msg_02 (void)
|
|||||||
mu_msg_destroy (msg);
|
mu_msg_destroy (msg);
|
||||||
|
|
||||||
g_free (mfile);
|
g_free (mfile);
|
||||||
mu_msg_uninit ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -159,8 +159,6 @@ test_mu_query_04 (void)
|
|||||||
|
|
||||||
query = mu_query_new (xpath);
|
query = mu_query_new (xpath);
|
||||||
iter = mu_query_run (query, "fünkÿ", NULL, FALSE, 1);
|
iter = mu_query_run (query, "fünkÿ", NULL, FALSE, 1);
|
||||||
|
|
||||||
mu_msg_init ();
|
|
||||||
msg = mu_msg_iter_get_msg (iter);
|
msg = mu_msg_iter_get_msg (iter);
|
||||||
|
|
||||||
g_assert_cmpstr (mu_msg_get_subject(msg),==,
|
g_assert_cmpstr (mu_msg_get_subject(msg),==,
|
||||||
@ -169,8 +167,6 @@ test_mu_query_04 (void)
|
|||||||
" Let's write some fünkÿ text using umlauts. ");
|
" Let's write some fünkÿ text using umlauts. ");
|
||||||
|
|
||||||
mu_msg_destroy (msg);
|
mu_msg_destroy (msg);
|
||||||
mu_msg_uninit ();
|
|
||||||
|
|
||||||
mu_msg_iter_destroy (iter);
|
mu_msg_iter_destroy (iter);
|
||||||
mu_query_destroy (query);
|
mu_query_destroy (query);
|
||||||
g_free (xpath);
|
g_free (xpath);
|
||||||
|
|||||||
Reference in New Issue
Block a user