aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <chad@chadaustin.me>2012-10-30 15:18:22 -0700
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:21:22 +0300
commitdf6ba03eed0f08abe51fb1a5afd3e9d2c94a878f (patch)
treecae783a07dc835dff00d43296559513b342e62f9
parent1c0c7be7aaf6f231bd29d8b9db68506be6a0a5b1 (diff)
Fix several ownership/lifetime bugs in argument wire types
-rw-r--r--src/embind/embind.js4
-rw-r--r--src/embind/emval.js5
-rw-r--r--system/include/emscripten/bind.h2
-rw-r--r--system/include/emscripten/val.h2
-rw-r--r--system/include/emscripten/wire.h34
5 files changed, 12 insertions, 35 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 1f5da572..3e916ed4 100644
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -368,8 +368,8 @@ function __embind_register_smart_ptr(
var Handle = createNamedFunction(name, function(ptr) {
this.count = {value: 1};
- this.smartPointer = ptr;
- this.ptr = getPointee(ptr);
+ this.smartPointer = ptr; // std::shared_ptr<T>*
+ this.ptr = getPointee(ptr); // T*
});
// TODO: test for SmartPtr.prototype.constructor property?
diff --git a/src/embind/emval.js b/src/embind/emval.js
index b2adb89a..6552b0a7 100644
--- a/src/embind/emval.js
+++ b/src/embind/emval.js
@@ -13,11 +13,6 @@ 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) {
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;