From: Rémi Denis-Courmont Date: Sun, 11 Apr 2010 15:36:50 +0000 (+0300) Subject: VLC: infrastructure to detect and/or work-around thread-unsafe calls X-Git-Tag: 1.1.0-pre1~39 X-Git-Url: https://git.sesse.net/?p=vlc;a=commitdiff_plain;h=d8c9ed53b5680a5b6eb405f60a4a9539d2cc3a63 VLC: infrastructure to detect and/or work-around thread-unsafe calls --- diff --git a/bin/Makefile.am b/bin/Makefile.am index ab03616bb8..4833f86a34 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -14,7 +14,7 @@ AM_CFLAGS = `$(VLC_CONFIG) --cflags vlc` if !HAVE_WIN32 if !HAVE_WINCE bin_PROGRAMS += vlc-wrapper -vlc_SOURCES = vlc.c +vlc_SOURCES = vlc.c override.c endif endif diff --git a/bin/override.c b/bin/override.c new file mode 100644 index 0000000000..048c8fe1ca --- /dev/null +++ b/bin/override.c @@ -0,0 +1,80 @@ +/***************************************************************************** + * override.c: overriden function calls for VLC media player + ***************************************************************************** + * Copyright (C) 2010 Rémi Denis-Courmont + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +void vlc_enable_override (void); + +static bool override = false; + +void vlc_enable_override (void) +{ + override = true; +} + +#if defined (__GNUC__) /* typeof and statement-expression */ \ + && (defined (__ELF__) && !defined (__sun__)) +/* Solaris crashes on printf("%s", NULL); which is legal, but annoying. */ + +#include +#include +#include +#include + +static void vlogbug (const char *level, const char *func, const char *fmt, + va_list ap) +{ + flockfile (stderr); + fprintf (stderr, "%s: call to %s(", level, func); + vfprintf (stderr, fmt, ap); + fputs (")\n", stderr); + funlockfile (stderr); +} + +static void logbug (const char *level, const char *func, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + vlogbug (level, func, fmt, ap); + va_end (ap); +} + +static void *getsym (const char *name) +{ + void *sym = dlsym (RTLD_NEXT, name); + if (sym == NULL) + { + fprintf (stderr, "Cannot resolve symbol %s!\n", name); + abort (); + } + return sym; +} + +#define LOG(level, ...) logbug(level, __func__, __VA_ARGS__) +#define CALL(func, ...) \ + ({ typeof (func) *sym = getsym ( # func); sym (__VA_ARGS__); }) + + +#endif /* __ELF__ */ diff --git a/bin/vlc.c b/bin/vlc.c index e486040ff5..9e769b018c 100644 --- a/bin/vlc.c +++ b/bin/vlc.c @@ -42,6 +42,7 @@ /* Explicit HACK */ extern void LocaleFree (const char *); extern char *FromLocale (const char *); +extern void vlc_enable_override (void); #include #include @@ -157,6 +158,8 @@ int main( int i_argc, const char *ppsz_argv[] ) return 1; // BOOM! argv[argc] = NULL; + vlc_enable_override (); + /* Initialize libvlc */ libvlc_instance_t *vlc = libvlc_new (argc, argv);