|
Boost : |
Subject: [boost] [Regex] Calling convention for _MANAGED code still somewhat broken when mixing native and managed projects
From: Martin B. (0xCDCDCDCD_at_[hidden])
Date: 2011-12-02 00:59:17
Hi there!
Background
----------
The header boost/regex/config.hpp currently contains the following code:
#if defined(BOOST_MSVC) && (BOOST_MSVC >= 1200) && defined(_MSC_EXTENSIONS)
#if defined(_DEBUG) || defined(__MSVC_RUNTIME_CHECKS) || defined(_MANAGED)
# define BOOST_REGEX_CALL __cdecl
#else
# define BOOST_REGEX_CALL __fastcall
#endif
# define BOOST_REGEX_CCALL __cdecl
#endif
the `|| defined(_MANAGED)` was added in 2006 (SVN history) to cater for
the fact that __fastcall does not work on managed C++/CLI (/clr
compiled) projects.
See, e.g. this: http://lists.boost.org/boost-users/2004/12/9203.php
Problem
-------
This is really quite suboptimal, as with the solution as posted above,
you need *a separate* lib/dll for managed-C++ and native-C++ Projects.
Especially for the DLL, this is a non-solution, as I can only have one
DLL for projects/modules that are used in the same application.
_MANAGED is a define set by the VC compiler if the /clr switch is
present, therefore it is actually never set when compiling the boost
libraries. Of course you can set it via `define=_MANAGED` and you can
then use these generated libraries from a C++/CLI project. (Which I have
done: ... `define=_MANAGED` ... --with-regex ...)
BUT: You can now *not* use these libraries from a non-managed ("native")
C++ project as that, obviously, doesn't have _MANAGED set, and unlike
with the boost build, I don't think it's feasible to define this
wholesale for a native project. (And anyways, I'm rather hesitant to
define this myself.)
Obviously, I could just edit regex/config.hpp, but that is a maintenance
nightmare of its own here.
Solution
--------
I *think* what really would be needed would be a define that the user
could specify, something like this:
#if defined(_DEBUG) || ... || defined(BOOST_REGEX_NO_FASTCALL)
# define BOOST_REGEX_CALL __cdecl
...
(I have attached a patch, hope this works.)
Would this make sense?
To add a short rationale: We use C++/CLI projects as bridges between
managed and native modules of our application. In the C++ part, we use
boost regexes, and sometimes it would make sense to reuse some native
code in a C++/CLI bridge module. If this native code uses Boost.Regex,
this doesn't work currently, as the native code file will also be
compiled with /clr, and then we have a calling convention mismatch and
can't use our boost-regex-dll.
cheers,
Martin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk