Loading...
Searching...
No Matches
hydrocouplecomponentabi.h
Go to the documentation of this file.
1
57
58#ifndef HYDROCOUPLE_HYDROCOUPLECOMPONENTABI_H
59#define HYDROCOUPLE_HYDROCOUPLECOMPONENTABI_H
60
61#include "hydrocouple.h"
62
63// ── Export/visibility ───────────────────────────────────────────────────────
64#if defined(_WIN32)
65# define HYDROCOUPLE_COMPONENT_EXPORT __declspec(dllexport)
66#else
67# define HYDROCOUPLE_COMPONENT_EXPORT __attribute__((visibility("default")))
68#endif
69
70// ── Stamp construction ──────────────────────────────────────────────────────
71#define HYDROCOUPLE_ABI_STRINGIFY_(x) #x
72#define HYDROCOUPLE_ABI_STRINGIFY(x) HYDROCOUPLE_ABI_STRINGIFY_(x)
73
80#define HYDROCOUPLE_COMPONENT_ABI_REVISION "2"
81
92#define HYDROCOUPLE_COMPONENT_IFACE_VERSION_NUMBER 5
93#define HYDROCOUPLE_COMPONENT_IFACE_VERSION \
94 HYDROCOUPLE_ABI_STRINGIFY(HYDROCOUPLE_COMPONENT_IFACE_VERSION_NUMBER)
95
96// One number, two spellings — so they are made to agree at compile time. This
97// line is what the Composer-era header lacked: it said "2" through ABI 3 and 4.
100 "hydrocouplecomponentabi.h: HYDROCOUPLE_COMPONENT_IFACE_VERSION_NUMBER "
101 "disagrees with HydroCouple::HYDROCOUPLE_ABI_VERSION. The interface "
102 "ABI was bumped without bumping the component stamp; every component "
103 "would stamp the wrong iface and hosts would accept mismatched pairs.");
104
105// Compiler. MSVC is tested first because clang-cl defines _MSC_VER and follows
106// the MSVC ABI. Visual Studio 2015 onward (_MSC_VER 19xx, toolsets v140-v14x)
107// is one binary-compatible family, so the stamp names the family, not the
108// exact version: an update to the compiler must not reject every library.
109#if defined(_MSC_VER)
110# if _MSC_VER >= 1900 && _MSC_VER < 2000
111# define HYDROCOUPLE_ABI_COMPILER "msvc-v14x"
112# else
113# define HYDROCOUPLE_ABI_COMPILER "msvc-" HYDROCOUPLE_ABI_STRINGIFY(_MSC_VER)
114# endif
115#elif defined(__clang__)
116# define HYDROCOUPLE_ABI_COMPILER "clang-" HYDROCOUPLE_ABI_STRINGIFY(__clang_major__)
117#elif defined(__GNUC__)
118# define HYDROCOUPLE_ABI_COMPILER "gcc-" HYDROCOUPLE_ABI_STRINGIFY(__GNUC__)
119#else
120# define HYDROCOUPLE_ABI_COMPILER "unknown"
121#endif
122
123// Standard library, with the build settings that change the layout of the
124// std::string and std::vector objects the interfaces pass by value:
125// libstdc++'s dual ABI (_GLIBCXX_USE_CXX11_ABI) and debug mode, libc++'s ABI
126// version, and the MSVC STL's iterator-debug level.
127#if defined(_LIBCPP_VERSION)
128# define HYDROCOUPLE_ABI_STDLIB "libc++" HYDROCOUPLE_ABI_STRINGIFY(_LIBCPP_ABI_VERSION)
129#elif defined(__GLIBCXX__)
130# if defined(_GLIBCXX_DEBUG)
131# define HYDROCOUPLE_ABI_STDLIB_DEBUG "-debug"
132# else
133# define HYDROCOUPLE_ABI_STDLIB_DEBUG ""
134# endif
135# if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI == 0
136# define HYDROCOUPLE_ABI_STDLIB "libstdc++-cow" HYDROCOUPLE_ABI_STDLIB_DEBUG
137# else
138# define HYDROCOUPLE_ABI_STDLIB "libstdc++-cxx11" HYDROCOUPLE_ABI_STDLIB_DEBUG
139# endif
140#elif defined(_MSVC_STL_VERSION)
141# define HYDROCOUPLE_ABI_STDLIB "msvcstl-idl" HYDROCOUPLE_ABI_STRINGIFY(_ITERATOR_DEBUG_LEVEL)
142#else
143# define HYDROCOUPLE_ABI_STDLIB "unknown"
144#endif
145
146// C runtime (Windows only). Debug and release CRTs lay out and allocate
147// differently, and a static CRT (/MT) gives each image its own heap, which the
148// STL-by-value rule cannot survive: a std::string allocated in a component and
149// freed in the host would cross heaps. /MT builds are therefore stamped so a
150// host can name the problem, but they cannot work.
151#if defined(_MSC_VER)
152# if defined(_DLL) && defined(_DEBUG)
153# define HYDROCOUPLE_ABI_CRT ";crt=mdd"
154# elif defined(_DLL)
155# define HYDROCOUPLE_ABI_CRT ";crt=md"
156# elif defined(_DEBUG)
157# define HYDROCOUPLE_ABI_CRT ";crt=mtd"
158# else
159# define HYDROCOUPLE_ABI_CRT ";crt=mt"
160# endif
161#else
162# define HYDROCOUPLE_ABI_CRT ""
163#endif
164
165// Pointer width in bytes. __SIZEOF_POINTER__ is GCC/Clang only.
166#if defined(__SIZEOF_POINTER__)
167# define HYDROCOUPLE_ABI_POINTER_BYTES HYDROCOUPLE_ABI_STRINGIFY(__SIZEOF_POINTER__)
168#elif defined(_WIN64)
169# define HYDROCOUPLE_ABI_POINTER_BYTES "8"
170#elif defined(_WIN32)
171# define HYDROCOUPLE_ABI_POINTER_BYTES "4"
172#else
173# error "hydrocouplecomponentabi.h: cannot determine the pointer width for the ABI stamp"
174#endif
175
185#define HYDROCOUPLE_COMPONENT_ABI_STAMP \
186 "hc-abi/" HYDROCOUPLE_COMPONENT_ABI_REVISION \
187 ";iface=" HYDROCOUPLE_COMPONENT_IFACE_VERSION \
188 ";cxx=" HYDROCOUPLE_ABI_COMPILER \
189 ";stdlib=" HYDROCOUPLE_ABI_STDLIB \
190 HYDROCOUPLE_ABI_CRT \
191 ";ptr=" HYDROCOUPLE_ABI_POINTER_BYTES
192
193// ── Entry-point names (kept as string literals for the loader's dlsym) ──────
194#define HYDROCOUPLE_COMPONENT_ABI_SYMBOL "hydrocouple_component_abi_v1"
195#define HYDROCOUPLE_COMPONENT_INFO_SYMBOL "hydrocouple_component_info_v1"
196
211#define HYDROCOUPLE_COMPONENT_LEGACY_INFO_SYMBOL "CreateComponentInfo"
212
214#define HYDROCOUPLE_COMPONENT_UNSTAMPED "unstamped(legacy CreateComponentInfo)"
215
216extern "C"
217{
219 typedef const char *(*HydroCoupleComponentAbiFn)(void);
220
222 typedef HydroCouple::IComponentInfo *(*HydroCoupleComponentInfoFn)(void);
223
225 typedef HydroCouple::IModelComponentInfo *(*HydroCoupleLegacyComponentInfoFn)(void);
226}
227
237#define HYDROCOUPLE_DECLARE_COMPONENT(InfoType) \
238 extern "C" HYDROCOUPLE_COMPONENT_EXPORT const char * \
239 hydrocouple_component_abi_v1(void) \
240 { \
241 return HYDROCOUPLE_COMPONENT_ABI_STAMP; \
242 } \
243 \
244 extern "C" HYDROCOUPLE_COMPONENT_EXPORT HydroCouple::IComponentInfo * \
245 hydrocouple_component_info_v1(void) \
246 { \
247 static InfoType s_info; \
248 return &s_info; \
249 }
250
251#endif // HYDROCOUPLE_HYDROCOUPLECOMPONENTABI_H
IComponentInfo interface class is a factory that provides detailed metadata about a component and cre...
Definition hydrocouple.h:505
IModelComponentInfo interface inherits from the IComponentInfo interface which provides detailed meta...
Definition hydrocouple.h:665
Core interface definitions for the HydroCouple component-based modeling framework.
#define HYDROCOUPLE_COMPONENT_IFACE_VERSION_NUMBER
Interface ABI this convention targets, as a number the preprocessor can stringify into the stamp.
Definition hydrocouplecomponentabi.h:92
constexpr int HYDROCOUPLE_ABI_VERSION
ABI version for the HydroCouple interface.
Definition hydrocouple.h:71