<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<h2 id="note">Note</h2>
<p>Related to this problem is the fact that loading of modules stores pointer-to-functions inside pointer-to-void, which is undefined-behavior according to both the C and C++ Standard.</p>
<p>Fixing the above would require major changes to the codebase, and as such it is currently ignored.</p>
</blockquote>
<p>We currently have an issue with C++ modules not utilizing the proper linkage for the callbacks set when declaring the plugin. Since the given callbacks are invoked from code compiled as C, the callbacks shall have C linkage.</p>
<h2 id="example">Example</h2>
<p>The following is taken from <code>modules/access/live555.cpp</code>:</p>
<pre><code> 70: static int  Open ( vlc_object_t * );
 71: static void Close( vlc_object_t * );
   ...
 95: vlc_module_begin ()
   ...
 99:     set_callbacks( Open, Close )
   ...
142: vlc_module_end ()</code></pre>
<p><code>Open</code> and <code>Close</code>, implicitly having C++ linkage, are indirectly stored in a variable of type <code>int(*)(vlc_object_t*)</code>, implicitly having C linkage, at <code>src/modules/modules.c:146</code> and <code>src/modules/modules.c:154</code>, respectivelly.</p>
<h2 id="proposed-resolution">Proposed Resolution</h2>
<p>In order to fix the issue the following patch can be applied. It will ensure that the type of <code>Open</code> and <code>Close</code> has C linkage, even though the functions themselves have internal linkage (due to <code>static</code>).</p>
<pre><code>--- a/modules/access/live555.cpp
+++ b/modules/access/live555.cpp
@@ -67,8 +67,10 @@ extern "C" {
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-static int  Open ( vlc_object_t * );
-static void Close( vlc_object_t * );
+extern "C" {
+  static int  Open ( vlc_object_t * );
+  static void Close( vlc_object_t * );
+}
 
 #define KASENNA_TEXT N_( "Kasenna RTSP dialect")
 #define KASENNA_LONGTEXT N_( "Kasenna servers use an old and nonstandard " \</code></pre>
<hr />
<hr />
<h2 id="questions">Questions</h2>
<ul>
<li>Any thoughts on the matter?</li>
<li>Should I go ahead and patch this everywhere it is required?</li>
</ul>