diff options
author | wm4 <wm4@nowhere> | 2018-03-09 04:10:28 +0100 |
---|---|---|
committer | Kevin Mitchell <kevmitch@gmail.com> | 2018-03-15 00:00:04 -0700 |
commit | 782fa455b54f9153abefb64e26b8a25925118fc9 (patch) | |
tree | ec589c11845924c4f20bc89f70fb4e1c81dd0f27 /player | |
parent | b2073d08b0913aa7eaa4c2e6c59e880104b3c346 (diff) |
player: move locale check to mp_create()
The intention is to reduce annoying differences between mpv CLI and
libmpv, and there's no reason to have the locale check only in libmpv
(although it doesn't help with any real issues either).
Diffstat (limited to 'player')
-rw-r--r-- | player/client.c | 36 | ||||
-rw-r--r-- | player/main.c | 19 |
2 files changed, 30 insertions, 25 deletions
diff --git a/player/client.c b/player/client.c index 21c6807ad3..4a7307194a 100644 --- a/player/client.c +++ b/player/client.c @@ -19,7 +19,6 @@ #include <unistd.h> #include <fcntl.h> #include <errno.h> -#include <locale.h> #include <math.h> #include <assert.h> @@ -462,15 +461,18 @@ static void *core_thread(void *tag) { mpthread_set_name("mpv core"); + mpv_handle *ctx = NULL; struct MPContext *mpctx = mp_create(); - mpctx->autodetach = true; - mpv_handle *ctx = mp_new_client(mpctx->clients, "main"); - if (ctx) { - ctx->owner = true; - ctx->fuzzy_initialized = true; - m_config_set_profile(mpctx->mconfig, "libmpv", 0); - } else { - mp_destroy(mpctx); + if (mpctx) { + mpctx->autodetach = true; + ctx = mp_new_client(mpctx->clients, "main"); + if (ctx) { + ctx->owner = true; + ctx->fuzzy_initialized = true; + m_config_set_profile(mpctx->mconfig, "libmpv", 0); + } else { + mp_destroy(mpctx); + } } // Let mpv_create() return, and pass it the handle. @@ -491,24 +493,8 @@ static void *core_thread(void *tag) return NULL; } -// We mostly care about LC_NUMERIC, and how "." vs. "," is treated, -// Other locale stuff might break too, but probably isn't too bad. -static bool check_locale(void) -{ - char *name = setlocale(LC_NUMERIC, NULL); - return !name || strcmp(name, "C") == 0 || strcmp(name, "C.UTF-8") == 0; -} - mpv_handle *mpv_create(void) { - if (!check_locale()) { - // Normally, we never print anything (except if the "terminal" option - // is enabled), so this is an exception. - fprintf(stderr, "Non-C locale detected. This is not supported.\n" - "Call 'setlocale(LC_NUMERIC, \"C\");' in your code.\n"); - return NULL; - } - char tag; pthread_t thread; if (pthread_create(&thread, NULL, core_thread, &tag) != 0) diff --git a/player/main.c b/player/main.c index 66ae538d4a..bb83accb7e 100644 --- a/player/main.c +++ b/player/main.c @@ -22,6 +22,7 @@ #include <assert.h> #include <string.h> #include <pthread.h> +#include <locale.h> #include "config.h" #include "mpv_talloc.h" @@ -263,8 +264,24 @@ static void abort_playback_cb(void *ctx) mp_abort_playback_async(mpctx); } +// We mostly care about LC_NUMERIC, and how "." vs. "," is treated, +// Other locale stuff might break too, but probably isn't too bad. +static bool check_locale(void) +{ + char *name = setlocale(LC_NUMERIC, NULL); + return !name || strcmp(name, "C") == 0 || strcmp(name, "C.UTF-8") == 0; +} + struct MPContext *mp_create(void) { + if (!check_locale()) { + // Normally, we never print anything (except if the "terminal" option + // is enabled), so this is an exception. + fprintf(stderr, "Non-C locale detected. This is not supported.\n" + "Call 'setlocale(LC_NUMERIC, \"C\");' in your code.\n"); + return NULL; + } + char *enable_talloc = getenv("MPV_LEAK_REPORT"); if (enable_talloc && strcmp(enable_talloc, "1") == 0) talloc_enable_leak_report(); @@ -441,6 +458,8 @@ int mp_initialize(struct MPContext *mpctx, char **options) int mpv_main(int argc, char *argv[]) { struct MPContext *mpctx = mp_create(); + if (!mpctx) + return 1; char **options = argv && argv[0] ? argv + 1 : NULL; // skips program name int r = mp_initialize(mpctx, options); |