2
0
mirror of synced 2025-02-24 15:28:28 +00:00
mobile/bind/testdata/issue12403.java.c.golden
Elias Naur a3e0621280 mobile/bind: use objects to pass errors across the language barrier
Gobind uses strings for passing errors across the language barrier.
However, since Gobind doesn't have a concept of a nil string, it
can't separate an empty native string from a nil string.

In turn, that means that empty errors, exceptions or NSError * with
an empty description are treated as no error. With ObjC, empty errors
are replaced with a default string to workaround the issue, while
with Java empty errors are silently ignored.

Fix this by replacing strings with actual error objects, wrapping
the Go error, Java Throwable or ObjC NSError *, and letting the
existing bind machinery take care of passing the references across.

It's a large change for a small corner case, but I believe objects
are a better fit for exception that strings. Error objects also
naturally leads to future additions, for example accessing the
exception class name or chained exception.

Change-Id: Ie03b47cafcb231ad1e12a80195693fa7459c6265
Reviewed-on: https://go-review.googlesource.com/24100
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-06-23 18:55:48 +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_init(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/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(12);
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(10);
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_wrap_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;
}