diff --git a/src/mu-util.c b/src/mu-util.c index e4fd04ef..214f477e 100644 --- a/src/mu-util.c +++ b/src/mu-util.c @@ -1,4 +1,4 @@ -/* +/* ** Copyright (C) 2010 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify @@ -22,12 +22,14 @@ #include #include +#include /* for setlocale() */ #include #include #include #include +#include #include #include @@ -66,6 +68,28 @@ mu_util_dir_expand (const char *path) return dir; } +gboolean +mu_util_init_system (void) +{ + /* without setlocale, non-ascii cmdline params (like search + * terms) won't work */ + setlocale (LC_ALL, ""); + + /* on FreeBSD, it seems g_slice_new and friends lead to + * segfaults. So we shut if off */ +#ifdef __FreeBSD__ + if (!g_setenv ("G_SLICE", "always-malloc", TRUE)) { + g_critical ("cannot set G_SLICE"); + return FALSE; + } + MU_LOG_FILE("setting G_SLICE to always-malloc"); +#endif /*__FreeBSD__*/ + + g_type_init (); + + return TRUE; +} + gboolean mu_util_check_dir (const gchar* path, gboolean readable, gboolean writeable) diff --git a/src/mu-util.h b/src/mu-util.h index 86e9bc47..7fbf9ca4 100644 --- a/src/mu-util.h +++ b/src/mu-util.h @@ -24,6 +24,14 @@ G_BEGIN_DECLS +/** + * do system-specific initialization. should be called before anything + * else. Initializes the locale and Gtype + * + * @return TRUE if is succeeds, FALSE otherwise + */ +gboolean mu_util_init_system (void); + /** * get the expanded path; ie. perform shell expansion on the path * diff --git a/src/mu.cc b/src/mu.cc index 3c236e7a..1b56d23c 100644 --- a/src/mu.cc +++ b/src/mu.cc @@ -1,5 +1,5 @@ /* -b** Copyright (C) 2010 Dirk-Jan C. Binnema +** Copyright (C) 2010 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -20,10 +20,9 @@ b** Copyright (C) 2010 Dirk-Jan C. Binnema #include #include -#include #include /* for fileno() */ -#include /* for setlocale() */ +#include "mu-util.h" #include "mu-config.h" #include "mu-cmd.h" #include "mu-log.h" @@ -48,18 +47,14 @@ init_log (MuConfigOptions *opts) return rv; } - int main (int argc, char *argv[]) { MuConfigOptions config; gboolean rv; - /* without setlocale, non-ascii cmdline params (like search - * terms) won't work */ - setlocale (LC_ALL, ""); - - g_type_init (); + if (!mu_util_init_system()) + return 1; if (!mu_config_init (&config, &argc, &argv)) return 1;