💡 Looking for inspiration for your next open source project? Or perhaps you've got a brilliant idea you can't wait to share with others? Open Source Ideas is a community built specifically for this! 👋
6.59k
stars
220
forks
source link
C++ compile-time mangling and demangling library #286
When a C++ entity is exported from / imported to a file of executable format, it is mangled. The mangling is the way to distinguish entities with the same name and different signatures. But when it is needed to import the stuff from DLL in runtime, people usually une extern"C", which disables mangling. It is not good because it allows to import a function of an incompatible signature with UB as a result. They usually to it because mangling schemes are not standardized and each compilers authors tend to try to invent an own one. So, to properly import a func, one needs to probe all varieants of mangled names for all the compilers. Keeping names in mangled form is unmaintainable.
Of course the issue arises only because we don't have the right tools. This tool is a header-only library, computing a mangled name from a function signature. Something with interface like
typedef int FuncT(const char a, struct b c);
auto mangledVariantGcc = mangle::mangle<FuncT, mangled::compiler::GCC>::result;
Project description
When a C++ entity is exported from / imported to a file of executable format, it is mangled. The mangling is the way to distinguish entities with the same name and different signatures. But when it is needed to import the stuff from DLL in runtime, people usually une
extern"C"
, which disables mangling. It is not good because it allows to import a function of an incompatible signature with UB as a result. They usually to it because mangling schemes are not standardized and each compilers authors tend to try to invent an own one. So, to properly import a func, one needs to probe all varieants of mangled names for all the compilers. Keeping names in mangled form is unmaintainable.Of course the issue arises only because we don't have the right tools. This tool is a header-only library, computing a mangled name from a function signature. Something with interface like
.
Demangling in compile time is also possible. There are libs for constructing and evaluating parsers using templates, such as https://www.boost.org/doc/libs/develop/doc/html/metaparse.html .
Relevant Technology
Complexity and required time
Complexity
Required time (ETA)
Categories