r4123 - trunk/bse



Author: timj
Date: 2006-12-03 19:03:49 -0500 (Sun, 03 Dec 2006)
New Revision: 4123

Modified:
   trunk/bse/ChangeLog
   trunk/bse/bsecxxplugin.cc
   trunk/bse/bsecxxplugin.hh
   trunk/bse/bseexports.h
   trunk/bse/bseplugin.c
   trunk/bse/bseplugin.h
Log:
Sun Dec  3 19:13:17 2006  Tim Janik  <timj gtk org>

        * bseexports.h: changed plugin mechanism to skip per-plugin names and
        to provide feature flag masks to check plugin requirements (to check
        for MMX/SSE support).

        * bsecxxplugin.hh, bsecxxplugin.cc: changed symbol export mechanism to 
        use Bse::ExportTypeKeeper constructor and destructor instead of single
        symbols. use bse_exports__add_node() and bse_exports__del_node() to
        register/unregister the type nodes. this allows compilation of multiple
        C++ plugin types into the same .so binary.

        * bseplugin.h, bseplugin.c: rewrote plugin symbol lookup and type node 
        exports to support load time registration via bse_exports__add_node()
        and bse_exports__del_node().




Modified: trunk/bse/ChangeLog
===================================================================
--- trunk/bse/ChangeLog	2006-12-03 23:58:07 UTC (rev 4122)
+++ trunk/bse/ChangeLog	2006-12-04 00:03:49 UTC (rev 4123)
@@ -1,3 +1,19 @@
+Sun Dec  3 19:13:17 2006  Tim Janik  <timj gtk org>
+
+	* bseexports.h: changed plugin mechanism to skip per-plugin names and
+	to provide feature flag masks to check plugin requirements (to check
+	for MMX/SSE support).
+
+	* bsecxxplugin.hh, bsecxxplugin.cc: changed symbol export mechanism to 
+	use Bse::ExportTypeKeeper constructor and destructor instead of single
+	symbols. use bse_exports__add_node() and bse_exports__del_node() to
+	register/unregister the type nodes. this allows compilation of multiple
+	C++ plugin types into the same .so binary.
+
+	* bseplugin.h, bseplugin.c: rewrote plugin symbol lookup and type node 
+	exports to support load time registration via bse_exports__add_node()
+	and bse_exports__del_node().
+
 Sun Dec  3 21:13:32 2006  Stefan Westerfeld  <stefan space twc de>
 
 	* bsedatahandle-fir.cc: Made state size computation work correctly.

Modified: trunk/bse/bsecxxplugin.cc
===================================================================
--- trunk/bse/bsecxxplugin.cc	2006-12-03 23:58:07 UTC (rev 4122)
+++ trunk/bse/bsecxxplugin.cc	2006-12-04 00:03:49 UTC (rev 4123)
@@ -16,8 +16,32 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  */
 #include "bsecxxplugin.hh"
+#include "bseplugin.h"
+#include "bsemain.h"
 #include <new>
 
-namespace {
+namespace Bse {
 
-} // anon
+BsePlugin*
+ExportTypeKeeper::plugin_export_node (const ::BseExportIdentity *plugin_identity,
+                                      ::BseExportNode           *enode)
+{
+  if (plugin_identity == &bse_builtin_export_identity)
+    {
+      /* handle builtin types */
+      enode->next = bse_builtin_export_identity.export_chain;
+      bse_builtin_export_identity.export_chain = enode;
+      return NULL;
+    }
+  else
+    return bse_exports__add_node (plugin_identity, enode);
+}
+
+void
+ExportTypeKeeper::plugin_cleanup (BsePlugin                 *plugin,
+                                  ::BseExportNode           *enode)
+{
+  bse_exports__del_node (plugin, enode);
+}
+
+} // Bse

Modified: trunk/bse/bsecxxplugin.hh
===================================================================
--- trunk/bse/bsecxxplugin.hh	2006-12-03 23:58:07 UTC (rev 4122)
+++ trunk/bse/bsecxxplugin.hh	2006-12-04 00:03:49 UTC (rev 4123)
@@ -18,15 +18,6 @@
 #ifndef __BSE_CXX_PLUGIN_H__
 #define __BSE_CXX_PLUGIN_H__
 
-/* default plugin name specification (if omitted in plugin) */
-#ifndef BSE_PLUGIN_NAME
-#  ifdef BSE_PLUGIN_FALLBACK
-#    define BSE_PLUGIN_NAME BSE_PLUGIN_FALLBACK
-#  else /* !BSE_PLUGIN_NAME && !BSE_PLUGIN_FALLBACK */
-#    define BSE_PLUGIN_NAME __FILE__
-#  endif /* !BSE_PLUGIN_NAME && !BSE_PLUGIN_FALLBACK */
-#endif /* !BSE_PLUGIN_NAME */
-
 #include <bse/bsecxxmodule.hh>
 #include <bse/bseexports.h>
 #include <bse/bseparam.h>
@@ -44,18 +35,12 @@
 /* -- export identity --- */
 /* provide plugin export identity, preceeding all type exports */
 #ifndef BSE_COMPILATION
-#define BSE_CXX_DEFINE_EXPORTS()                                                \
-  static ::BseExportNode __export_chain_head = { NULL, BSE_EXPORT_NODE_LINK, }; \
-  static ::BseExportIdentity __export_identity =                                \
-                    BSE_EXPORT_IDENTITY (BSE_PLUGIN_NAME, __export_chain_head); \
-  extern "C" {                                                                  \
-    extern ::BseExportIdentity *const BSE_EXPORT_IDENTITY_SYMBOL;               \
-    ::BseExportIdentity *const BSE_EXPORT_IDENTITY_SYMBOL = &__export_identity; \
-  }
-#define BSE_CXX_EXPORT_IDENTITY    __export_identity
+#define BSE_CXX_DEFINE_EXPORTS()               \
+  static ::BseExportIdentity __staticbse_export_identity = BSE_EXPORT_IDENTITY (*(::BseExportNode*) 0);
+#define BSE_CXX_EXPORT_IDENTITY    &__staticbse_export_identity
 #else   /* BSE internal "Plugins" */
 #define BSE_CXX_DEFINE_EXPORTS()
-#define BSE_CXX_EXPORT_IDENTITY    bse_builtin_export_identity
+#define BSE_CXX_EXPORT_IDENTITY    &bse_builtin_export_identity
 extern "C" {
 extern ::BseExportIdentity bse_builtin_export_identity; /* sync with bseplugin.h */
 };
@@ -95,7 +80,7 @@
   extern ::Bse::ExportTypeKeeper bse_type_keeper__7##HookType;          \
   ::Bse::ExportTypeKeeper                                               \
          bse_type_keeper__7##HookType (bse_export_node<HookType>,       \
-                                       &BSE_CXX_EXPORT_IDENTITY);
+                                       BSE_CXX_EXPORT_IDENTITY);
 
 /* --- enum registration --- */
 /* enum registration is based on a static ExportTypeKeeper
@@ -137,7 +122,7 @@
 #define BSE_CXX_REGISTER_ENUM(EnumType)                                 \
   ::Bse::ExportTypeKeeper                                               \
          bse_type_keeper__3##EnumType (bse_export_node<EnumType>,       \
-                                       &BSE_CXX_EXPORT_IDENTITY);
+                                       BSE_CXX_EXPORT_IDENTITY);
 /* convenience creator to allow easy assignments of GEnumValue structs */
 inline const GEnumValue
 EnumValue (int         int_value,
@@ -187,7 +172,7 @@
 #define BSE_CXX_REGISTER_RECORD(RecordType)                             \
   ::Bse::ExportTypeKeeper                                               \
          bse_type_keeper__1##RecordType (bse_export_node<RecordType>,   \
-                                         &BSE_CXX_EXPORT_IDENTITY);
+                                         BSE_CXX_EXPORT_IDENTITY);
 
 
 /* --- sequence registration --- */
@@ -223,7 +208,7 @@
 #define BSE_CXX_REGISTER_SEQUENCE(SequenceType)                                 \
   ::Bse::ExportTypeKeeper                                                       \
          bse_type_keeper__2##SequenceType (bse_export_node<SequenceType>,       \
-                                           &BSE_CXX_EXPORT_IDENTITY);
+                                           BSE_CXX_EXPORT_IDENTITY);
 
 
 /* --- procedure registration --- */
@@ -258,7 +243,7 @@
   }                                                                             \
   ::Bse::ExportTypeKeeper                                                       \
          bse_type_keeper__9##ProcType (bse_export_node<Procedure::ProcType>,    \
-                                   &BSE_CXX_EXPORT_IDENTITY);
+                                   BSE_CXX_EXPORT_IDENTITY);
 
 
 /* --- class registration --- */
@@ -303,7 +288,7 @@
   }                                                                             \
   ::Bse::ExportTypeKeeper                                                       \
          bse_type_keeper__0##Effect (bse_export_node<Effect>,                   \
-                                     &BSE_CXX_EXPORT_IDENTITY);
+                                     BSE_CXX_EXPORT_IDENTITY);
 /* implement static_data portions used by auto-generated classes */
 #define BSE_CXX_DEFINE_STATIC_DATA(ObjectType)                                  \
   ObjectType::StaticData ObjectType::static_data;
@@ -313,20 +298,25 @@
 class ExportTypeKeeper
 {
   BseExportNode    *enode;
-  explicit          ExportTypeKeeper (const ExportTypeKeeper&);
-  ExportTypeKeeper& operator=        (const ExportTypeKeeper&);
+  BsePlugin        *plugin;
+  static BsePlugin* plugin_export_node (const ::BseExportIdentity *plugin_identity,
+                                        ::BseExportNode           *enode);
+  static void       plugin_cleanup     (BsePlugin                 *plugin,
+                                        ::BseExportNode           *enode);
+  BIRNET_PRIVATE_CLASS_COPY (ExportTypeKeeper);
 public:
-  explicit          ExportTypeKeeper (::BseExportNode*   (*export_node) (),
-                                      ::BseExportIdentity *export_identity)
+  ExportTypeKeeper (::BseExportNode* (*export_node) (),
+                    ::BseExportIdentity *export_identity)
   {
-    enode = export_node ();
-    enode->next = export_identity->export_chain;
-    export_identity->export_chain = enode;
+    enode = export_node();
+    plugin = plugin_export_node (export_identity, enode);
   }
-  const GType get_type()
+  ~ExportTypeKeeper()
   {
-    return enode->type;
+    if (plugin)
+      plugin_cleanup (plugin, enode);
   }
+  const GType get_type()        { return enode->type; }
 };
 
 } // Bse

Modified: trunk/bse/bseexports.h
===================================================================
--- trunk/bse/bseexports.h	2006-12-03 23:58:07 UTC (rev 4122)
+++ trunk/bse/bseexports.h	2006-12-04 00:03:49 UTC (rev 4123)
@@ -121,19 +121,68 @@
 #define BSE_EXPORT_IDENTITY_SYMBOL      bse_export__identity
 #define BSE_EXPORT_IDENTITY_STRING     "bse_export__identity"
 typedef struct {
-  const gchar   *name;
   guint          major, minor, micro;
   guint          binary_age, interface_age;
+  guint          dummy1, dummy2, dummy3;
+  guint64        export_flags;
   BseExportNode *export_chain;
 } BseExportIdentity;
-#define BSE_EXPORT_IDENTITY(Name, HEAD)                                 \
-  { Name, BSE_MAJOR_VERSION, BSE_MINOR_VERSION, BSE_MICRO_VERSION,      \
-    BSE_BINARY_AGE, BSE_INTERFACE_AGE, &HEAD }
+#define BSE_EXPORT_IDENTITY(HEAD)                               \
+  { BSE_MAJOR_VERSION, BSE_MINOR_VERSION, BSE_MICRO_VERSION,    \
+    BSE_BINARY_AGE, BSE_INTERFACE_AGE, 0, 0, 0,                 \
+    BSE_EXPORT_CONFIG, &HEAD }
 
+#define BSE_EXPORT_FLAG_MMX      (0x1ull << 0)
+#define BSE_EXPORT_FLAG_MMXEXT   (0x1ull << 1)
+#define BSE_EXPORT_FLAG_3DNOW    (0x1ull << 2)
+#define BSE_EXPORT_FLAG_3DNOWEXT (0x1ull << 3)
+#define BSE_EXPORT_FLAG_SSE      (0x1ull << 4)
+#define BSE_EXPORT_FLAG_SSE2     (0x1ull << 5)
+#define BSE_EXPORT_FLAG_SSE3     (0x1ull << 6)
+#define BSE_EXPORT_FLAG_SSE4     (0x1ull << 7)
+
+#define BSE_EXPORT_CONFIG       (BSE_EXPORT_CONFIG__MMX | BSE_EXPORT_CONFIG__3DNOW | \
+                                 BSE_EXPORT_CONFIG__SSE | BSE_EXPORT_CONFIG__SSE2 |  \
+                                 BSE_EXPORT_CONFIG__SSE3)
+
+
+
+BsePlugin*      bse_exports__add_node   (const BseExportIdentity *identity,     // bseplugin.c
+                                         BseExportNode           *enode);
+void            bse_exports__del_node   (BsePlugin               *plugin,       // bseplugin.c
+                                         BseExportNode           *enode);
+
 /* implementation prototype */
 void	bse_procedure_complete_info	(const BseExportNodeProc *pnode,
 					 GTypeInfo               *info);
 
+/* --- export config --- */
+#ifdef   __MMX__
+#define BSE_EXPORT_CONFIG__MMX   BSE_EXPORT_FLAG_MMX
+#else
+#define BSE_EXPORT_CONFIG__MMX   0
+#endif
+#ifdef  __3dNOW__
+#define BSE_EXPORT_CONFIG__3DNOW BSE_EXPORT_FLAG_3DNOW
+#else
+#define BSE_EXPORT_CONFIG__3DNOW 0
+#endif
+#ifdef  __SSE__
+#define BSE_EXPORT_CONFIG__SSE   BSE_EXPORT_FLAG_SSE
+#else
+#define BSE_EXPORT_CONFIG__SSE   0
+#endif
+#ifdef  __SSE2__
+#define BSE_EXPORT_CONFIG__SSE2  BSE_EXPORT_FLAG_SSE2
+#else
+#define BSE_EXPORT_CONFIG__SSE2  0
+#endif
+#ifdef  __SSE3__
+#define BSE_EXPORT_CONFIG__SSE3  BSE_EXPORT_FLAG_SSE3
+#else
+#define BSE_EXPORT_CONFIG__SSE3  0
+#endif
+
 G_END_DECLS
 
 #endif /* __BSE_EXPORTS_H__ */

Modified: trunk/bse/bseplugin.c
===================================================================
--- trunk/bse/bseplugin.c	2006-12-03 23:58:07 UTC (rev 4122)
+++ trunk/bse/bseplugin.c	2006-12-04 00:03:49 UTC (rev 4123)
@@ -50,7 +50,7 @@
 /* --- variables --- */
 static GSList       *bse_plugins = NULL;
 static BseExportNode builtin_export_chain_head = { NULL, BSE_EXPORT_NODE_LINK, };
-BseExportIdentity    bse_builtin_export_identity = BSE_EXPORT_IDENTITY (NULL, builtin_export_chain_head);
+BseExportIdentity    bse_builtin_export_identity = BSE_EXPORT_IDENTITY (builtin_export_chain_head);
 
 
 /* --- functions --- */
@@ -93,30 +93,47 @@
 bse_plugin_dispose (GObject *object)
 {
   BsePlugin *plugin = BSE_PLUGIN (object);
+
+  if (plugin->gmodule || plugin->use_count || plugin->n_types)
+    g_warning ("%s: plugin partially initialized during destruciton", G_STRFUNC);
   
-  g_warning ("%s: dispose should never happen for static plugins", G_STRFUNC);
-  
-  g_object_ref (object);
-  
   /* chain parent class handler */
   G_OBJECT_CLASS (g_type_class_peek_parent (BSE_PLUGIN_GET_CLASS (plugin)))->dispose (object);
 }
 
 static void
+bse_plugin_finalize (GObject *object)
+{
+  BsePlugin *plugin = BSE_PLUGIN (object);
+
+  if (plugin->gmodule || plugin->use_count || plugin->n_types)
+    g_warning ("%s: plugin partially initialized during destruciton", G_STRFUNC);
+  
+  /* chain parent class handler */
+  G_OBJECT_CLASS (g_type_class_peek_parent (BSE_PLUGIN_GET_CLASS (plugin)))->finalize (object);
+
+  g_free (plugin->fname);
+  g_free (plugin->types);
+}
+
+static void
 bse_plugin_class_init (BsePluginClass *class)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
   
   gobject_class->dispose = bse_plugin_dispose;
+  gobject_class->finalize = bse_plugin_finalize;
 }
 
 static void
 bse_plugin_init (BsePlugin *plugin)
 {
-  plugin->name = NULL;
   plugin->fname = NULL;
   plugin->gmodule = NULL;
+  plugin->missing_export_flags = 0;
   plugin->use_count = 0;
+  plugin->version_match = 1;
+  plugin->force_clean = 0;
   plugin->n_types = 0;
   plugin->types = NULL;
 }
@@ -145,8 +162,7 @@
               BsePlugin *plugin = g_object_new (BSE_TYPE_PLUGIN, NULL);
               g_object_ref (plugin);
               plugin->use_count = 1;
-              g_free (plugin->name);
-              plugin->name = g_strdup ("BSE-BUILTIN");
+              plugin->fname = g_strdup ("BSE-BUILTIN");
               plugin->chain = chain;
               bse_plugins = g_slist_prepend (bse_plugins, plugin);
               bse_plugin_init_types (plugin);
@@ -159,8 +175,7 @@
           BsePlugin *plugin = g_object_new (BSE_TYPE_PLUGIN, NULL);
           g_object_ref (plugin);
           plugin->use_count = 1;
-          g_free (plugin->name);
-          plugin->name = g_strdup ("BSE-CXX-BUILTIN");
+          plugin->fname = g_strdup ("BSE-CXX-BUILTIN");
           plugin->chain = bse_builtin_export_identity.export_chain;
           bse_plugins = g_slist_prepend (bse_plugins, plugin);
           bse_plugin_init_types (plugin);
@@ -168,15 +183,79 @@
     }
 }
 
-static BseExportIdentity*
-lookup_export_identity (GModule *gmodule)
+static guint64
+runtime_export_config (void)
 {
-  BseExportIdentity **symbol_p = NULL;
-  if (g_module_symbol (gmodule, BSE_EXPORT_IDENTITY_STRING, (gpointer) &symbol_p))
+  SfiCPUInfo cinfo = sfi_cpu_info();
+  guint64 emask = 0;
+  if (cinfo.x86_mmx)
+    emask |= BSE_EXPORT_FLAG_MMX;
+  if (cinfo.x86_mmxext)
+    emask |= BSE_EXPORT_FLAG_MMXEXT;
+  if (cinfo.x86_3dnow)
+    emask |= BSE_EXPORT_FLAG_3DNOW;
+  if (cinfo.x86_3dnowext)
+    emask |= BSE_EXPORT_FLAG_3DNOWEXT;
+  if (cinfo.x86_sse && cinfo.x86_ssesys)
+    emask |= BSE_EXPORT_FLAG_SSE;
+  if (cinfo.x86_sse2 && cinfo.x86_ssesys)
+    emask |= BSE_EXPORT_FLAG_SSE2;
+  if (cinfo.x86_sse3 && cinfo.x86_ssesys)
+    emask |= BSE_EXPORT_FLAG_SSE3;
+  if (cinfo.x86_sse4 && cinfo.x86_ssesys)
+    emask |= BSE_EXPORT_FLAG_SSE4;
+  return emask;
+}
+
+static BsePlugin *startup_plugin = NULL;
+
+BsePlugin*
+bse_exports__add_node (const BseExportIdentity *identity,
+                       BseExportNode           *enode)
+{
+  if (!startup_plugin)
+    g_error ("%s: plugin startup called without plugin", G_STRFUNC);
+  if (!enode || enode->next)
+    return NULL;
+  if (identity->major != BSE_MAJOR_VERSION ||
+      identity->minor != BSE_MINOR_VERSION ||
+      identity->micro != BSE_MICRO_VERSION)
+    startup_plugin->version_match = false;
+  startup_plugin->missing_export_flags = identity->export_flags & ~runtime_export_config();
+  if (startup_plugin->version_match && !startup_plugin->missing_export_flags)
     {
-      if (symbol_p)
-        return *symbol_p;
+      enode->next = startup_plugin->chain;
+      startup_plugin->chain = enode;
     }
+  return startup_plugin;
+}
+
+static const char*
+plugin_check_identity (BsePlugin *plugin,
+                       GModule   *gmodule)
+{
+  if (!plugin->chain)
+    {
+      /* handle legacy C plugins */
+      BseExportIdentity **symbol_p = NULL;
+      if (g_module_symbol (gmodule, BSE_EXPORT_IDENTITY_STRING, (gpointer) &symbol_p) && *symbol_p)
+        {
+          BseExportIdentity *identity = *symbol_p;
+          if (identity->major != BSE_MAJOR_VERSION ||
+              identity->minor != BSE_MINOR_VERSION ||
+              identity->micro != BSE_MICRO_VERSION)
+            plugin->version_match = false;
+          plugin->missing_export_flags = identity->export_flags & ~runtime_export_config();
+          plugin->chain = identity->export_chain;
+          plugin->force_clean = true;
+        }
+    }
+
+  if (!plugin->version_match)
+    return "Invalid BSE Plugin Version";
+  if (plugin->missing_export_flags)
+    return "Incompatible CPU requirements";
+
   return NULL;
 }
 
@@ -190,24 +269,48 @@
   g_object_ref (G_OBJECT (plugin));
   if (!plugin->use_count)
     {
-      BseExportIdentity *plugin_identity;
-
-      DEBUG ("reloading-plugin: %s (\"%s\")", plugin->name, plugin->fname ? plugin->fname : "???NULL???");
+      DEBUG ("reloading-plugin: %s", plugin->fname);
       
       plugin->use_count++;
+      startup_plugin = plugin;
       plugin->gmodule = g_module_open (plugin->fname, 0); /* reopen for use non-lazy */
-      plugin_identity = plugin->gmodule ? lookup_export_identity (plugin->gmodule) : NULL;
-      if (!plugin->gmodule || !plugin_identity)
-	g_error ("failed to reinitialize plugin: %s", g_module_error ());
+      startup_plugin = NULL;
+      if (!plugin->gmodule)
+	g_error ("failed to reinitialize plugin \"%s\": %s", plugin->fname, g_module_error ());
+      const char *cerror = plugin_check_identity (plugin, plugin->gmodule);
+      if (cerror)
+	g_error ("failed to reinitialize plugin \"%s\": %s", plugin->fname, cerror);
+      if (!plugin->chain)
+	g_error ("failed to reinitialize plugin \"%s\": %s", plugin->fname, "empty plugin");
 
-      plugin->chain = plugin_identity->export_chain;
-
       bse_plugin_reinit_types (plugin);
     }
   else
     plugin->use_count++;
 }
 
+void
+bse_exports__del_node (BsePlugin               *plugin,
+                       BseExportNode           *enode)
+{
+  if (!plugin || !enode)
+    {
+      g_warning ("%s: invalid plugin shutdown", G_STRFUNC);
+      return;
+    }
+  BseExportNode *last = NULL, *link;
+  for (link = plugin->chain; link; last = link, link = last->next)
+    if (enode == link)
+      {
+        if (last)
+          last->next = link->next;
+        else
+          plugin->chain = link->next;
+        return;
+      }
+  g_warning ("%s: plugin attempt to unregister invalid export node: %s", plugin->fname, enode->name);
+}
+
 static void
 bse_plugin_unload (BsePlugin *plugin)
 {
@@ -219,9 +322,10 @@
   plugin->gmodule = NULL;
   
   /* reset plugin local pointers */
-  plugin->chain = NULL;
+  if (plugin->force_clean)
+    plugin->chain = NULL;
   
-  DEBUG ("unloaded-plugin: %s", plugin->name);
+  DEBUG ("unloaded-plugin: %s", plugin->fname);
 }
 
 static void
@@ -311,7 +415,7 @@
         break;
       }
   if (!node || node->type != type)
-    g_error ("%s: unable to complete type from plugin: %s", plugin->name, g_type_name (type));
+    g_error ("%s: unable to complete type from plugin: %s", plugin->fname, g_type_name (type));
 }
 
 static void
@@ -337,7 +441,7 @@
               }
           if (!found_type)
             g_message ("%s: plugin attempts to reregister foreign type: %s",
-                       plugin->name, node->name);
+                       plugin->fname, node->name);
           else if (node->ntype == BSE_EXPORT_NODE_ENUM)
             {
               BseExportNodeEnum *enode = (BseExportNodeEnum*) node;
@@ -350,7 +454,7 @@
         }
     }
   while (n--)
-    g_message ("%s: plugin failed to reregister type: %s", plugin->name, g_type_name (types[n]));
+    g_warning ("%s: plugin failed to reregister type: %s", plugin->fname, g_type_name (types[n]));
   g_free (types);
 }
 
@@ -373,13 +477,13 @@
         if (!type)
           {
             g_message ("%s: plugin type %s derives from unknown parent type: %s",
-                       plugin->name, node->name, cnode->parent);
+                       plugin->fname, node->name, cnode->parent);
             return;
           }
         if (!BSE_TYPE_IS_OBJECT (type))
           {
             g_message ("%s: plugin object type %s derives from non-object type: %s",
-                       plugin->name, node->name, cnode->parent);
+                       plugin->fname, node->name, cnode->parent);
             return;
           }
       case BSE_EXPORT_NODE_HOOK:
@@ -391,7 +495,7 @@
         if (type)
           {
             g_message ("%s: plugin contains type already registered: %s",
-                       plugin->name, node->name);
+                       plugin->fname, node->name);
             return;
           }
         break;
@@ -439,10 +543,10 @@
           error = bse_procedure_type_register (node->name, plugin, &type);
           if (error)
             g_message ("%s: while registering procedure \"%s\": %s",
-                       plugin->name, node->name, error);
+                       plugin->fname, node->name, error);
           break;
         default:
-          g_message ("%s: plugin contains invalid type node (%u)", plugin->name, node->ntype);
+          g_message ("%s: plugin contains invalid type node (%u)", plugin->fname, node->ntype);
           node = NULL;
           break;
         }
@@ -494,7 +598,6 @@
 const gchar*
 bse_plugin_check_load (const gchar *const_file_name)
 {
-  BseExportIdentity *plugin_identity;
   gchar *file_name;
   GModule *gmodule;
   gchar *error = NULL;
@@ -553,12 +656,17 @@
   DEBUG ("register: %s", file_name);
 
   /* load module */
+  BsePlugin *plugin = g_object_new (BSE_TYPE_PLUGIN, NULL);
+  plugin->fname = g_strdup (file_name);
+  startup_plugin = plugin;
   gmodule = g_module_open (file_name, G_MODULE_BIND_LAZY);
+  startup_plugin = NULL;
   if (!gmodule)
     {
       cerror = g_module_error ();
       DEBUG ("error: %s: %s", file_name, cerror);
       g_free (file_name);
+      g_object_unref (plugin);
       return cerror;
     }
   if (bse_plugin_find (gmodule))
@@ -567,39 +675,26 @@
       cerror = "Plugin already loaded";
       DEBUG ("error: %s: %s", file_name, cerror);
       g_free (file_name);
+      g_object_unref (plugin);
       return cerror;
     }
 
   /* verify plugin identity (BSE + version) */
-  plugin_identity = lookup_export_identity (gmodule);
-  if (!plugin_identity || !plugin_identity->name)
+  cerror = plugin_check_identity (plugin, gmodule);
+  if (cerror)
     {
       g_module_close (gmodule);
-      cerror = "Not a BSE Plugin";
       DEBUG ("error: %s: %s", file_name, cerror);
       g_free (file_name);
+      g_object_unref (plugin);
       return cerror;
     }
-  if (plugin_identity->major != BSE_MAJOR_VERSION ||
-      plugin_identity->minor != BSE_MINOR_VERSION ||
-      plugin_identity->micro != BSE_MICRO_VERSION)
-    {
-      g_module_close (gmodule);
-      cerror = "Invalid BSE Plugin Version";
-      DEBUG ("error: %s: %s", file_name, cerror);
-      g_free (file_name);
-      return cerror;
-    }
 
   /* create plugin if this is a BSE plugin with valid type chain */
-  if (plugin_identity->export_chain)
+  if (plugin->chain)
     {
-      BsePlugin *plugin = g_object_new (BSE_TYPE_PLUGIN, NULL);
-      g_free (plugin->name);
-      plugin->name = g_strdup (plugin_identity->name);
       plugin->fname = file_name;
       plugin->gmodule = gmodule;
-      plugin->chain = plugin_identity->export_chain;
       
       /* register BSE module types */
       bse_plugin_init_types (plugin);
@@ -614,29 +709,12 @@
       error = NULL; /* empty plugin */
       DEBUG ("plugin empty: %s", file_name);
       g_free (file_name);
+      g_object_unref (plugin);
     }
 
   return error;
 }
 
-BsePlugin*
-bse_plugin_lookup (const gchar *name)
-{
-  GSList *slist;
-  
-  g_return_val_if_fail (name != NULL, NULL);
-  
-  for (slist = bse_plugins; slist; slist = slist->next)
-    {
-      BsePlugin *plugin = slist->data;
-      
-      if (bse_string_equals (name, plugin->name))
-	return plugin;
-    }
-  
-  return NULL;
-}
-
 #include "topconfig.h"
 
 static bool

Modified: trunk/bse/bseplugin.h
===================================================================
--- trunk/bse/bseplugin.h	2006-12-03 23:58:07 UTC (rev 4122)
+++ trunk/bse/bseplugin.h	2006-12-04 00:03:49 UTC (rev 4123)
@@ -18,15 +18,6 @@
 #ifndef __BSE_PLUGIN_H__
 #define __BSE_PLUGIN_H__
 
-/* default plugin name specification (if omitted in plugin) */
-#ifndef BSE_PLUGIN_NAME
-#  ifdef BSE_PLUGIN_FALLBACK
-#    define BSE_PLUGIN_NAME BSE_PLUGIN_FALLBACK
-#  else /* !BSE_PLUGIN_NAME && !BSE_PLUGIN_FALLBACK */
-#    define BSE_PLUGIN_NAME __FILE__
-#  endif /* !BSE_PLUGIN_NAME && !BSE_PLUGIN_FALLBACK */
-#endif /* !BSE_PLUGIN_NAME */
-
 #include	<bse/bse.h>	/* for bse_check_version() */
 #include	<bse/bseexports.h>
 
@@ -47,10 +38,12 @@
 {
   GObject	 parent_instance;
 
-  gchar		*name;
   gchar		*fname;
   gpointer	 gmodule;
+  guint64        missing_export_flags;
   guint		 use_count : 16;
+  guint          version_match : 1;
+  guint          force_clean : 1;
 
   BseExportNode *chain;
   guint		 n_types;
@@ -66,23 +59,22 @@
 SfiRing*	bse_plugin_path_list_files	(gboolean        include_drivers,
                                                  gboolean        include_plugins);
 const gchar*	bse_plugin_check_load		(const gchar	*file_name);
-BsePlugin*	bse_plugin_lookup		(const gchar	*name);
 
 
 /* --- registration macros --- */
 
 #ifdef __cplusplus
-#define BSE_DEFINE_EXPORTS(PluginName)                                                          \
+#define BSE_DEFINE_EXPORTS()                                                                    \
     static ::BseExportIdentity __bse_export_identity =                                          \
-                               BSE_EXPORT_IDENTITY (BSE_PLUGIN_NAME, __enode_chain_head);       \
+                               BSE_EXPORT_IDENTITY (__enode_chain_head);                        \
   extern "C" {                                                                                  \
     extern ::BseExportIdentity *const BSE_EXPORT_IDENTITY_SYMBOL;                               \
     ::BseExportIdentity *const BSE_EXPORT_IDENTITY_SYMBOL = &__bse_export_identity;             \
   }
 #else
-#define BSE_DEFINE_EXPORTS(PluginName)                                                          \
+#define BSE_DEFINE_EXPORTS()                                                                    \
   static BseExportIdentity __bse_export_identity =                                              \
-                             BSE_EXPORT_IDENTITY (BSE_PLUGIN_NAME, __enode_chain_head);         \
+                             BSE_EXPORT_IDENTITY (__enode_chain_head);                          \
   BseExportIdentity *const BSE_EXPORT_IDENTITY_SYMBOL = &__bse_export_identity
 #endif
 
@@ -109,7 +101,7 @@
 
 
 /* --- implementation details --- */
-void		         bse_plugin_init_builtins     (void);
+void		         bse_plugin_init_builtins       (void);
 extern BseExportIdentity bse_builtin_export_identity; /* sync with bsecxxplugin.hh */
 
 G_END_DECLS




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]