2
0
mirror of synced 2025-02-23 06:48:15 +00:00
mobile/bind/testdata/classes.java.c.golden
Elias Naur 89b8360218 bind: remove error wrappers to preserve error instance identity
CL 24800 changed the error representation from strings to objects.
However, since native errors types are not immediately compatible
across languages, wrapper types were introduced to bridge the gap.

This CL remove those wrappers and instead special case the error
proxy types to conform to their language error protocol.

Specifically:

 - The ObjC proxy for Go errors now extends NSError and calls
   initWithDomain to store the error message.
 - The Go proxy for ObjC NSError return the localizedDescription
    property for calls to Error.
 - The Java proxy for Go errors ow extends Exception and
   overrides getMessage() to return the error message.
 - The Go proxy for Java Exceptions returns getMessage whenever
   Error is called.

The end result is that error values behave more like normal objects
across the language boundary. In particular, instance identity is
now preserved: an error passed across the boundary and back will
result in the same instance.

There are two semantic changes that followed this change:

 - The domain for wrapped Go errors is now always "go".
   The domain wasn't useful before this CL: the domains were set to
   the package name of function or method where the error happened
   to cross the language boundary.
 - If a Go method that returns an error is implemented in ObjC, the
   implementation must now both return NO _and_ set the error result
   for the calling Go code to receive a non-nil error.
   Before this CL, because errors were always wrapped, a nil ObjC
   could be represented with a non-nil wrapper.

Change-Id: Idb415b6b13ecf79ccceb60f675059942bfc48fec
Reviewed-on: https://go-review.googlesource.com/29298
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-04 09:11:42 +00:00

262 lines
9.6 KiB
Plaintext

// File is generated by gobind. Do not edit.
#include <jni.h>
#include "seq.h"
#include "classes.h"
static jclass class_java_lang_Runnable;
static jmethodID m_java_lang_Runnable_run;
static jclass class_java_io_InputStream;
static jmethodID m_java_io_InputStream_read__;
static jclass class_java_util_concurrent_Future;
static jmethodID m_java_util_concurrent_Future_get__;
static jmethodID m_java_util_concurrent_Future_get__JLjava_util_concurrent_TimeUnit_2;
static jclass class_java_lang_Object;
static jclass class_java_util_concurrent_TimeUnit;
void init_proxies() {
JNIEnv *env = go_seq_push_local_frame(5);
jclass clazz;
clazz = (*env)->FindClass(env, "java/lang/Runnable");
class_java_lang_Runnable = (*env)->NewGlobalRef(env, clazz);
m_java_lang_Runnable_run = go_seq_get_method_id(clazz, "run", "()V");
clazz = (*env)->FindClass(env, "java/io/InputStream");
class_java_io_InputStream = (*env)->NewGlobalRef(env, clazz);
m_java_io_InputStream_read__ = go_seq_get_method_id(clazz, "read", "()I");
clazz = (*env)->FindClass(env, "java/util/concurrent/Future");
class_java_util_concurrent_Future = (*env)->NewGlobalRef(env, clazz);
m_java_util_concurrent_Future_get__ = go_seq_get_method_id(clazz, "get", "()Ljava/lang/Object;");
m_java_util_concurrent_Future_get__JLjava_util_concurrent_TimeUnit_2 = go_seq_get_method_id(clazz, "get", "(JLjava/util/concurrent/TimeUnit;)Ljava/lang/Object;");
clazz = (*env)->FindClass(env, "java/lang/Object");
class_java_lang_Object = (*env)->NewGlobalRef(env, clazz);
clazz = (*env)->FindClass(env, "java/util/concurrent/TimeUnit");
class_java_util_concurrent_TimeUnit = (*env)->NewGlobalRef(env, clazz);
go_seq_pop_local_frame(env);
}
jint cproxy_java_lang_Runnable_run(jint this) {
JNIEnv *env = go_seq_push_local_frame(1);
// Must be a Java object
jobject _this = go_seq_from_refnum(env, this, NULL, NULL);
(*env)->CallVoidMethod(env, _this, m_java_lang_Runnable_run);
jobject _exc = go_seq_get_exception(env);
int32_t _exc_ref = go_seq_to_refnum(env, _exc);
go_seq_pop_local_frame(env);
return _exc_ref;
}
ret_jint cproxy_java_io_InputStream_read__(jint this) {
JNIEnv *env = go_seq_push_local_frame(1);
// Must be a Java object
jobject _this = go_seq_from_refnum(env, this, NULL, NULL);
jint res = (*env)->CallIntMethod(env, _this, m_java_io_InputStream_read__);
jobject _exc = go_seq_get_exception(env);
int32_t _exc_ref = go_seq_to_refnum(env, _exc);
jint _res = res;
go_seq_pop_local_frame(env);
ret_jint __res = {_res, _exc_ref};
return __res;
}
ret_jint csuper_java_io_InputStream_read__(jint this) {
JNIEnv *env = go_seq_push_local_frame(1);
// Must be a Java object
jobject _this = go_seq_from_refnum(env, this, NULL, NULL);
jint res = (*env)->CallNonvirtualIntMethod(env, _this, class_java_io_InputStream, m_java_io_InputStream_read__);
jobject _exc = go_seq_get_exception(env);
int32_t _exc_ref = go_seq_to_refnum(env, _exc);
jint _res = res;
go_seq_pop_local_frame(env);
ret_jint __res = {_res, _exc_ref};
return __res;
}
ret_jint cproxy_java_util_concurrent_Future_get__(jint this) {
JNIEnv *env = go_seq_push_local_frame(1);
// Must be a Java object
jobject _this = go_seq_from_refnum(env, this, NULL, NULL);
jobject res = (*env)->CallObjectMethod(env, _this, m_java_util_concurrent_Future_get__);
jobject _exc = go_seq_get_exception(env);
int32_t _exc_ref = go_seq_to_refnum(env, _exc);
jint _res = go_seq_to_refnum(env, res);
go_seq_pop_local_frame(env);
ret_jint __res = {_res, _exc_ref};
return __res;
}
ret_jint cproxy_java_util_concurrent_Future_get__JLjava_util_concurrent_TimeUnit_2(jint this, jlong a0, jint a1) {
JNIEnv *env = go_seq_push_local_frame(3);
// Must be a Java object
jobject _this = go_seq_from_refnum(env, this, NULL, NULL);
jlong _a0 = a0;
jobject _a1 = go_seq_from_refnum(env, a1, NULL, NULL);
jobject res = (*env)->CallObjectMethod(env, _this, m_java_util_concurrent_Future_get__JLjava_util_concurrent_TimeUnit_2, _a0, _a1);
jobject _exc = go_seq_get_exception(env);
int32_t _exc_ref = go_seq_to_refnum(env, _exc);
jint _res = go_seq_to_refnum(env, res);
go_seq_pop_local_frame(env);
ret_jint __res = {_res, _exc_ref};
return __res;
}
// JNI functions for the Go <=> Java bridge.
// gobind -lang=java classes
//
// File is generated by gobind. Do not edit.
#include <android/log.h>
#include <stdint.h>
#include "seq.h"
#include "_cgo_export.h"
#include "java.h"
jclass proxy_class_java_Future;
jmethodID proxy_class_java_Future_cons;
jclass proxy_class_java_InputStream;
jmethodID proxy_class_java_InputStream_cons;
jclass proxy_class_java_Object;
jmethodID proxy_class_java_Object_cons;
jclass proxy_class_java_Runnable;
jmethodID proxy_class_java_Runnable_cons;
JNIEXPORT void JNICALL
Java_go_java_Java__1init(JNIEnv *env, jclass _unused) {
jclass clazz;
clazz = (*env)->FindClass(env, "go/java/Future");
proxy_class_java_Future = (*env)->NewGlobalRef(env, clazz);
proxy_class_java_Future_cons = (*env)->GetMethodID(env, clazz, "<init>", "(Lgo/Seq$Ref;)V");
clazz = (*env)->FindClass(env, "go/java/Object");
proxy_class_java_Object = (*env)->NewGlobalRef(env, clazz);
proxy_class_java_Object_cons = (*env)->GetMethodID(env, clazz, "<init>", "(Lgo/Seq$Ref;)V");
clazz = (*env)->FindClass(env, "go/java/Runnable");
proxy_class_java_Runnable = (*env)->NewGlobalRef(env, clazz);
proxy_class_java_Runnable_cons = (*env)->GetMethodID(env, clazz, "<init>", "(Lgo/Seq$Ref;)V");
}
JNIEXPORT jobject JNICALL
Java_go_java_Java_newInputStream(JNIEnv* env, jclass _clazz) {
int32_t r0 = proxyjava__NewInputStream();
jobject _r0 = go_seq_from_refnum(env, r0, proxy_class_java_InputStream, proxy_class_java_InputStream_cons);
return _r0;
}
JNIEXPORT jobject JNICALL
Java_go_java_Future__1_1New(JNIEnv *env, jclass clazz) {
int32_t refnum = new_java_Future();
return go_seq_from_refnum(env, refnum, NULL, NULL);
}
JNIEXPORT jobject JNICALL
Java_go_java_Future_get__(JNIEnv* env, jobject __this__) {
int32_t o = go_seq_to_refnum_go(env, __this__);
int32_t r0 = proxyjava_Future_Get(o);
jobject _r0 = go_seq_from_refnum(env, r0, NULL, NULL);
return _r0;
}
JNIEXPORT jobject JNICALL
Java_go_java_Future_get__JLjava_util_concurrent_TimeUnit_2(JNIEnv* env, jobject __this__, jlong p0, jobject p1) {
int32_t o = go_seq_to_refnum_go(env, __this__);
int64_t _p0 = (int64_t)p0;
int32_t _p1 = go_seq_to_refnum(env, p1);
int32_t r0 = proxyjava_Future_Get2(o, _p0, _p1);
jobject _r0 = go_seq_from_refnum(env, r0, NULL, NULL);
return _r0;
}
JNIEXPORT void JNICALL
Java_go_java_Future_setFuture(JNIEnv *env, jobject this, jobject v) {
int32_t o = go_seq_to_refnum(env, this);
int32_t _v = go_seq_to_refnum(env, v);
proxyjava_Future_Future_Set(o, _v);
}
JNIEXPORT jobject JNICALL
Java_go_java_Future_getFuture(JNIEnv *env, jobject this) {
int32_t o = go_seq_to_refnum(env, this);
int32_t r0 = proxyjava_Future_Future_Get(o);
jobject _r0 = go_seq_from_refnum(env, r0, NULL, NULL);
return _r0;
}
JNIEXPORT jobject JNICALL
Java_go_java_InputStream__1_1NewInputStream(JNIEnv *env, jclass clazz) {
int32_t refnum = proxyjava__NewInputStream();
return go_seq_from_refnum(env, refnum, NULL, NULL);
}
JNIEXPORT jint JNICALL
Java_go_java_InputStream_read__(JNIEnv* env, jobject __this__) {
int32_t o = go_seq_to_refnum_go(env, __this__);
struct proxyjava_InputStream_Read_return res = proxyjava_InputStream_Read(o);
jint _r0 = (jint)res.r0;
jobject _r1 = go_seq_from_refnum(env, res.r1, proxy_class__error, proxy_class__error_cons);
go_seq_maybe_throw_exception(env, _r1);
return _r0;
}
JNIEXPORT void JNICALL
Java_go_java_InputStream_setInputStream(JNIEnv *env, jobject this, jobject v) {
int32_t o = go_seq_to_refnum(env, this);
int32_t _v = go_seq_to_refnum(env, v);
proxyjava_InputStream_InputStream_Set(o, _v);
}
JNIEXPORT jobject JNICALL
Java_go_java_InputStream_getInputStream(JNIEnv *env, jobject this) {
int32_t o = go_seq_to_refnum(env, this);
int32_t r0 = proxyjava_InputStream_InputStream_Get(o);
jobject _r0 = go_seq_from_refnum(env, r0, NULL, NULL);
return _r0;
}
JNIEXPORT jobject JNICALL
Java_go_java_Object__1_1New(JNIEnv *env, jclass clazz) {
int32_t refnum = new_java_Object();
return go_seq_from_refnum(env, refnum, NULL, NULL);
}
JNIEXPORT void JNICALL
Java_go_java_Object_setObject(JNIEnv *env, jobject this, jobject v) {
int32_t o = go_seq_to_refnum(env, this);
int32_t _v = go_seq_to_refnum(env, v);
proxyjava_Object_Object_Set(o, _v);
}
JNIEXPORT jobject JNICALL
Java_go_java_Object_getObject(JNIEnv *env, jobject this) {
int32_t o = go_seq_to_refnum(env, this);
int32_t r0 = proxyjava_Object_Object_Get(o);
jobject _r0 = go_seq_from_refnum(env, r0, NULL, NULL);
return _r0;
}
JNIEXPORT jobject JNICALL
Java_go_java_Runnable__1_1New(JNIEnv *env, jclass clazz) {
int32_t refnum = new_java_Runnable();
return go_seq_from_refnum(env, refnum, NULL, NULL);
}
JNIEXPORT void JNICALL
Java_go_java_Runnable_run(JNIEnv* env, jobject __this__) {
int32_t o = go_seq_to_refnum_go(env, __this__);
int32_t _this = go_seq_to_refnum(env, __this__);
proxyjava_Runnable_Run(o, _this);
}
JNIEXPORT void JNICALL
Java_go_java_Runnable_setRunnable(JNIEnv *env, jobject this, jobject v) {
int32_t o = go_seq_to_refnum(env, this);
int32_t _v = go_seq_to_refnum(env, v);
proxyjava_Runnable_Runnable_Set(o, _v);
}
JNIEXPORT jobject JNICALL
Java_go_java_Runnable_getRunnable(JNIEnv *env, jobject this) {
int32_t o = go_seq_to_refnum(env, this);
int32_t r0 = proxyjava_Runnable_Runnable_Get(o);
jobject _r0 = go_seq_from_refnum(env, r0, NULL, NULL);
return _r0;
}