aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Welden <bwelden@imvu.com>2013-01-11 14:28:56 -0800
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:23:06 +0300
commitd0969fc651367d801d28146ef6f4dbe1d26f2aa2 (patch)
treeb94bf4726e2d819242b331068ebe6cf05f99a86a
parentc59bb0d3975d7e15faaab87f785ae66bf6730f35 (diff)
o Temporary shared pointers created to hold upcast argument values now share ownership with the original pointer.
o New test cases for edge cases. o Other minor clean-up.
-rwxr-xr-xsrc/embind/embind.js10
-rwxr-xr-xsystem/include/emscripten/bind.h10
2 files changed, 7 insertions, 13 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index c37ef55b..39e120e0 100755
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -443,9 +443,9 @@ RegisteredPointer.prototype.toWireType = function(destructors, handle) {
}
var ptr = staticPointerCast(handle.ptr, fromRawType, this.pointeeType.rawType);
if (this.isSmartPointer) {
+ // todo: if ptr == handle.ptr, there's no need to allocate a new smartPtr!
var smartPtr = _malloc(16);
- // todo: this does not create a pointer that shares the reference count !
- handle.pointeeType.smartPointerType.rawConstructor(smartPtr, ptr);
+ handle.pointeeType.smartPointerType.rawConstructor(smartPtr, ptr, handle.smartPointer);
ptr = smartPtr;
destructors.push(handle.pointeeType.smartPointerType.rawDestructor);
destructors.push(ptr);
@@ -511,8 +511,6 @@ RegisteredPointer.prototype.fromWireTypeAutoDowncast = function(ptr) { // ptr is
}
var toType = this.getDynamicDowncastType(ptr);
if (toType) {
- // todo: need to clone the ptr here (really??)
- // todo: we need to release the pre-cast pointer, don't we? how did this get past the tests?
var fromType = this.pointeeType;
if (this.isSmartPointer) {
handle = toType.smartPointerType.fromWireType(ptr);
@@ -526,11 +524,9 @@ RegisteredPointer.prototype.fromWireTypeAutoDowncast = function(ptr) { // ptr is
return handle;
};
-// todo: don't need isPolymorphic parameter any more
function __embind_register_smart_ptr(
rawType,
rawPointeeType,
- isPolymorphic,
name,
rawConstructor,
rawDestructor,
@@ -579,7 +575,7 @@ function __embind_register_smart_ptr(
this.smartPointer = undefined;
this.ptr = undefined;
};
- var registeredPointer = new RegisteredPointer(Handle, isPolymorphic, true, rawGetPointee, rawConstructor, rawDestructor);
+ var registeredPointer = new RegisteredPointer(Handle, pointeeType.isPolymorphic, true, rawGetPointee, rawConstructor, rawDestructor);
registeredPointer.pointeeType = pointeeType;
pointeeType.smartPointerType = registerType(rawType, name, registeredPointer);
}
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index bbce9a93..652fb1b4 100755
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -96,7 +96,6 @@ namespace emscripten {
void _embind_register_smart_ptr(
TYPEID pointerType,
TYPEID pointeeType,
- bool isPolymorphic,
const char* pointerName,
GenericFunction constructor,
GenericFunction destructor,
@@ -322,12 +321,12 @@ namespace emscripten {
);
}
- template<typename PointerType>
- void nullDeallocator(PointerType* p) {}
+// template<typename PointerType>
+// void nullDeallocator(PointerType* p) {}
template<typename PointerType>
- typename std::shared_ptr<PointerType> raw_smart_pointer_constructor(PointerType *ptr, void (PointerType*)) {
- return std::shared_ptr<PointerType>(ptr, nullDeallocator<PointerType>);
+ typename std::shared_ptr<PointerType> raw_smart_pointer_constructor(PointerType *ptr, std::shared_ptr<PointerType> basePtr, void (PointerType*)) {
+ return std::shared_ptr<PointerType>(basePtr, ptr);
}
template<typename ClassType>
@@ -620,7 +619,6 @@ namespace emscripten {
_embind_register_smart_ptr(
TypeID<PointerType>::get(),
TypeID<PointeeType>::get(),
- std::is_polymorphic<PointeeType>::value,
name,
reinterpret_cast<GenericFunction>(&raw_smart_pointer_constructor<PointeeType*>),
reinterpret_cast<GenericFunction>(&raw_destructor<PointerType>),