[vlc-devel] Callbacks in modules written in C++ have wrong linkage
Filip Roséen
filip at atch.se
Mon Feb 22 13:37:40 CET 2016
> Note
> --------
> 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.
>
> Fixing the above would require major changes to the codebase, and as
> such it is currently ignored.
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.
Example
-------
The following is taken from `modules/access/live555.cpp`:
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 ()
`Open` and `Close`, implicitly having C++ linkage, are indirectly stored
in a variable of type `int(*)(vlc_object_t*)`, implicitly having C
linkage, at `src/modules/modules.c:146` and `src/modules/modules.c:154`,
respectivelly.
Proposed Resolution
-------------------
In order to fix the issue the following patch can be applied. It will
ensure that the type of `Open` and `Close` has C linkage, even though
the functions themselves have internal linkage (due to `static`).
--- 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 " \
------------------------------------------------------------------------
------------------------------------------------------------------------
Questions
---------
- Any thoughts on the matter?
- Should I go ahead and patch this everywhere it is required?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20160222/00ef912b/attachment.html>
More information about the vlc-devel
mailing list