[vlc-devel] Callbacks in modules written in C++ have wrong linkage

Filip Roséen filip at atch.se
Mon Feb 22 19:53:38 CET 2016


I spent some time coming up with a draft-patch that fixes the issues described
in the earlier post.

The process was quite straight forward (even though mind numbing), and
most modules were fixed with very small patches. Very few required more work, as
detailed in the upcoming sections.

I do not want to pollute `vlc-devel` with another patch-bomb (17 commits) prior
to getting some input on patch.

  - What do you guys think?



`modules/services_discovery/upnp.cpp`
-------------------------------------

The most dramatic change happend in `modules/services_discovery/upnp.cpp` where
we, in order to have functions with the correct linkage, have to move
`SD::{Open,Close}` as well as `Access::{Open,Close}` from within their
respective namespace.

This in turn means that the functions, in order to have
proper linkage, had to be renamed to `SD_{Open,Close}` and `Access_{Open,Close}`
to avoid name-collision in the global scope.

An alternative solution would be to introduce simple wrapper functions with
proper linkage, that only calls the affected ones.



`modules/demux/adaptive/PlaylistManager.h`
------------------------------------------

`demux/adaptive` uses `static` *member-functions* when supplying `libvlc` with
callbacks. The problem with such approach is that it is impossible to declare
such functions with `extern "C"` on the normal point of declaration (since the
standard says that *linkage-specifications* belong in namespace scope).

In order to circumvent the issue the following approach has been applied: 

    namespace Foo {
      extern "C" {
        typedef int(*callback_t)(demux_t*);
      }

      class Bar {
        static callback_t baz_cb;
      };
    }


In the above `Foo::baz_cb` will have C linkage, but disregarding that it is
directly equivalent to the below:

    namespace Foo {
      class Bar {
        static int baz_cb (demux_t*);
      };
    }

--------------------------------------------------------------------------------

On 16/02/22 13:37, Filip Roséen wrote:

> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20160222/ec9a5071/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: errorneous_linkage-draft.patch
Type: text/x-diff
Size: 29239 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20160222/ec9a5071/attachment.patch>


More information about the vlc-devel mailing list