diff options
author | Chad Austin <chad@imvu.com> | 2013-02-28 13:00:14 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:24:33 +0300 |
commit | 612076a7cd5e24924f878873b01c321e0ccee444 (patch) | |
tree | 409ccfa615358068bb54b389b6fe410dd5b490cc /system | |
parent | 76705c9008a9f075f2c3447079a6650326488376 (diff) |
Kill a bunch of C-style casts
Diffstat (limited to 'system')
-rwxr-xr-x | system/include/emscripten/bind.h | 34 | ||||
-rwxr-xr-x | system/lib/embind/bind.cpp | 25 |
2 files changed, 24 insertions, 35 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 298df4a4..bf9706d4 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -116,6 +116,13 @@ namespace emscripten { GenericFunction invoker, GenericFunction constructor); + void _embind_register_class_smart_ptr_constructor( + TYPEID classType, + unsigned argCount, + TYPEID argTypes[], + GenericFunction invoker, + GenericFunction constructor); + void _embind_register_class_method( TYPEID classType, const char* methodName, @@ -241,11 +248,11 @@ namespace emscripten { //////////////////////////////////////////////////////////////////////////////// extern "C" { - int __getDynamicPointerType(int p); + void* __getDynamicPointerType(void* p); } template<typename ReturnType, typename... Args, typename... Policies> - void function(const char* name, ReturnType (fn)(Args...), Policies...) { + void function(const char* name, ReturnType (*fn)(Args...), Policies...) { using namespace internal; registerStandardTypes(); @@ -640,35 +647,18 @@ namespace emscripten { class_& constructor(SmartPtr (*factory)(Args...)) { using namespace internal; + // todo: generate unique name smart_ptr<SmartPtr>("SmartPtr"); typename WithPolicies<>::template ArgTypeList<void, Args...> args; - /* _embind_register_class_smart_ptr_constructor( TypeID<ClassType>::get(), args.count, args.types, - reinterpret_cast<GenericFunction>(&raw_smart_ptr_constructor - */ - return *this; - } - - /* - template<typename SmartPtr, typename... Args> - class_& constructor(SmartPtr (*factory)(Args...)) { - using namespace internal; - - smart_ptr<SmartPtr>("SmartPtr"); - - typename WithPolicies<>::template ArgTypeList<void, Args...> args; - _embind_register_class_smart_ptr_constructor( - TypeID<ClassType>::get(), - args.count, - args.types, - reinterpret_cast<GenericFunction>(&raw_smart_ptr_constructor + reinterpret_cast<GenericFunction>(&Invoker<SmartPtr, Args...>::invoke), + reinterpret_cast<GenericFunction>(factory)); return *this; } - */ template<typename WrapperType> class_& allow_subclass() { diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp index 705cc4db..081db2cd 100755 --- a/system/lib/embind/bind.cpp +++ b/system/lib/embind/bind.cpp @@ -147,7 +147,7 @@ namespace emscripten { // They are used by embind.js to implement automatic downcasting of return values which are pointers to
// polymorphic objects.
- void* EMSCRIPTEN_KEEPALIVE __staticPointerCast(void* p, int from, int to) {
+ void* EMSCRIPTEN_KEEPALIVE __staticPointerCast(void* p, const void* from, void* to) {
std::vector<std::vector<const __cxxabiv1::__class_type_info*>> paths;
int direction = 1;
@@ -185,30 +185,29 @@ namespace emscripten { // __getDynamicPointerType returns (for polymorphic types only!) the type of the instance actually
// pointed to.
- int EMSCRIPTEN_KEEPALIVE __getDynamicPointerType(int p) {
- void** vtable = *(void***)p;
- return (int)static_cast<const std::type_info*>(vtable[-1]);
+ const void* EMSCRIPTEN_KEEPALIVE __getDynamicPointerType(void* p) {
+ void** vtable = *reinterpret_cast<void***>(p);
+ return 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);
+ void* __dynamic_cast(void*, const std::type_info*, const std::type_info*, void*);
// __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);
+ void* EMSCRIPTEN_KEEPALIVE __dynamicPointerCast(void* p, void* to) {
+ void* ret = __staticPointerCast(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);
+ const char* EMSCRIPTEN_KEEPALIVE __typeName(const std::type_info* ti) {
+ size_t nameLen = std::min(strlen(ti->name()), 1024U);
char* name = (char *)malloc(nameLen+1);
int stat;
@@ -221,8 +220,8 @@ namespace emscripten { return name;
}
- int EMSCRIPTEN_KEEPALIVE __peek32(int p) {
- return *(int *)p;
+ size_t EMSCRIPTEN_KEEPALIVE __peek32(size_t p) {
+ return *reinterpret_cast<size_t*>(p);
}
EMSCRIPTEN_BINDINGS(([]() {
@@ -231,7 +230,7 @@ namespace emscripten { // developers, but perhaps the double underscore will scare them away from calling it.
function("__getDerivationPath", &__getDerivationPath);
function("__getBaseClasses", &__getBaseClasses);
- function("__peek32", &__peek32);
+ function("__peek32", &__peek32, allow_raw_pointers());
}));
}
|