From 2308f2a5b19e92d9f974b4a7ee733d5c6f3da4bb Mon Sep 17 00:00:00 2001 From: Bill Welden Date: Sat, 22 Dec 2012 10:19:52 -0800 Subject: More work on auto downcasting. --- system/lib/embind/bind.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'system/lib/embind/bind.cpp') diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp index de03052a..bc1e09ee 100755 --- a/system/lib/embind/bind.cpp +++ b/system/lib/embind/bind.cpp @@ -138,19 +138,19 @@ namespace emscripten { return derivationPath; } - void* EMSCRIPTEN_KEEPALIVE __staticPointerCast(void* p, int dv, int bs) { + void* EMSCRIPTEN_KEEPALIVE __staticPointerCast(void* p, int from, int to) { std::vector> paths; int direction = 1; - const std::type_info* dv1 = (std::type_info*)dv; - const std::type_info* bs1 = (std::type_info*)bs; - const __cxxabiv1::__class_type_info* dv2 = dynamic_cast(dv1); - const __cxxabiv1::__class_type_info* bs2 = dynamic_cast(bs1); + const std::type_info* from1 = (std::type_info*)from; + const std::type_info* to1 = (std::type_info*)to; + const __cxxabiv1::__class_type_info* from2 = dynamic_cast(from1); + const __cxxabiv1::__class_type_info* to2 = dynamic_cast(to1); - if (dv2 && bs2) { - __cxxabiv1::__getDerivationPaths(dv2, bs2, std::vector(), paths); + if (from2 && to2) { + __cxxabiv1::__getDerivationPaths(from2, to2, std::vector(), paths); if (paths.size() == 0) { - __cxxabiv1::__getDerivationPaths(bs2, dv2, std::vector(), paths); + __cxxabiv1::__getDerivationPaths(to2, from2, std::vector(), paths); direction = -1; } } @@ -189,10 +189,14 @@ 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 from, int to) { + 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. - return (int)__dynamic_cast((void *)p, (const std::type_info*)from, (const std::type_info *)to, -1); + int ret = (int)__staticPointerCast((void *)p, __getDynamicPointerType(p), to); + if (ret < 0) { + return 0; + } + return ret; } const char* EMSCRIPTEN_KEEPALIVE __typeName(int p) { -- cgit v1.2.3-18-g5258