From fdb48ba8f4fff05a155d0d0c4bc5588a79ec1e58 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Sun, 22 Dec 2024 10:32:29 +0300 Subject: [PATCH] Add test from bugreport, provide compile time diagnostics for such cases (#85) Fixes https://github.com/apolukhin/Boost.DLL/issues/47 --- include/boost/dll/detail/demangling/msvc.hpp | 13 +++++++-- test/Jamfile.v2 | 1 + test/cpp_mangling1_cf.cpp | 30 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/cpp_mangling1_cf.cpp diff --git a/include/boost/dll/detail/demangling/msvc.hpp b/include/boost/dll/detail/demangling/msvc.hpp index e5b5aa04..13437659 100644 --- a/include/boost/dll/detail/demangling/msvc.hpp +++ b/include/boost/dll/detail/demangling/msvc.hpp @@ -76,7 +76,7 @@ void mangled_storage_impl::trim_typename(std::string & val) static constexpr char class_ [7] = "class "; static constexpr char struct_[8] = "struct "; - if (equal(begin(class_), end(class_)-1, val.begin())) //aklright, starts with 'class ' + if (equal(begin(class_), end(class_)-1, val.begin())) val.erase(0, 6); else if (val.size() >= 7) if (equal(begin(struct_), end(struct_)-1, val.begin())) @@ -98,7 +98,7 @@ namespace parser { parser::try_consume_prefix(s, prefix); return true; } - + inline void consume_ptrs(boost::core::string_view& s) { do { while (parser::try_consume_prefix(s, " ")) {} @@ -126,6 +126,15 @@ namespace parser { parser::ignore_prefix(s, "struct "); const auto& mangled_name = ms.get_name(); + + static_assert( + !std::is_function::type>::value, + "boost::dll::smart_library on Windows platform does not support " + "functions that accept functions. If you wish to see such support " + "- please provide a working PR on github with sufficient tests. " + "Otherwise simplify the function. For example, use `void*` " + "parameter instead of a function pointer. " + ); if (!parser::try_consume_prefix(s, mangled_name)) { return false; } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5779e7bf..648e6bcd 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -100,6 +100,7 @@ project [ run shared_library_concurrent_load_test.cpp /boost/thread//boost_thread : : library1 library2 my_plugin_aggregator refcounting_plugin : shared ] [ run cpp_mangle_test.cpp : : cpp_plugin ] [ run cpp_mangling.cpp ] + [ compile-fail cpp_mangling1_cf.cpp ] [ run cpp_load_test.cpp : : cpp_plugin ] [ run cpp_import_test.cpp : : cpp_plugin ] [ run template_method_linux_test.cpp : : cpp_plugin ] diff --git a/test/cpp_mangling1_cf.cpp b/test/cpp_mangling1_cf.cpp new file mode 100644 index 00000000..cd973b74 --- /dev/null +++ b/test/cpp_mangling1_cf.cpp @@ -0,0 +1,30 @@ +// Copyright 2024 Antony Polukhin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +// For more information, see http://www.boost.org + +#include + +struct CallbackInfo; + +#ifdef _MSC_VER +typedef void(__stdcall* Callback)(CallbackInfo* pInfo); +#else +typedef void(*Callback)(CallbackInfo* pInfo); +#endif + + +int main() { + namespace parser = boost::dll::detail::parser; + boost::dll::detail::mangled_storage_impl ms; + + // The following case of mangling is not supported at the moment. Make + // sure that we detect it on compile time. + parser::is_mem_fn_with_name("set_callback", ms) + ("public: void __cdecl int::set_callback(void (__cdecl*)(struct CallbackInfo * __ptr64)) __ptr64") + ; +} +