fix marshalling return values when calling java methods from native code

This commit is contained in:
Joel Dice 2008-01-17 12:55:05 -07:00
parent 7a7c36f8e0
commit 9a13df3024
2 changed files with 14 additions and 49 deletions

View File

@ -2780,34 +2780,7 @@ invoke(Thread* t, object method)
return 0; return 0;
} }
switch (returnCode(t, method)) {
case ByteField:
return makeByte(t, static_cast<int8_t>(intValue(t, result)));
case BooleanField:
return makeBoolean(t, static_cast<uint8_t>(intValue(t, result)));
case CharField:
return makeChar(t, static_cast<uint16_t>(intValue(t, result)));
case ShortField:
return makeShort(t, static_cast<int16_t>(intValue(t, result)));
case FloatField:
return makeFloat(t, static_cast<uint32_t>(intValue(t, result)));
case DoubleField:
return makeDouble(t, static_cast<uint64_t>(longValue(t, result)));
case ObjectField:
case IntField:
case LongField:
case VoidField:
return result; return result;
default:
abort(t);
}
} }
class MyProcessor: public Processor { class MyProcessor: public Processor {

View File

@ -330,7 +330,7 @@ CallBooleanMethodV(Thread* t, jobject o, jmethodID m, va_list a)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a); object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a);
return (t->exception ? 0 : booleanValue(t, r)); return (t->exception ? false : (intValue(t, r) != 0));
} }
jboolean JNICALL jboolean JNICALL
@ -352,7 +352,7 @@ CallByteMethodV(Thread* t, jobject o, jmethodID m, va_list a)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a); object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a);
return (t->exception ? 0 : byteValue(t, r)); return (t->exception ? 0 : intValue(t, r));
} }
jbyte JNICALL jbyte JNICALL
@ -374,7 +374,7 @@ CallCharMethodV(Thread* t, jobject o, jmethodID m, va_list a)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a); object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a);
return (t->exception ? 0 : charValue(t, r)); return (t->exception ? 0 : intValue(t, r));
} }
jchar JNICALL jchar JNICALL
@ -396,7 +396,7 @@ CallShortMethodV(Thread* t, jobject o, jmethodID m, va_list a)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a); object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a);
return (t->exception ? 0 : shortValue(t, r)); return (t->exception ? 0 : intValue(t, r));
} }
jshort JNICALL jshort JNICALL
@ -440,7 +440,7 @@ CallLongMethodV(Thread* t, jobject o, jmethodID m, va_list a)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a); object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a);
return (t->exception ? 0 : longValue(t, r)); return (t->exception ? 0 : intValue(t, r));
} }
jlong JNICALL jlong JNICALL
@ -462,9 +462,7 @@ CallFloatMethodV(Thread* t, jobject o, jmethodID m, va_list a)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a); object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a);
jint i = (t->exception ? 0 : floatValue(t, r)); return (t->exception ? 0 : bitsToFloat(intValue(t, r)));
jfloat f; memcpy(&f, &i, 4);
return f;
} }
jfloat JNICALL jfloat JNICALL
@ -486,9 +484,7 @@ CallDoubleMethodV(Thread* t, jobject o, jmethodID m, va_list a)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a); object r = t->m->processor->invokeList(t, getMethod(t, *o, m), *o, true, a);
jlong i = (t->exception ? 0 : doubleValue(t, r)); return (t->exception ? 0 : bitsToDouble(longValue(t, r)));
jdouble f; memcpy(&f, &i, 4);
return f;
} }
jdouble JNICALL jdouble JNICALL
@ -558,7 +554,7 @@ CallStaticBooleanMethodV(Thread* t, jclass c, jmethodID m, va_list a)
object r = t->m->processor->invokeList object r = t->m->processor->invokeList
(t, getStaticMethod(t, *c, m), 0, true, a); (t, getStaticMethod(t, *c, m), 0, true, a);
return (t->exception ? 0 : booleanValue(t, r)); return (t->exception ? 0 : (intValue(t, r) != 0));
} }
jboolean JNICALL jboolean JNICALL
@ -581,7 +577,7 @@ CallStaticByteMethodV(Thread* t, jclass c, jmethodID m, va_list a)
object r = t->m->processor->invokeList object r = t->m->processor->invokeList
(t, getStaticMethod(t, *c, m), 0, true, a); (t, getStaticMethod(t, *c, m), 0, true, a);
return (t->exception ? 0 : byteValue(t, r)); return (t->exception ? 0 : intValue(t, r));
} }
jbyte JNICALL jbyte JNICALL
@ -604,7 +600,7 @@ CallStaticCharMethodV(Thread* t, jclass c, jmethodID m, va_list a)
object r = t->m->processor->invokeList object r = t->m->processor->invokeList
(t, getStaticMethod(t, *c, m), 0, true, a); (t, getStaticMethod(t, *c, m), 0, true, a);
return (t->exception ? 0 : charValue(t, r)); return (t->exception ? 0 : intValue(t, r));
} }
jchar JNICALL jchar JNICALL
@ -627,7 +623,7 @@ CallStaticShortMethodV(Thread* t, jclass c, jmethodID m, va_list a)
object r = t->m->processor->invokeList object r = t->m->processor->invokeList
(t, getStaticMethod(t, *c, m), 0, true, a); (t, getStaticMethod(t, *c, m), 0, true, a);
return (t->exception ? 0 : shortValue(t, r)); return (t->exception ? 0 : intValue(t, r));
} }
jshort JNICALL jshort JNICALL
@ -696,9 +692,7 @@ CallStaticFloatMethodV(Thread* t, jclass c, jmethodID m, va_list a)
object r = t->m->processor->invokeList object r = t->m->processor->invokeList
(t, getStaticMethod(t, *c, m), 0, true, a); (t, getStaticMethod(t, *c, m), 0, true, a);
jint i = (t->exception ? 0 : floatValue(t, r)); return (t->exception ? 0 : bitsToFloat(intValue(t, r)));
jfloat f; memcpy(&f, &i, 4);
return f;
} }
jfloat JNICALL jfloat JNICALL
@ -721,9 +715,7 @@ CallStaticDoubleMethodV(Thread* t, jclass c, jmethodID m, va_list a)
object r = t->m->processor->invokeList object r = t->m->processor->invokeList
(t, getStaticMethod(t, *c, m), 0, true, a); (t, getStaticMethod(t, *c, m), 0, true, a);
jlong i = (t->exception ? 0 : doubleValue(t, r)); return (t->exception ? 0 : bitsToDouble(longValue(t, r)));
jdouble f; memcpy(&f, &i, 4);
return f;
} }
jdouble JNICALL jdouble JNICALL