vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Wed Feb 20 22:57:37 2019 +0200| [420f6350dbd4626b4f88a459890639ca32c73086] | committer: Rémi Denis-Courmont
messages: rationalize vlc_LogSwitchCreate() > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=420f6350dbd4626b4f88a459890639ca32c73086 --- src/libvlc.c | 1 - src/misc/messages.c | 21 ++++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/libvlc.c b/src/libvlc.c index 98480ecc4d..8e8d2ca8b2 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -429,7 +429,6 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) config_AutoSaveConfigFile( VLC_OBJECT(p_libvlc) ); vlc_LogDestroy(p_libvlc->obj.logger); - free(p_libvlc->obj.logger); /* transitional hack */ /* Free module bank. It is refcounted, so we call this each time */ module_EndBank (true); #if defined(_WIN32) || defined(__OS2__) diff --git a/src/misc/messages.c b/src/misc/messages.c index 0653ea5a44..19291bd4dd 100644 --- a/src/misc/messages.c +++ b/src/misc/messages.c @@ -300,6 +300,7 @@ static struct vlc_logger discard_log = { &discard_ops, NULL }; */ struct vlc_logger_switch { struct vlc_logger *backend; + struct vlc_logger frontend; vlc_rwlock_t lock; }; @@ -336,11 +337,11 @@ static const struct vlc_logger_operations switch_ops = { static void vlc_LogSwitch(vlc_logger_t *logger, vlc_logger_t *new_logger) { - struct vlc_logger_switch *logswitch = logger->sys; + struct vlc_logger_switch *logswitch = + container_of(logger, struct vlc_logger_switch, frontend); struct vlc_logger *old_logger; assert(logger->ops == &switch_ops); - assert(logswitch != NULL); if (new_logger == NULL) new_logger = &discard_log; @@ -354,17 +355,17 @@ static void vlc_LogSwitch(vlc_logger_t *logger, vlc_logger_t *new_logger) old_logger->ops->destroy(old_logger->sys); } -static -const struct vlc_logger_operations *vlc_LogSwitchCreate(void **restrict sysp) +static struct vlc_logger *vlc_LogSwitchCreate(void) { struct vlc_logger_switch *logswitch = malloc(sizeof (*logswitch)); if (unlikely(logswitch == NULL)) return NULL; + logswitch->frontend.ops = &switch_ops; + logswitch->frontend.sys = logswitch; logswitch->backend = &discard_log; vlc_rwlock_init(&logswitch->lock); - *sysp = logswitch; - return &switch_ops; + return &logswitch->frontend; } /** @@ -455,15 +456,9 @@ void vlc_LogInit(libvlc_int_t *vlc) */ int vlc_LogPreinit(libvlc_int_t *vlc) { - vlc_logger_t *logger = malloc(sizeof (*logger)); + vlc_logger_t *logger = vlc_LogSwitchCreate(); if (unlikely(logger == NULL)) return -1; - - logger->ops = vlc_LogSwitchCreate(&logger->sys); - if (unlikely(logger->ops == NULL)) { - free(logger); - return -1; - } vlc->obj.logger = logger; struct vlc_logger *early = vlc_LogEarlyOpen(logger); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
