]> git.sesse.net Git - vlc/blobdiff - src/modules/os.c
Privatize vlc_module_create()
[vlc] / src / modules / os.c
index 38df5e77159e8407c41125306ed338498d863f22..4a8912799533be8bc24249e5d12662685172cf7f 100644 (file)
@@ -70,7 +70,7 @@
  * Local prototypes
  *****************************************************************************/
 #ifdef HAVE_DYNAMIC_PLUGINS
-static void * GetSymbol        ( module_handle_t, const char * );
+static void *module_Lookup( module_handle_t, const char * );
 
 #if defined(HAVE_DL_WINDOWS)
 static char * GetWindowsError  ( void );
@@ -90,7 +90,8 @@ int module_Call( vlc_object_t *obj, module_t *p_module )
     int (* pf_symbol) ( module_t * p_module );
 
     /* Try to resolve the symbol */
-    pf_symbol = (int (*)(module_t *)) GetSymbol( p_module->handle, psz_name );
+    pf_symbol = (int (*)(module_t *)) module_Lookup( p_module->handle,
+                                                     psz_name );
 
     if( pf_symbol == NULL )
     {
@@ -132,7 +133,7 @@ int module_Call( vlc_object_t *obj, module_t *p_module )
 /* Make sure libvlccore is in the global namespace */
 static void load_libvlccore( void )
 {
-    if( !dlsym( RTLD_DEFAULT, "vlc_module_create" )
+    if( !dlsym( RTLD_DEFAULT, "libvlc_Quit" )
      && !dlopen( "libvlccore.so", RTLD_GLOBAL|RTLD_NOLOAD ) )
         fprintf( stderr, "ERROR: failed loading libvlccore\n" );
 }
@@ -213,27 +214,21 @@ int module_Load( vlc_object_t *p_this, const char *psz_file,
         return -1;
     }
 
-#elif defined(HAVE_DL_DLOPEN) && defined(RTLD_NOW)
+#elif defined(HAVE_DL_DLOPEN)
 # if defined (RTLD_NOLOAD)
     static pthread_once_t once = PTHREAD_ONCE_INIT;
     pthread_once( &once, &load_libvlccore );
 # endif
 
-    /* static is OK, we are called atomically */
-    handle = dlopen( psz_file, RTLD_NOW );
-    if( handle == NULL )
-    {
-        msg_Warn( p_this, "cannot load module `%s' (%s)",
-                          psz_file, dlerror() );
-        return -1;
-    }
+# if defined (RTLD_NOW)
+    const int flags = RTLD_NOW;
+# elif defined (DL_LAZY)
+    const int flags = DL_LAZY;
+# else
+    const int flags = 0;
+# endif
 
-#elif defined(HAVE_DL_DLOPEN)
-#   if defined(DL_LAZY)
-    handle = dlopen( psz_file, DL_LAZY );
-#   else
-    handle = dlopen( psz_file, 0 );
-#   endif
+    handle = dlopen( psz_file, flags );
     if( handle == NULL )
     {
         msg_Warn( p_this, "cannot load module `%s' (%s)",
@@ -293,41 +288,24 @@ void module_Unload( module_handle_t handle )
 }
 
 /**
- * GetSymbol: get a symbol from a dynamic library
+ * Looks up a symbol from a dynamically loaded library
  *
  * This function queries a loaded library for a symbol specified in a
  * string, and returns a pointer to it. We don't check for dlerror() or
  * similar functions, since we want a non-NULL symbol anyway.
- * \param handle handle to the module
- * \param psz_function function name
- * \return nothing
+ *
+ * @param handle handle to the module
+ * @param psz_function function name
+ * @return NULL on error, or the address of the symbol
  */
-static void * _module_getsymbol( module_handle_t, const char * );
-
-static void * GetSymbol( module_handle_t handle, const char * psz_function )
-{
-    void * p_symbol = _module_getsymbol( handle, psz_function );
-
-    /* MacOS X dl library expects symbols to begin with "_". So do
-     * some other operating systems. That's really lame, but hey, what
-     * can we do ? */
-    if( p_symbol == NULL )
-    {
-        char psz_call[strlen( psz_function ) + 2];
-
-        psz_call[ 0 ] = '_';
-        memcpy( psz_call + 1, psz_function, sizeof (psz_call) - 1 );
-        p_symbol = _module_getsymbol( handle, psz_call );
-    }
-
-    return p_symbol;
-}
-
-static void * _module_getsymbol( module_handle_t handle,
-                                 const char * psz_function )
+static void *module_Lookup( module_handle_t handle, const char *psz_function )
 {
 #if defined(HAVE_DL_DYLD)
-    NSSymbol sym = NSLookupSymbolInModule( handle, psz_function );
+    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)
@@ -343,10 +321,13 @@ static void * _module_getsymbol( module_handle_t handle,
     }
 
 #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 );