diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 6e99b59fcddfa..be8067c92655b 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -22,7 +22,7 @@ #include #endif -#include +#include #include #include @@ -565,97 +565,35 @@ struct FunctorInvoker { namespace internal { -template -struct SignatureCode {}; - -template<> -struct SignatureCode { - static constexpr char get() { - return 'i'; - } -}; - -template<> -struct SignatureCode { - static constexpr char get() { - return 'v'; - } -}; +// TODO: this is a historical default, but we should probably use 'p' instead, +// and only enable it for smart_ptr_trait<> descendants. +template::value)> +struct SignatureCode : __em_asm_sig {}; -template<> -struct SignatureCode { - static constexpr char get() { - return 'f'; - } -}; +template +struct SignatureCode::value)> : __em_asm_sig {}; +// TODO: should we add this override to em_asm? +// Most places, including Embind, use `p` for `size_t` (aka `unsigned long`) but +// `em_asm` uses platform-specific code instead which represents `unsigned long` +// as a JavaScript `number` on wasm32 and as a `BigInt` on wasm64. template<> -struct SignatureCode { - static constexpr char get() { - return 'd'; - } -}; +struct SignatureCode : __em_asm_sig {}; -template<> -struct SignatureCode { - static constexpr char get() { - return 'p'; - } -}; -template<> -struct SignatureCode { - static constexpr char get() { - return 'p'; - } -}; - -template<> -struct SignatureCode { - static constexpr char get() { - return 'j'; - } -}; +template +struct SignatureCode : SignatureCode {}; -#ifdef __wasm64__ template<> -struct SignatureCode { - static constexpr char get() { - return 'j'; - } +struct SignatureCode { + static constexpr char value = 'v'; }; -#endif template -const char* getGenericSignature() { - static constexpr char signature[] = { SignatureCode::get()..., 0 }; - return signature; -} - -template struct SignatureTranslator { using type = int; }; -template<> struct SignatureTranslator { using type = void; }; -template<> struct SignatureTranslator { using type = float; }; -template<> struct SignatureTranslator { using type = double; }; -#ifdef __wasm64__ -template<> struct SignatureTranslator { using type = long; }; -#endif -template<> struct SignatureTranslator { using type = long long; }; -template<> struct SignatureTranslator { using type = long long; }; -template<> struct SignatureTranslator { using type = size_t; }; -template -struct SignatureTranslator { using type = void*; }; -template -struct SignatureTranslator { using type = void*; }; -template -struct SignatureTranslator { using type = void*; }; - -template -EMSCRIPTEN_ALWAYS_INLINE const char* getSpecificSignature() { - return getGenericSignature::type...>(); -} +constexpr const char Signature[] = { SignatureCode::value..., 0 }; template -EMSCRIPTEN_ALWAYS_INLINE const char* getSignature(Return (*)(Args...)) { - return getSpecificSignature(); +constexpr const char* getSignature(Return (*)(Args...)) { + return Signature; } } // end namespace internal @@ -2159,7 +2097,7 @@ struct MapAccess { } // end namespace internal -template, +template, class Allocator = std::allocator>> class_> register_map(const char* name) { typedef std::map MapType;