X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fos.c;h=cc33c513287710ab18d09cdfb225ae85f1b32dd7;hb=e1f9ab22e7e3e620d5b5b1c2d0532614ee103576;hp=a34540bb94fcda7a0637421cfe508adb15dfa194;hpb=b8faf36e58cc0a7f9a4d6e1d1f86fdf076aebbe3;p=vlc diff --git a/src/modules/os.c b/src/modules/os.c index a34540bb94..cc33c51328 100644 --- a/src/modules/os.c +++ b/src/modules/os.c @@ -30,6 +30,7 @@ #include #include /* MODULE_SUFFIX */ +#include #include "libvlc.h" #include "modules.h" @@ -37,20 +38,16 @@ #include /* sprintf() */ #include /* strdup() */ -#ifdef HAVE_SYS_TYPES_H -# include -#endif +#include #if !defined(HAVE_DYNAMIC_PLUGINS) /* no support for plugins */ -#elif defined(HAVE_DL_DYLD) -# if defined(HAVE_MACH_O_DYLD_H) -# include -# endif #elif defined(HAVE_DL_BEOS) # if defined(HAVE_IMAGE_H) # include # endif +#elif defined(__APPLE__) +# include #elif defined(HAVE_DL_WINDOWS) # include #elif defined(HAVE_DL_DLOPEN) @@ -65,6 +62,9 @@ # include # endif #endif +#ifdef HAVE_VALGRIND_VALGRIND_H +# include +#endif /***************************************************************************** * Local prototypes @@ -95,7 +95,7 @@ int module_Call( vlc_object_t *obj, module_t *p_module ) if( pf_symbol == NULL ) { -#if defined(HAVE_DL_DYLD) || defined(HAVE_DL_BEOS) +#if defined(HAVE_DL_BEOS) msg_Warn( obj, "cannot find symbol \"%s\" in file `%s'", psz_name, p_module->psz_filename ); #elif defined(HAVE_DL_WINDOWS) @@ -129,16 +129,6 @@ int module_Call( vlc_object_t *obj, module_t *p_module ) return 0; } -#if defined (RTLD_NOLOAD) -/* Make sure libvlccore is in the global namespace */ -static void load_libvlccore( void ) -{ - if( !dlsym( RTLD_DEFAULT, "vlc_module_create" ) - && !dlopen( "libvlccore.so", RTLD_GLOBAL|RTLD_NOLOAD ) ) - fprintf( stderr, "ERROR: failed loading libvlccore\n" ); -} -#endif - /** * Load a dynamically linked library using a system dependent method. * @@ -152,37 +142,7 @@ int module_Load( vlc_object_t *p_this, const char *psz_file, { module_handle_t handle; -#if defined(HAVE_DL_DYLD) - NSObjectFileImage image; - NSObjectFileImageReturnCode ret; - - ret = NSCreateObjectFileImageFromFile( psz_file, &image ); - - if( ret != NSObjectFileImageSuccess ) - { - msg_Warn( p_this, "cannot create image from `%s'", psz_file ); - return -1; - } - - /* Open the dynamic module */ - handle = NSLinkModule( image, psz_file, - NSLINKMODULE_OPTION_RETURN_ON_ERROR ); - - if( !handle ) - { - NSLinkEditErrors errors; - const char *psz_file, *psz_err; - int i_errnum; - NSLinkEditError( &errors, &i_errnum, &psz_file, &psz_err ); - msg_Warn( p_this, "cannot link module `%s' (%s)", psz_file, psz_err ); - NSDestroyObjectFileImage( image ); - return -1; - } - - /* Destroy our image, we won't need it */ - NSDestroyObjectFileImage( image ); - -#elif defined(HAVE_DL_BEOS) +#if defined(HAVE_DL_BEOS) handle = load_add_on( psz_file ); if( handle < 0 ) { @@ -192,7 +152,7 @@ int module_Load( vlc_object_t *p_this, const char *psz_file, #elif defined(HAVE_DL_WINDOWS) wchar_t psz_wfile[MAX_PATH]; - MultiByteToWideChar( CP_ACP, 0, psz_file, -1, psz_wfile, MAX_PATH ); + MultiByteToWideChar( CP_UTF8, 0, psz_file, -1, psz_wfile, MAX_PATH ); #ifndef UNDER_CE /* FIXME: this is not thread-safe -- Courmisch */ @@ -215,10 +175,6 @@ int module_Load( vlc_object_t *p_this, const char *psz_file, } #elif defined(HAVE_DL_DLOPEN) -# if defined (RTLD_NOLOAD) - static pthread_once_t once = PTHREAD_ONCE_INIT; - pthread_once( &once, &load_libvlccore ); -# endif # if defined (RTLD_NOW) const int flags = RTLD_NOW; @@ -227,14 +183,16 @@ int module_Load( vlc_object_t *p_this, const char *psz_file, # else const int flags = 0; # endif + char *path = ToLocale( psz_file ); - handle = dlopen( psz_file, RTLD_NOW ); + handle = dlopen( path, flags ); if( handle == NULL ) { - msg_Warn( p_this, "cannot load module `%s' (%s)", - psz_file, dlerror() ); + msg_Warn( p_this, "cannot load module `%s' (%s)", path, dlerror() ); + LocaleFree( path ); return -1; } + LocaleFree( path ); #elif defined(HAVE_DL_SHL_LOAD) handle = shl_load( psz_file, BIND_IMMEDIATE | BIND_NONFATAL, NULL ); @@ -264,21 +222,18 @@ int module_Load( vlc_object_t *p_this, const char *psz_file, */ void module_Unload( module_handle_t handle ) { -#if defined(HAVE_DL_DYLD) - NSUnLinkModule( handle, FALSE ); - -#elif defined(HAVE_DL_BEOS) +#if defined(HAVE_DL_BEOS) unload_add_on( handle ); #elif defined(HAVE_DL_WINDOWS) FreeLibrary( handle ); #elif defined(HAVE_DL_DLOPEN) -# ifdef NDEBUG - dlclose( handle ); -# else - (void)handle; +# ifdef HAVE_VALGRIND_VALGRIND_H + if( RUNNING_ON_VALGRIND > 0 ) + return; /* do not dlclose() so that we get proper stack traces */ # endif + dlclose( handle ); #elif defined(HAVE_DL_SHL_LOAD) shl_unload( handle ); @@ -300,15 +255,7 @@ void module_Unload( module_handle_t handle ) */ static void *module_Lookup( module_handle_t handle, const char *psz_function ) { -#if defined(HAVE_DL_DYLD) - char psz_call[strlen( psz_function ) + 2]; - psz_call[0] = '_'; - memcpy( psz_call + 1, psz_function, sizeof( psz_call ) - 1 ); - - NSSymbol sym = NSLookupSymbolInModule( handle, psz_call ); - return NSAddressOfSymbol( sym ); - -#elif defined(HAVE_DL_BEOS) +#if defined(HAVE_DL_BEOS) void * p_symbol; if( B_OK == get_image_symbol( handle, psz_function, B_SYMBOL_TYPE_TEXT, &p_symbol ) ) @@ -321,10 +268,13 @@ static void *module_Lookup( module_handle_t handle, const char *psz_function ) } #elif defined(HAVE_DL_WINDOWS) && defined(UNDER_CE) - wchar_t psz_real[256]; - MultiByteToWideChar( CP_ACP, 0, psz_function, -1, psz_real, 256 ); + wchar_t wide[strlen( psz_function ) + 1]; + size_t i = 0; + do + wide[i] = psz_function[i]; /* UTF-16 <- ASCII */ + while( psz_function[i++] ); - return (void *)GetProcAddress( handle, psz_real ); + return (void *)GetProcAddress( handle, wide ); #elif defined(HAVE_DL_WINDOWS) && defined(WIN32) return (void *)GetProcAddress( handle, (char *)psz_function );