diff options
-rwxr-xr-x | src/embind/embind.js | 8 | ||||
-rwxr-xr-x | system/include/emscripten/bind.h | 23 |
2 files changed, 21 insertions, 10 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index 8da583ba..3ecea3e0 100755 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -601,7 +601,13 @@ RegisteredPointer.prototype.toWireType = function(destructors, handle) { } var ptr = staticPointerCast(handle.$$.ptr, fromRawType, this.pointeeType.rawType); if (this.isSmartPointer) { - ptr = handle.$$.pointeeType.smartPointerType.rawConstructor(ptr, handle.$$.smartPtr); + // If this is for smart ptr type conversion, I think it + // assumes that smart_ptr<T> has an identical binary layout to + // smart_ptr<U>. I wonder if that's untrue for any common + // smart pointer. - chad + ptr = handle.$$.pointeeType.smartPointerType.rawConstructor( + ptr, + handle.$$.smartPtr); destructors.push(handle.$$.pointeeType.smartPointerType.rawDestructor); destructors.push(ptr); } diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 9120a095..ad11395b 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -274,14 +274,6 @@ namespace emscripten { ); } - template<typename PointerType> - typename std::shared_ptr<PointerType>* raw_smart_pointer_constructor( - PointerType *ptr, - std::shared_ptr<PointerType>* basePtr - ) { - return new std::shared_ptr<PointerType>(*basePtr, ptr); - } - template<typename ClassType> void raw_destructor(ClassType* ptr) { delete ptr; @@ -539,12 +531,25 @@ namespace emscripten { template<typename PointerType> struct smart_ptr_trait { typedef typename PointerType::element_type element_type; + static element_type* get(const PointerType& ptr) { return ptr.get(); } + + static PointerType share(const PointerType& r, element_type* ptr) { + return PointerType(r, ptr); + } }; namespace internal { + template<typename SmartPointerType> + SmartPointerType* raw_smart_pointer_constructor( + typename smart_ptr_trait<SmartPointerType>::element_type* ptr, + SmartPointerType* basePtr + ) { + return new SmartPointerType(smart_ptr_trait<SmartPointerType>::share(*basePtr, ptr)); + } + template<typename PointerType> typename smart_ptr_trait<PointerType>::element_type* get_pointee(const PointerType& ptr) { return smart_ptr_trait<PointerType>::get(ptr); @@ -561,7 +566,7 @@ namespace emscripten { TypeID<PointerType>::get(), TypeID<PointeeType>::get(), name, - reinterpret_cast<GenericFunction>(&raw_smart_pointer_constructor<PointeeType*>), + reinterpret_cast<GenericFunction>(&raw_smart_pointer_constructor<PointerType>), reinterpret_cast<GenericFunction>(&raw_destructor<PointerType>), reinterpret_cast<GenericFunction>(&get_pointee<PointerType>)); }; |