@@ -573,13 +573,6 @@ struct SignatureCode : __em_asm_sig<int> {};
573
573
template <typename T>
574
574
struct SignatureCode <T, decltype (__em_asm_sig<T>::value)> : __em_asm_sig<T> {};
575
575
576
- // TODO: should we add this override to em_asm?
577
- // Most places, including Embind, use `p` for `size_t` (aka `unsigned long`) but
578
- // `em_asm` uses platform-specific code instead which represents `unsigned long`
579
- // as a JavaScript `number` on wasm32 and as a `BigInt` on wasm64.
580
- template <>
581
- struct SignatureCode <size_t > : __em_asm_sig<void *> {};
582
-
583
576
template <typename T>
584
577
struct SignatureCode <T&> : SignatureCode<T*> {};
585
578
@@ -1986,7 +1979,7 @@ struct VectorAccess {
1986
1979
#if __cplusplus >= 201703L
1987
1980
static std::optional<typename VectorType::value_type> get (
1988
1981
const VectorType& v,
1989
- typename VectorType::size_type index
1982
+ unsigned int index
1990
1983
) {
1991
1984
if (index < v.size ()) {
1992
1985
return v[index];
@@ -1997,7 +1990,7 @@ struct VectorAccess {
1997
1990
#else
1998
1991
static val get (
1999
1992
const VectorType& v,
2000
- typename VectorType::size_type index
1993
+ unsigned int index
2001
1994
) {
2002
1995
if (index < v.size ()) {
2003
1996
return val (v[index], allow_raw_pointers ());
@@ -2009,12 +2002,31 @@ struct VectorAccess {
2009
2002
2010
2003
static bool set (
2011
2004
VectorType& v,
2012
- typename VectorType::size_type index,
2005
+ unsigned int index,
2013
2006
const typename VectorType::value_type& value
2014
2007
) {
2015
2008
v[index] = value;
2016
2009
return true ;
2017
2010
}
2011
+
2012
+ static unsigned int size (const VectorType& v) {
2013
+ return v.size ();
2014
+ }
2015
+
2016
+ static void resize (
2017
+ VectorType& v,
2018
+ unsigned int len,
2019
+ const typename VectorType::value_type& value
2020
+ ) {
2021
+ v.resize (len, value);
2022
+ }
2023
+
2024
+ static void push_back (
2025
+ VectorType& v,
2026
+ typename VectorType::value_type&& value
2027
+ ) {
2028
+ v.push_back (std::move (value));
2029
+ }
2018
2030
};
2019
2031
2020
2032
} // end namespace internal
@@ -2026,16 +2038,13 @@ class_<std::vector<T, Allocator>> register_vector(const char* name) {
2026
2038
register_optional<T>();
2027
2039
#endif
2028
2040
2029
- void (VecType::*push_back)(const T&) = &VecType::push_back;
2030
- void (VecType::*resize)(const size_t , const T&) = &VecType::resize;
2031
- size_t (VecType::*size)() const = &VecType::size;
2032
- return class_<std::vector<T>>(name)
2041
+ return class_<VecType>(name)
2033
2042
.template constructor <>()
2034
- .function (" push_back" , push_back, allow_raw_pointers ())
2035
- .function (" resize" , resize, allow_raw_pointers ())
2036
- .function (" size" , size)
2037
- .function (" get" , & internal::VectorAccess<VecType>::get, allow_raw_pointers ())
2038
- .function (" set" , & internal::VectorAccess<VecType>::set, allow_raw_pointers ())
2043
+ .function (" push_back" , internal::VectorAccess<VecType>:: push_back, allow_raw_pointers ())
2044
+ .function (" resize" , internal::VectorAccess<VecType>:: resize, allow_raw_pointers ())
2045
+ .function (" size" , internal::VectorAccess<VecType>:: size, allow_raw_pointers () )
2046
+ .function (" get" , internal::VectorAccess<VecType>::get, allow_raw_pointers ())
2047
+ .function (" set" , internal::VectorAccess<VecType>::set, allow_raw_pointers ())
2039
2048
;
2040
2049
}
2041
2050
@@ -2093,6 +2102,10 @@ struct MapAccess {
2093
2102
}
2094
2103
return keys;
2095
2104
}
2105
+
2106
+ static unsigned int size (const MapType& m) {
2107
+ return m.size ();
2108
+ }
2096
2109
};
2097
2110
2098
2111
} // end namespace internal
@@ -2105,10 +2118,9 @@ class_<std::map<K, V, Compare, Allocator>> register_map(const char* name) {
2105
2118
register_optional<V>();
2106
2119
#endif
2107
2120
2108
- size_t (MapType::*size)() const = &MapType::size;
2109
2121
return class_<MapType>(name)
2110
2122
.template constructor <>()
2111
- .function (" size" , size)
2123
+ .function (" size" , internal::MapAccess<MapType>:: size)
2112
2124
.function (" get" , internal::MapAccess<MapType>::get)
2113
2125
.function (" set" , internal::MapAccess<MapType>::set)
2114
2126
.function (" keys" , internal::MapAccess<MapType>::keys)
0 commit comments