aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/embind/embind.js39
-rwxr-xr-xsystem/include/emscripten/bind.h27
-rwxr-xr-xsystem/lib/embind/bind.cpp7
3 files changed, 19 insertions, 54 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index e02b9e01..b9a16fbb 100755
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -407,12 +407,11 @@ function __embind_register_struct_field(
};
}
-function RegisteredPointer(Handle, isPolymorphic, isSmartPointer, rawGetPointee, rawConstructor, rawDestructor) {
+function RegisteredPointer(Handle, isPolymorphic, isSmartPointer, rawGetPointee, rawDestructor) {
this.Handle = Handle;
this.isPolymorphic = isPolymorphic;
this.isSmartPointer = isSmartPointer;
this.rawGetPointee = rawGetPointee;
- this.rawConstructor = rawConstructor;
this.rawDestructor = rawDestructor;
}
@@ -429,29 +428,19 @@ RegisteredPointer.prototype.toWireType = function(destructors, o) {
}
};
-RegisteredPointer.prototype.toWireTypeAutoUpcast = function(destructors, handle) {
- var fromRawType;
- if (!handle) {
- return null;
- }
- if (handle.pointeeType.isPolymorphic) {
- fromRawType = handle.pointeeType.getDynamicRawPointerType(handle.ptr);
- } else {
- fromRawType = handle.pointeeType.rawType;
- }
- if (fromRawType == this.pointeeType.rawType) {
- return this.isSmartPointer ? handle.smartPointer : handle.ptr;
- }
- var ptr = ___staticPointerCast(handle.ptr, fromRawType, this.pointeeType.rawType);
+// todo: distinguish ptr and rawPtr
+RegisteredPointer.prototype.toWireTypeAutoUpcast = function(destructors, o) {
if (this.isSmartPointer) {
- var smartPtr = _malloc(16);
- // todo: this does not create a pointer that shares the reference count !?!?
- handle.pointeeType.smartPointerType.rawConstructor(smartPtr, ptr);
- ptr = smartPtr;
- destructors.push(handle.pointeeType.smartPointerType.rawDestructor);
- destructors.push(ptr);
+ return this.toWireType(destructors, o); // for now
+ } else {
+ if (o.pointeeType.isPolymorphic) {
+ var dynamicType = o.pointeeType.getDynamicRawPointerType(o.ptr);
+ return ___staticPointerCast(o.ptr, dynamicType, this.pointeeType.rawType);
+ } else {
+ return ___staticPointerCast(o.ptr, o.pointeeType.rawType, this.pointeeType.rawType);
+ }
+ // todo: this cast can fail
}
- return ptr;
};
RegisteredPointer.prototype.getPointee = function(ptr) {
@@ -534,13 +523,11 @@ function __embind_register_smart_ptr(
rawPointeeType,
isPolymorphic,
name,
- rawConstructor,
rawDestructor,
rawGetPointee
) {
name = Pointer_stringify(name);
var pointeeType = requireRegisteredType(rawPointeeType, 'class');
- rawConstructor = FUNCTION_TABLE[rawConstructor];
rawDestructor = FUNCTION_TABLE[rawDestructor];
rawGetPointee = FUNCTION_TABLE[rawGetPointee];
@@ -581,7 +568,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, isPolymorphic, true, rawGetPointee, 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..592928f5 100755
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -98,7 +98,6 @@ namespace emscripten {
TYPEID pointeeType,
bool isPolymorphic,
const char* pointerName,
- GenericFunction constructor,
GenericFunction destructor,
GenericFunction getPointee);
@@ -283,18 +282,9 @@ namespace emscripten {
return *static_cast<ToType*>(&from);
};
- template<typename FromRawType, typename ToRawType, bool isPolymorphic>
- struct performShared {
- static std::shared_ptr<ToRawType> cast(std::shared_ptr<FromRawType> from) {
- return std::dynamic_pointer_cast<ToRawType>(from);
- };
- };
-
template<typename FromRawType, typename ToRawType>
- struct performShared<FromRawType, ToRawType, false> {
- static std::shared_ptr<ToRawType> cast(std::shared_ptr<FromRawType> from) {
- return std::shared_ptr<ToRawType>(from, static_cast<ToRawType*>(from.get()));
- };
+ std::shared_ptr<ToRawType> performSharedStaticCast(std::shared_ptr<FromRawType> from) {
+ return std::shared_ptr<ToRawType>(from, static_cast<ToRawType*>(from.get()));
};
template<typename ReturnType, typename... Args, typename... Policies>
@@ -322,14 +312,6 @@ namespace emscripten {
);
}
- 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>);
- }
-
template<typename ClassType>
void raw_destructor(ClassType* ptr) {
delete ptr;
@@ -622,7 +604,6 @@ namespace emscripten {
TypeID<PointeeType>::get(),
std::is_polymorphic<PointeeType>::value,
name,
- reinterpret_cast<GenericFunction>(&raw_smart_pointer_constructor<PointeeType*>),
reinterpret_cast<GenericFunction>(&raw_destructor<PointerType>),
reinterpret_cast<GenericFunction>(&get_pointee<PointerType>));
@@ -639,8 +620,8 @@ namespace emscripten {
TypeID<ReturnPointeeType>::get(),
std::is_polymorphic<PointeeType>::value,
methodName,
- reinterpret_cast<GenericFunction>(&performShared<PointeeType, ReturnPointeeType, std::is_polymorphic<PointeeType>::value>::cast));
- return *this;
+ reinterpret_cast<GenericFunction>(&performSharedStaticCast<PointeeType,ReturnPointeeType>));
+ return *this;
}
};
diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp
index a4b67fa5..46924505 100755
--- a/system/lib/embind/bind.cpp
+++ b/system/lib/embind/bind.cpp
@@ -190,6 +190,8 @@ namespace emscripten {
// __dynamicPointerCast performs a C++ dynamic_cast<>() operation, but allowing run-time specification of
// the from and to pointer types.
int EMSCRIPTEN_KEEPALIVE __dynamicPointerCast(int p, int to) {
+ // The final parameter is a place-holder for a hint, a feature which is not currently implemented
+ // in the emscripten runtime. The compiler passes a dummy value of -1, and so do we.
int ret = (int)__staticPointerCast((void *)p, __getDynamicPointerType(p), to);
if (ret < 0) {
return 0;
@@ -212,16 +214,11 @@ namespace emscripten {
return name;
}
- int EMSCRIPTEN_KEEPALIVE __peek32(int p) {
- return *(int *)p;
- }
-
EMSCRIPTEN_BINDINGS(([]() {
// We bind __getDerivationPath in order to take advantage of the std::vector to Javascript array
// conversion for the return value. This has the unfortunate side-effect of exposing it to third party
// developers, but perhaps the double underscore will scare them away from calling it.
function("__getDerivationPath", &__getDerivationPath);
- function("__peek32", &__peek32);
}));
}