aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-03-01 16:21:30 -0800
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:24:45 +0300
commit50c5092c4a37565558e6ffab7602e778b6774e2a (patch)
treebf1b717e4d5f20cbdef454aaa9b8bef68fb8d21e
parent1a352601847328eb9f60b5c7068b8f18ab28ddc6 (diff)
Kill the malloc(16) by writing a test with a 1 MB smart pointer type :)
-rwxr-xr-xsrc/embind/embind.js6
-rwxr-xr-xsystem/include/emscripten/bind.h7
2 files changed, 6 insertions, 7 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index aab20b69..8da583ba 100755
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -601,11 +601,7 @@ 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!
- // todo: _malloc(16) is not big enough
- var smartPtr = _malloc(16);
- handle.$$.pointeeType.smartPointerType.rawConstructor(smartPtr, ptr, handle.$$.smartPtr);
- ptr = smartPtr;
+ 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 e8f21be4..9120a095 100755
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -275,8 +275,11 @@ namespace emscripten {
}
template<typename 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);
+ 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>