Boost logo

Boost :

Subject: Re: [boost] [Boost.DLL] Formal Review request
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2014-10-04 08:07:23


2014-10-04 15:24 GMT+04:00 Niall Douglas <s_sourceforge_at_[hidden]>:

> On 4 Oct 2014 at 12:41, Andrey Semashev wrote:
> <...>
>
> > All the major compilers do provide this, and a large
> > > number of the minor ones. When myself and Antony surveyed the
> > > situation during TypeIndex we were pleasantly surprised at just how
> > > widespread support is for some magic macro which expands to the
> > > mangled form of the enclosing function. Mangling schemes have also
> > > basically reduced to just two kinds in recent compilers, with the
> > > Microsoft mangling scheme considerably the harder to parse. Mangling
> > > schemes are also very stable over time. That makes this proposal
> > > tractable.
> >
> > We had a similar discussion already. IMO, the library in its core should
> not
> > rely on compiler specific features and should be implementable in pure
> C++ and
> > standard APIs. This ensures its portability. It doesn't matter how many
> > compilers implement the extension because there will always be the one
> that
> > doesn't.
>
> Andrey, please list here three C++ compilers which had at least one
> version release in the past five years which doesn't provide a magic
> macro expanding out to the mangling of the enclosing function.
>
> > In any case, I don't think that mangled names are useful for other
> reasons I
> > mentioned.
>
> With such support, the following:
>
> plugin = dll::import_variable_alias<my_plugin_api>(
> lib_path / "my_plugin_sum",
> "plugin",
> dll::load_mode::append_decorations
> );
>
> can become:
>
> BOOST_DLL_IMPORT(
> lib_path / "my_plugin_sum",
> BOOST_DLL_AUTO_ALIAS(my_namespace::plugin), // import a
> variable
> BOOST_DLL_AUTO_ALIAS(my_namespace::function), // import a
> function
> BOOST_DLL_AUTO_ALIAS(my_namespace::object), // import a class
> implementation
> ...
> )
>

TypeIndex approach works for object types, but not for function names. It
will return function signature, not its real name:

BOOST_DLL_AUTO_ALIAS(my_namespace::function) == "void(int)" // not a
mangled "my_namespace::adl_barrier::function(int)" string

I see no way to extract function name from compiler internals. Implementing
mangling for variables only is a task that does not worth wasting time,
because exporting functions is a much more popular case than exporting
variables.

Any attempt to implement mangling of strings from scratch (from
"my_namespace::function" for example) will cause many hard detectable
errors. It would be also hard for user to use such macro, because provided
string must specify full typename with namespace for every input variable.
For a function that accepts some boost::variant or boost::mpl::vector
variables such string could be more than 10 Kbytes. Portability and
reliability of such method will not match high standards of Boost.

-- 
Best regards,
Antony Polukhin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk