diff options
| author | Chad Austin <chad@chadaustin.me> | 2012-10-30 15:18:22 -0700 |
|---|---|---|
| committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:21:22 +0300 |
| commit | df6ba03eed0f08abe51fb1a5afd3e9d2c94a878f (patch) | |
| tree | cae783a07dc835dff00d43296559513b342e62f9 /system | |
| parent | 1c0c7be7aaf6f231bd29d8b9db68506be6a0a5b1 (diff) | |
Fix several ownership/lifetime bugs in argument wire types
Diffstat (limited to 'system')
| -rw-r--r-- | system/include/emscripten/bind.h | 2 | ||||
| -rw-r--r-- | system/include/emscripten/val.h | 2 | ||||
| -rw-r--r-- | system/include/emscripten/wire.h | 34 |
3 files changed, 10 insertions, 28 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 2de14fab..69d1f08c 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -223,7 +223,7 @@ namespace emscripten { } template<typename PointerType> - typename PointerType::element_type* get_pointee(PointerType ptr) { + typename PointerType::element_type* get_pointee(const PointerType& ptr) { // TODO: replace with general pointer traits implementation return ptr.get(); } diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index ada89638..8369caf7 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -194,7 +194,7 @@ namespace emscripten { return v.handle; } static val fromWireType(WireType v) { - return val(v); + return val::take_ownership(v); } }; } diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h index b618be83..ceabd280 100644 --- a/system/include/emscripten/wire.h +++ b/system/include/emscripten/wire.h @@ -130,7 +130,7 @@ namespace emscripten { template<> struct BindingType<std::string> { typedef char* WireType; - static WireType toWireType(std::string v) { + static WireType toWireType(const std::string& v) { return strdup(v.c_str()); } static std::string fromWireType(char* v) { @@ -138,14 +138,14 @@ namespace emscripten { } }; - template<> - struct BindingType<const std::string&> { - typedef char* WireType; - static WireType toWireType(std::string v) { - return strdup(v.c_str()); + template<typename T> + struct BindingType<const T&> { + typedef typename BindingType<T>::WireType WireType; + static WireType toWireType(const T& v) { + return BindingType<T>::toWireType(v); } - static std::string fromWireType(char* v) { - return std::string(v); + static T fromWireType(WireType wt) { + return BindingType<T>::fromWireType(wt); } }; @@ -210,24 +210,6 @@ namespace emscripten { }; template<typename T> - struct GenericBindingType<std::shared_ptr<T>> { - typedef typename std::shared_ptr<T> ActualT; - typedef ActualT* WireType; - - static WireType toWireType(std::shared_ptr<T> p) { - return new std::shared_ptr<T>(p); - } - - static std::shared_ptr<T> fromWireType(WireType p) { - return *p; - } - - static void destroy(WireType p) { - delete p; - } - }; - - template<typename T> struct WireDeleter { typedef typename BindingType<T>::WireType WireType; |
