git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: better handling of void* casts in runtime
46dddf5Andy Arvanitis
pcc/runtime/purescript.hh+12−6
@@ -251,14 +251,9 @@ class any {
251 any(T&& val, typename std::enable_if<std::is_assignable<managed<void>,T>::value>::type* = 0) noexcept
251 any(T&& val, typename std::enable_if<std::is_assignable<managed<void>,T>::value>::type* = 0) noexcept
252 : tag(Tag::Pointer), p(std::move(val)) {}
252 : tag(Tag::Pointer), p(std::move(val)) {}
253
253
254− // Explicit void* to raw pointer value
255− template <typename T>
256− any(const T& val, typename std::enable_if<std::is_same<T,void*>::value>::type* = 0) noexcept
257− : tag(Tag::RawPointer), v(val) {}
254+ any(void * val) noexcept : tag(Tag::RawPointer), v(val) {}
258−
259 any(nullptr_t) noexcept : tag(Tag::RawPointer), v(nullptr) {}
255 any(nullptr_t) noexcept : tag(Tag::RawPointer), v(nullptr) {}
260
256
261−
262#if !defined(USE_GC)
257#if !defined(USE_GC)
263 private:
258 private:
264 auto destruct() const noexcept -> void {
259 auto destruct() const noexcept -> void {
@@ -337,6 +332,17 @@ class any {
337 operator const array&() const;
332 operator const array&() const;
338 operator const record&() const;
333 operator const record&() const;
339
334
335+ operator void *() const {
336+ return extractPointer(IF_DEBUG(Tag::RawPointer));
337+ }
338+
339+ template <typename T,
340+ typename = typename std::enable_if<std::is_pointer<T>::value &&
341+ std::is_class<typename std::remove_pointer<T>::type>::value>::type>
342+ operator T() const {
343+ return static_cast<T>(extractPointer(IF_DEBUG(Tag::RawPointer)));
344+ }
345+
340 auto operator[](const size_t) const -> const any&;
346 auto operator[](const size_t) const -> const any&;
341 auto at(const char *) const -> const any&;
347 auto at(const char *) const -> const any&;
342 auto size() const -> size_t;
348 auto size() const -> size_t;
src/Language/PureScript/CodeGen/Cpp/Common.hs+3−4
@@ -186,8 +186,6 @@ nameIsCppReserved name =
186 , "noexcept"
186 , "noexcept"
187 , "not"
187 , "not"
188 , "not_eq"
188 , "not_eq"
189− , "NULL"
190− , "null"
191 , "nullptr"
189 , "nullptr"
192 , "nullptr_t"
190 , "nullptr_t"
193 , "operator"
191 , "operator"
@@ -263,8 +261,9 @@ moduleNameToCpp (ModuleName pns) =
263--
261--
264properNameIsCppReserved :: Text -> Bool
262properNameIsCppReserved :: Text -> Bool
265properNameIsCppReserved name =
263properNameIsCppReserved name =
264+ name `elem` [ "DEFINE_SYMBOL"
265+ , "NULL"
266− name `elem` [ "Private"
266+ , "Private"
267 , "PureScript"
267 , "PureScript"
268 , "SYM"
268 , "SYM"
269− , "DEFINE_SYMBOL"
270 ]
269 ]