[vlc-commits] Inline module_Call()

Rémi Denis-Courmont git at videolan.org
Thu May 12 23:02:12 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu May 12 22:23:51 2011 +0300| [bdc46e27b25d35169380632df8ad9971530a1bf3] | committer: Rémi Denis-Courmont

Inline module_Call()

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

 src/modules/modules.c |   34 +++++++++++++++++++++---------
 src/modules/modules.h |    4 +-
 src/modules/os.c      |   54 +------------------------------------------------
 3 files changed, 27 insertions(+), 65 deletions(-)

diff --git a/src/modules/modules.c b/src/modules/modules.c
index 5a5d241..14631aa 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -1059,21 +1059,35 @@ static module_t * AllocatePlugin( vlc_object_t * p_this, const char *psz_file )
     p_module->b_loaded = true;
 
     /* Initialize the module: fill p_module, default config */
-    if( module_Call( p_this, p_module ) != 0 )
+    static const char entry[] = "vlc_entry" MODULE_SUFFIX;
+
+    /* Try to resolve the symbol */
+    int (*pf_symbol)(module_t * p_module)
+        = (int (*)(module_t *)) module_Lookup( p_module->handle,entry );
+    if( pf_symbol == NULL )
     {
-        /* We couldn't call module_init() */
-        free( p_module->psz_filename );
-        module_release( p_module );
-        module_Unload( handle );
-        return NULL;
+        msg_Warn( p_this, "cannot find symbol \"%s\" in plugin `%s'",
+                  entry, psz_file );
+        goto error;
+    }
+    else
+    /* We can now try to call the symbol */
+    if( pf_symbol( p_module ) != 0 )
+    {
+        /* With a well-written module we shouldn't have to print an
+         * additional error message here, but just make sure. */
+        msg_Err( p_this, "cannot initialize plugin `%s'", psz_file );
+        goto error;
     }
 
     DupModule( p_module );
-
-    /* Everything worked fine ! The module is ready to be added to the list. */
-    p_module->b_builtin = false;
-
+    assert( !p_module->b_builtin );
     return p_module;
+error:
+    free( p_module->psz_filename );
+    module_release( p_module );
+    module_Unload( handle );
+    return NULL;
 }
 
 /*****************************************************************************
diff --git a/src/modules/modules.h b/src/modules/modules.h
index c972368..511b40a 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -143,8 +143,8 @@ void module_EndBank( vlc_object_t *, bool );
 int vlc_bindtextdomain (const char *);
 
 /* Low-level OS-dependent handler */
-int  module_Load   (vlc_object_t *, const char *, module_handle_t *);
-int  module_Call   (vlc_object_t *obj, module_t *);
+int module_Load (vlc_object_t *, const char *, module_handle_t *);
+void *module_Lookup (module_handle_t, const char *);
 void module_Unload (module_handle_t);
 
 /* Plugins cache */
diff --git a/src/modules/os.c b/src/modules/os.c
index e4cfdac..5f5e8fc 100644
--- a/src/modules/os.c
+++ b/src/modules/os.c
@@ -66,63 +66,11 @@
  * Local prototypes
  *****************************************************************************/
 #ifdef HAVE_DYNAMIC_PLUGINS
-static void *module_Lookup( module_handle_t, const char * );
-
 #if defined(HAVE_DL_WINDOWS)
 static char * GetWindowsError  ( void );
 #endif
 
 /**
- * module Call
- *
- * Call a symbol given its name and a module structure. The symbol MUST
- * refer to a function returning int and taking a module_t* as an argument.
- * \param p_module the modules
- * \return 0 if it pass and -1 in case of a failure
- */
-int module_Call( vlc_object_t *obj, module_t *p_module )
-{
-    static const char psz_name[] = "vlc_entry" MODULE_SUFFIX;
-    int (* pf_symbol) ( module_t * p_module );
-
-    /* Try to resolve the symbol */
-    pf_symbol = (int (*)(module_t *)) module_Lookup( p_module->handle,
-                                                     psz_name );
-
-    if( pf_symbol == NULL )
-    {
-#if defined(HAVE_DL_WINDOWS)
-        char *psz_error = GetWindowsError();
-        msg_Warn( obj, "cannot find symbol \"%s\" in file `%s' (%s)",
-                  psz_name, p_module->psz_filename, psz_error );
-        free( psz_error );
-#elif defined(HAVE_DL_DLOPEN)
-        msg_Warn( obj, "cannot find symbol \"%s\" in file `%s' (%s)",
-                  psz_name, p_module->psz_filename, dlerror() );
-#elif defined(HAVE_DL_SHL_LOAD)
-        msg_Warn( obj, "cannot find symbol \"%s\" in file `%s' (%m)",
-                  psz_name, p_module->psz_filename );
-#else
-#   error "Something is wrong in modules.c"
-#endif
-        return -1;
-    }
-
-    /* We can now try to call the symbol */
-    if( pf_symbol( p_module ) != 0 )
-    {
-        /* With a well-written module we shouldn't have to print an
-         * additional error message here, but just make sure. */
-        msg_Err( obj, "Failed to call symbol \"%s\" in file `%s'",
-                 psz_name, p_module->psz_filename );
-        return -1;
-    }
-
-    /* Everything worked fine, we can return */
-    return 0;
-}
-
-/**
  * Load a dynamically linked library using a system dependent method.
  *
  * \param p_this vlc object
@@ -235,7 +183,7 @@ void module_Unload( module_handle_t handle )
  * @param psz_function function name
  * @return NULL on error, or the address of the symbol
  */
-static void *module_Lookup( module_handle_t handle, const char *psz_function )
+void *module_Lookup( module_handle_t handle, const char *psz_function )
 {
 #if defined(HAVE_DL_WINDOWS) && defined(UNDER_CE)
     wchar_t wide[strlen( psz_function ) + 1];



More information about the vlc-commits mailing list