aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Lee <tlee@imvu.com>2012-10-23 12:23:03 -0700
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:21:18 +0300
commitd0bf1b0aea625931255c31641ba53ad6d4cee7c3 (patch)
tree4dd26767b9c7ef2c03c299dab189f450c5bdce41
parent681ea9fc51ee9908008f0913356f673018c11c2e (diff)
Handle shared_ptr correctly.(keep underlying pointer point to the same address)
There was some global variable dependency. These bleed thru tests and affected test result. Adding a way to reset this state.
-rw-r--r--src/embind/embind.js2
-rw-r--r--src/embind/emval.js5
-rw-r--r--system/include/emscripten/bind.h4
-rw-r--r--system/include/emscripten/wire.h26
4 files changed, 33 insertions, 4 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 56f3520a..f63a8eff 100644
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -409,7 +409,7 @@ function __embind_register_smart_ptr(
return new Handle(ptr);
},
toWireType: function(destructors, o) {
- return o.ptr;
+ return o.smartPointer;
}
};
}
diff --git a/src/embind/emval.js b/src/embind/emval.js
index 9574ab37..26ceaf46 100644
--- a/src/embind/emval.js
+++ b/src/embind/emval.js
@@ -13,12 +13,17 @@ Module.count_emval_handles = function() {
return _emval_handle_array.length;
};
+Module.reset_emval_handles = function() {
+ _emval_handle_array = [];
+ _emval_free_list = [];
+}
// Private C++ API
function __emval_register(value) {
var handle = _emval_free_list.length ?
_emval_free_list.pop() :
_emval_handle_array.length;
+
_emval_handle_array[handle] = {refcount: 1, value: value};
return handle;
}
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index 6902eb86..b8858284 100644
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -223,9 +223,9 @@ namespace emscripten {
}
template<typename PointerType>
- typename PointerType::element_type* get_pointee(PointerType* ptr) {
+ typename PointerType::element_type* get_pointee(PointerType ptr) {
// TODO: replace with general pointer traits implementation
- return ptr->get();
+ return ptr.get();
}
template<typename ClassType, typename ReturnType, typename... Args>
diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h
index be8e4f6d..ab4caa97 100644
--- a/system/include/emscripten/wire.h
+++ b/system/include/emscripten/wire.h
@@ -30,6 +30,13 @@ namespace emscripten {
return TypeID<T>::get();
}
};
+
+ template<typename T>
+ struct TypeID<std::shared_ptr<T>> {
+ static TYPEID get() {
+ return TypeID<T>::get();
+ }
+ };
// count<>
@@ -210,6 +217,24 @@ 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;
@@ -236,6 +261,5 @@ namespace emscripten {
auto toWireType(const T& v) -> typename BindingType<T>::WireType {
return BindingType<T>::toWireType(v);
}
-
}
}