2
0
mirror of synced 2025-02-24 07:18:15 +00:00
mobile/bind/testdata/issue12403.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

72 lines
2.9 KiB
Plaintext

// JNI functions for the Go <=> Java bridge.
// gobind -lang=java issue12403
//
// File is generated by gobind. Do not edit.
#include <android/log.h>
#include <stdint.h>
#include "seq.h"
#include "_cgo_export.h"
#include "issue12403.h"
jclass proxy_class_issue12403_Parsable;
jmethodID proxy_class_issue12403_Parsable_cons;
static jmethodID mid_Parsable_FromJSON;
static jmethodID mid_Parsable_ToJSON;
JNIEXPORT void JNICALL
Java_go_issue12403_Issue12403__1init(JNIEnv *env, jclass _unused) {
jclass clazz;
clazz = (*env)->FindClass(env, "go/issue12403/Issue12403$proxyParsable");
proxy_class_issue12403_Parsable = (*env)->NewGlobalRef(env, clazz);
proxy_class_issue12403_Parsable_cons = (*env)->GetMethodID(env, clazz, "<init>", "(Lgo/Seq$Ref;)V");
clazz = (*env)->FindClass(env, "go/issue12403/Parsable");
mid_Parsable_FromJSON = (*env)->GetMethodID(env, clazz, "fromJSON", "(Ljava/lang/String;)Ljava/lang/String;");
mid_Parsable_ToJSON = (*env)->GetMethodID(env, clazz, "toJSON", "()Ljava/lang/String;");
}
JNIEXPORT jstring JNICALL
Java_go_issue12403_Issue12403_00024proxyParsable_fromJSON(JNIEnv* env, jobject __this__, jstring jstr) {
int32_t o = go_seq_to_refnum(env, __this__);
nstring _jstr = go_seq_from_java_string(env, jstr);
nstring r0 = proxyissue12403_Parsable_FromJSON(o, _jstr);
jstring _r0 = go_seq_to_java_string(env, r0);
return _r0;
}
nstring cproxyissue12403_Parsable_FromJSON(int32_t refnum, nstring jstr) {
JNIEnv *env = go_seq_push_local_frame(1);
jobject o = go_seq_from_refnum(env, refnum, proxy_class_issue12403_Parsable, proxy_class_issue12403_Parsable_cons);
jstring _jstr = go_seq_to_java_string(env, jstr);
jstring res = (*env)->CallObjectMethod(env, o, mid_Parsable_FromJSON, _jstr);
nstring _res = go_seq_from_java_string(env, res);
go_seq_pop_local_frame(env);
return _res;
}
JNIEXPORT jstring JNICALL
Java_go_issue12403_Issue12403_00024proxyParsable_toJSON(JNIEnv* env, jobject __this__) {
int32_t o = go_seq_to_refnum(env, __this__);
struct proxyissue12403_Parsable_ToJSON_return res = proxyissue12403_Parsable_ToJSON(o);
jstring _r0 = go_seq_to_java_string(env, 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;
}
struct cproxyissue12403_Parsable_ToJSON_return cproxyissue12403_Parsable_ToJSON(int32_t refnum) {
JNIEnv *env = go_seq_push_local_frame(0);
jobject o = go_seq_from_refnum(env, refnum, proxy_class_issue12403_Parsable, proxy_class_issue12403_Parsable_cons);
jstring res = (*env)->CallObjectMethod(env, o, mid_Parsable_ToJSON);
nstring _res = go_seq_from_java_string(env, res);
jobject exc = go_seq_get_exception(env);
int32_t _exc = go_seq_to_refnum(env, exc);
cproxyissue12403_Parsable_ToJSON_return sres = {
_res, _exc
};
go_seq_pop_local_frame(env);
return sres;
}