[vlc-commits] messages: resolve module name at link-time

Rémi Denis-Courmont git at videolan.org
Sat Nov 18 20:43:13 CET 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 18 21:18:24 2017 +0200| [e46fd2bfa69a2684736fbbfbe1dbf3fbce4d7356] | committer: Rémi Denis-Courmont

messages: resolve module name at link-time

Within all the introduced static libraries, the module cannot be known
at compilation time. This moves the module name from a compilation
constant to a link time constant string symbol. That way, the same
compiled object within a static library can use a different and correct
module name depending on which plugin it is linked into.

The symbol is hidden so it does not leak between shared objects. For
non-plugins shared libraries (vlccore, vlc, vlc_pulse and
vlc_xcb_events) the module name must be defined manually, unless the
library does not use msg_* macros at all (vlc_vdpau).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e46fd2bfa69a2684736fbbfbe1dbf3fbce4d7356
---

 include/vlc_messages.h            | 10 ++++------
 include/vlc_plugin.h              |  8 ++++++--
 lib/Makefile.am                   |  1 -
 lib/core.c                        |  2 ++
 modules/audio_output/Makefile.am  |  1 -
 modules/audio_output/vlcpulse.c   |  2 ++
 modules/video_output/Makefile.am  |  1 -
 modules/video_output/xcb/events.c |  2 ++
 src/libvlc-module.c               |  4 ++++
 src/misc/messages.c               |  2 +-
 10 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/include/vlc_messages.h b/include/vlc_messages.h
index 68121ea080..63f9476cd5 100644
--- a/include/vlc_messages.h
+++ b/include/vlc_messages.h
@@ -71,11 +71,11 @@ VLC_API void vlc_vaLog(vlc_object_t *obj, int prio, const char *module,
                        const char *file, unsigned line, const char *func,
                        const char *format, va_list ap);
 #define msg_GenericVa(o, p, fmt, ap) \
-    vlc_vaLog(VLC_OBJECT(o), p, MODULE_STRING, __FILE__, __LINE__, __func__, \
-              fmt, ap)
+    vlc_vaLog(VLC_OBJECT(o), p, vlc_module_name, __FILE__, __LINE__, \
+              __func__, fmt, ap)
 
 #define msg_Generic(o, p, ...) \
-    vlc_Log(VLC_OBJECT(o), p, MODULE_STRING, __FILE__, __LINE__, \
+    vlc_Log(VLC_OBJECT(o), p, vlc_module_name, __FILE__, __LINE__, \
             __func__, __VA_ARGS__)
 #define msg_Info(p_this, ...) \
     msg_Generic(p_this, VLC_MSG_INFO, __VA_ARGS__)
@@ -86,9 +86,7 @@ VLC_API void vlc_vaLog(vlc_object_t *obj, int prio, const char *module,
 #define msg_Dbg(p_this, ...) \
     msg_Generic(p_this, VLC_MSG_DBG, __VA_ARGS__)
 
-#ifndef MODULE_STRING
-# define MODULE_STRING __FILE__
-#endif
+extern const char vlc_module_name[];
 
 VLC_API const char *vlc_strerror(int);
 VLC_API const char *vlc_strerror_c(int);
diff --git a/include/vlc_plugin.h b/include/vlc_plugin.h
index 7e9e447d04..ce28562726 100644
--- a/include/vlc_plugin.h
+++ b/include/vlc_plugin.h
@@ -210,9 +210,12 @@ enum vlc_module_properties
 /* If the module is built-in, then we need to define foo_InitModule instead
  * of InitModule. Same for Activate- and DeactivateModule. */
 #ifdef __PLUGIN__
-#   define __VLC_SYMBOL( symbol  ) CONCATENATE( symbol, MODULE_SYMBOL )
+# define __VLC_SYMBOL( symbol  ) CONCATENATE( symbol, MODULE_SYMBOL )
+# define VLC_MODULE_NAME_HIDDEN_SYMBOL \
+    const char vlc_module_name[] = MODULE_STRING;
 #else
-#   define __VLC_SYMBOL( symbol )  CONCATENATE( symbol, MODULE_NAME )
+# define __VLC_SYMBOL( symbol )  CONCATENATE( symbol, MODULE_NAME )
+# define VLC_MODULE_NAME_HIDDEN_SYMBOL
 #endif
 
 #define CDECL_SYMBOL
@@ -267,6 +270,7 @@ int CDECL_SYMBOL __VLC_SYMBOL(vlc_entry) (vlc_set_cb vlc_set, void *opaque) \
 error: \
     return -1; \
 } \
+VLC_MODULE_NAME_HIDDEN_SYMBOL \
 VLC_METADATA_EXPORTS
 
 #define add_submodule( ) \
diff --git a/lib/Makefile.am b/lib/Makefile.am
index cf6cc83386..892d9b14f1 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,6 +1,5 @@
 AUTOMAKE_OPTIONS = subdir-objects
 pkgconfigdir = $(libdir)/pkgconfig
-AM_CPPFLAGS = -DMODULE_STRING=\"libvlc\"
 AM_CFLAGS = $(CFLAGS_libvlc)
 
 SUFFIXES = .pc.in .pc
diff --git a/lib/core.c b/lib/core.c
index 8ca4b5cf4d..5e8c614c83 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -256,3 +256,5 @@ int64_t libvlc_clock(void)
 {
     return mdate();
 }
+
+const char vlc_module_name[] = "libvlc";
diff --git a/modules/audio_output/Makefile.am b/modules/audio_output/Makefile.am
index 4cffed51bb..d7766af7e9 100644
--- a/modules/audio_output/Makefile.am
+++ b/modules/audio_output/Makefile.am
@@ -38,7 +38,6 @@ aout_LTLIBRARIES += libalsa_plugin.la
 endif
 
 libvlc_pulse_la_SOURCES = audio_output/vlcpulse.c audio_output/vlcpulse.h
-libvlc_pulse_la_CPPFLAGS = -DMODULE_STRING=\"pulse\"
 libvlc_pulse_la_CFLAGS = $(AM_CFLAGS) $(PULSE_CFLAGS)
 libvlc_pulse_la_LIBADD = $(PULSE_LIBS) $(LTLIBVLCCORE)
 libvlc_pulse_la_LDFLAGS = \
diff --git a/modules/audio_output/vlcpulse.c b/modules/audio_output/vlcpulse.c
index 4976cae2bc..fe0829ef0a 100644
--- a/modules/audio_output/vlcpulse.c
+++ b/modules/audio_output/vlcpulse.c
@@ -34,6 +34,8 @@
 #include <unistd.h>
 #include <pwd.h>
 
+const char vlc_module_name[] = "vlcpulse";
+
 #undef vlc_pa_error
 void vlc_pa_error (vlc_object_t *obj, const char *msg, pa_context *ctx)
 {
diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index 279d4a5d87..ae0049fd8b 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -120,7 +120,6 @@ endif # HAVE_GL
 ### XCB ###
 libvlc_xcb_events_la_SOURCES = \
 	video_output/xcb/events.c video_output/xcb/events.h
-libvlc_xcb_events_la_CPPFLAGS = -DMODULE_STRING=\"xcb\"
 libvlc_xcb_events_la_CFLAGS = $(AM_CFLAGS) $(XCB_CFLAGS)
 libvlc_xcb_events_la_LDFLAGS = \
 	-no-undefined \
diff --git a/modules/video_output/xcb/events.c b/modules/video_output/xcb/events.c
index 1b53f2b66a..8584bf2fe2 100644
--- a/modules/video_output/xcb/events.c
+++ b/modules/video_output/xcb/events.c
@@ -34,6 +34,8 @@
 
 #include "events.h"
 
+const char vlc_module_name[] = "vlcpulse";
+
 #pragma GCC visibility push(default)
 
 int vlc_xcb_error_Check(vout_display_t *vd, xcb_connection_t *conn,
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 8e9a29dea0..4b24445da8 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -2809,3 +2809,7 @@ vlc_module_end ()
 /*****************************************************************************
  * End configuration.
  *****************************************************************************/
+
+#ifdef HAVE_DYNAMIC_PLUGINS
+const char vlc_module_name[] = "main";
+#endif
diff --git a/src/misc/messages.c b/src/misc/messages.c
index 9fa840478e..b8316b1fe7 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -145,7 +145,7 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
  * \param obj VLC object emitting the message or NULL
  * \param type VLC_MSG_* message type (info, error, warning or debug)
  * \param module name of module from which the message come
- *               (normally MODULE_STRING)
+ *               (normally vlc_module_name)
  * \param file source module file name (normally __FILE__) or NULL
  * \param line function call source line number (normally __LINE__) or 0
  * \param func calling function name (normally __func__) or NULL



More information about the vlc-commits mailing list