From cc1b2b9684701b9ffd039c50284f0e2009d55b21 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Wed, 16 Nov 2016 18:41:36 +0300 Subject: [PATCH] Add CheckCast(). --- runtime/src/main/cpp/Memory.cpp | 8 ++++++++ runtime/src/main/cpp/Memory.h | 1 + 2 files changed, 9 insertions(+) diff --git a/runtime/src/main/cpp/Memory.cpp b/runtime/src/main/cpp/Memory.cpp index 3f1475a5aaf..7f7517dbe79 100644 --- a/runtime/src/main/cpp/Memory.cpp +++ b/runtime/src/main/cpp/Memory.cpp @@ -1,6 +1,7 @@ #include #include "Assert.h" +#include "Exceptions.h" #include "Memory.h" void FreeObject(ContainerHeader* header) { @@ -105,6 +106,13 @@ int IsInstance(const ObjHeader* obj, const TypeInfo* type_info) { return obj_type_info != nullptr; } +void CheckInstance(const ObjHeader* obj, const TypeInfo* type_info) { + if (IsInstance(obj, type_info)) { + return; + } + ThrowClassCastException(); +} + #ifdef __cplusplus } #endif diff --git a/runtime/src/main/cpp/Memory.h b/runtime/src/main/cpp/Memory.h index fce850e9499..3542f29a057 100644 --- a/runtime/src/main/cpp/Memory.h +++ b/runtime/src/main/cpp/Memory.h @@ -267,6 +267,7 @@ void* AllocInstance(const TypeInfo* type_info, PlacementHint hint); void* AllocArrayInstance( const TypeInfo* type_info, PlacementHint hint, uint32_t elements); int IsInstance(const ObjHeader* obj, const TypeInfo* type_info); +void CheckCast(const ObjHeader* obj, const TypeInfo* type_info); #ifdef __cplusplus }