From a020a3f6bba3002cbaa6e0df9dd2443eed78edd9 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sun, 23 Dec 2007 11:09:41 -0700 Subject: [PATCH] handle various return types properly in invokeNative2 --- makefile | 2 +- src/compile.cpp | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/makefile b/makefile index 9754eb923e..f911fe1c58 100644 --- a/makefile +++ b/makefile @@ -28,7 +28,7 @@ src = src classpath = classpath test = test -input = $(test-build)/GC.class +input = $(test-build)/Reflection.class build-cxx = g++ build-cc = gcc diff --git a/src/compile.cpp b/src/compile.cpp index 50c61cb8d7..58dd513ad1 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3279,7 +3279,8 @@ invokeNative2(MyThread* t, object method) } void* function = pointerValue(t, methodCode(t, method)); - unsigned returnType = fieldType(t, methodReturnCode(t, method)); + unsigned returnCode = methodReturnCode(t, method); + unsigned returnType = fieldType(t, returnCode); uint64_t result; if (Verbose) { @@ -3305,20 +3306,37 @@ invokeNative2(MyThread* t, object method) &byteArrayBody(t, methodName(t, method), 0)); } - if (LIKELY(t->exception == 0) and returnType == POINTER_TYPE) { - return result ? *reinterpret_cast(result) : 0; - } else if (BytesPerWord == 8) { - switch (returnType) { - case INT8_TYPE: - case INT16_TYPE: - case INT32_TYPE: - // force sign extension + if (LIKELY(t->exception == 0)) { + switch (returnCode) { + case ByteField: + case BooleanField: + return static_cast(result); + + case CharField: + return static_cast(result); + + case ShortField: + return static_cast(result); + + case FloatField: + case IntField: return static_cast(result); - default: return result; + case LongField: + case DoubleField: + return result; + + case ObjectField: + return static_cast(result) ? *reinterpret_cast + (static_cast(result)) : 0; + + case VoidField: + return 0; + + default: abort(t); } } else { - return result; + return 0; } }