diff options
Diffstat (limited to 'system')
-rwxr-xr-x | system/include/emscripten/bind.h | 62 | ||||
-rwxr-xr-x | system/lib/embind/bind.cpp | 20 |
2 files changed, 34 insertions, 48 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index ce9053f2..a3789cab 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -124,20 +124,14 @@ namespace emscripten { size_t memberFunctionSize, void* memberFunction); - void _embind_register_raw_cast_method( + void _embind_register_cast_method( TYPEID classType, bool isPolymorphic, const char* methodName, TYPEID returnType, - GenericFunction invoker); - - void _embind_register_smart_cast_method( - TYPEID pointerType, - TYPEID returnType, - TYPEID returnPointeeType, - bool isPolymorphic, - const char* methodName, - GenericFunction invoker); + TYPEID sharedReturnType, + GenericFunction rawInvoker, + GenericFunction sharedInvoker); void _embind_register_class_field( TYPEID classType, @@ -274,7 +268,6 @@ namespace emscripten { extern "C" { int __getDynamicPointerType(int p); - int __dynamicPointerCast(int p, int to); } template<typename FromType, typename ToType> @@ -283,14 +276,14 @@ namespace emscripten { }; template<typename FromRawType, typename ToRawType, bool isPolymorphic> - struct performShared { + struct performSharedCast { 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> { + struct performSharedCast<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())); }; @@ -300,7 +293,7 @@ namespace emscripten { void function(const char* name, ReturnType (fn)(Args...), Policies...) { using namespace internal; - registerStandardTypes(); + registerStandardTypes(); // todo: remove all typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args; _embind_register_function( @@ -625,21 +618,12 @@ namespace emscripten { reinterpret_cast<GenericFunction>(&get_pointee<PointerType>)); } + }; - template<typename ReturnType> - register_smart_ptr& cast(const char* methodName) { - using namespace internal; - typedef typename ReturnType::element_type ReturnPointeeType; - typedef typename PointerType::element_type PointeeType; - _embind_register_smart_cast_method( - TypeID<PointerType>::get(), - TypeID<ReturnType>::get(), - TypeID<ReturnPointeeType>::get(), - std::is_polymorphic<PointeeType>::value, - methodName, - reinterpret_cast<GenericFunction>(&performShared<PointeeType, ReturnPointeeType, std::is_polymorphic<PointeeType>::value>::cast)); - return *this; - } + template<typename PointeeType> + class shared_ptr: public register_smart_ptr<std::shared_ptr<PointeeType>> { + public: + shared_ptr(const char* name): register_smart_ptr<std::shared_ptr<PointeeType>>(name) {}; }; //////////////////////////////////////////////////////////////////////////////// @@ -777,13 +761,31 @@ namespace emscripten { template<typename ReturnType> class_& cast(const char* methodName) { using namespace internal; + //typedef typename std::shared_ptr<ClassType> PointerType; + typedef typename std::shared_ptr<ReturnType> SharedReturnType; - _embind_register_raw_cast_method( + _embind_register_cast_method( TypeID<ClassType>::get(), std::is_polymorphic<ClassType>::value, methodName, TypeID<ReturnType>::get(), - reinterpret_cast<GenericFunction>(&performRawStaticCast<ClassType,ReturnType>)); + TypeID<SharedReturnType>::get(), + reinterpret_cast<GenericFunction>(&performRawStaticCast<ClassType, ReturnType>), + reinterpret_cast<GenericFunction>(&performSharedCast<ClassType, ReturnType, std::is_polymorphic<ClassType>::value>::cast)); + return *this; + } + + class_& shared_ptr(const char* ptrName = "") { + using namespace internal; + typedef typename std::shared_ptr<ClassType> PointerType; + + _embind_register_smart_ptr( + TypeID<PointerType>::get(), + TypeID<ClassType>::get(), + ptrName, + reinterpret_cast<GenericFunction>(&raw_smart_pointer_constructor<ClassType*>), + reinterpret_cast<GenericFunction>(&raw_destructor<PointerType>), + reinterpret_cast<GenericFunction>(&get_pointee<PointerType>)); return *this; } }; diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp index 5e82bb7e..bc79876f 100755 --- a/system/lib/embind/bind.cpp +++ b/system/lib/embind/bind.cpp @@ -101,7 +101,7 @@ namespace emscripten { // __getDerivationPath returns an array of type_info pointers describing the derivation chain starting with
// the derived type and proceeding toward (and ending with) the base type. Types are only included if they
// appear on all possible derivation paths.
- std::vector<int> __getDerivationPath(int dv, const int bs) {
+ std::vector<int> __getDerivationPath(int dv, const int bs) { // todo: use emval array to pass return value??
std::vector<std::vector<const __cxxabiv1::__class_type_info*>> paths;
const std::type_info* dv1 = (std::type_info*)dv;
@@ -176,27 +176,11 @@ namespace emscripten { // __getDynamicPointerType returns (for polymorphic types only!) the type of the instance actually
// pointed to.
- int EMSCRIPTEN_KEEPALIVE __getDynamicPointerType(int p) {
+ int EMSCRIPTEN_KEEPALIVE __getDynamicPointerType(int p) { // use size_t
void** vtable = *(void***)p;
return (int)static_cast<const std::type_info*>(vtable[-1]);
}
- // Calls to __dynamic_cast are generated by the compiler to implement dynamic_cast<>() -- its prototype is
- // not available through any header file. It is called directly here because it allows run-time
- // specification of the target pointer type (which can only be specified at compile time when using
- // dynamic_cast<>().
- void* __dynamic_cast(void*, const std::type_info*, const std::type_info*, int);
-
- // __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) {
- int ret = (int)__staticPointerCast((void *)p, __getDynamicPointerType(p), to);
- if (ret < 0) {
- return 0;
- }
- return ret;
- }
-
const char* EMSCRIPTEN_KEEPALIVE __typeName(int p) {
const std::type_info* ti = (const std::type_info*)p;
size_t nameLen = std::min(strlen(ti->name()), (unsigned int)1024);
|