2
0
mirror of synced 2025-02-23 14:58:12 +00:00
mobile/bind/testdata/vars.objc.m.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

200 lines
3.5 KiB
Plaintext

// Objective-C API for talking to vars Go package.
// gobind -lang=objc vars
//
// File is generated by gobind. Do not edit.
#include <Foundation/Foundation.h>
#include "seq.h"
#include "_cgo_export.h"
#include "GoVars.h"
@implementation GoVarsS {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
@end
@implementation GoVarsI {
}
- (instancetype)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
@end
@implementation GoVars
+ (void) setABool:(BOOL)v {
char _v = (char)v;
var_setvars_ABool(_v);
}
+ (BOOL) aBool {
char r0 = var_getvars_ABool();
BOOL _r0 = r0 ? YES : NO;
return _r0;
}
+ (void) setAFloat:(double)v {
double _v = (double)v;
var_setvars_AFloat(_v);
}
+ (double) aFloat {
double r0 = var_getvars_AFloat();
double _r0 = (double)r0;
return _r0;
}
+ (void) setAFloat32:(float)v {
float _v = (float)v;
var_setvars_AFloat32(_v);
}
+ (float) aFloat32 {
float r0 = var_getvars_AFloat32();
float _r0 = (float)r0;
return _r0;
}
+ (void) setAFloat64:(double)v {
double _v = (double)v;
var_setvars_AFloat64(_v);
}
+ (double) aFloat64 {
double r0 = var_getvars_AFloat64();
double _r0 = (double)r0;
return _r0;
}
+ (void) setAString:(NSString*)v {
nstring _v = go_seq_from_objc_string(v);
var_setvars_AString(_v);
}
+ (NSString*) aString {
nstring r0 = var_getvars_AString();
NSString *_r0 = go_seq_to_objc_string(r0);
return _r0;
}
+ (void) setAStructPtr:(GoVarsS*)v {
int32_t _v;
if ([(id<NSObject>)(v) isKindOfClass:[GoVarsS class]]) {
id<goSeqRefInterface> v_proxy = (id<goSeqRefInterface>)(v);
_v = go_seq_go_to_refnum(v_proxy._ref);
} else {
_v = go_seq_to_refnum(v);
}
var_setvars_AStructPtr(_v);
}
+ (GoVarsS*) aStructPtr {
int32_t r0 = var_getvars_AStructPtr();
GoVarsS* _r0 = nil;
GoSeqRef* _r0_ref = go_seq_from_refnum(r0);
if (_r0_ref != NULL) {
_r0 = _r0_ref.obj;
if (_r0 == nil) {
_r0 = [[GoVarsS alloc] initWithRef:_r0_ref];
}
}
return _r0;
}
+ (void) setAnInt:(long)v {
nint _v = (nint)v;
var_setvars_AnInt(_v);
}
+ (long) anInt {
nint r0 = var_getvars_AnInt();
long _r0 = (long)r0;
return _r0;
}
+ (void) setAnInt16:(int16_t)v {
int16_t _v = (int16_t)v;
var_setvars_AnInt16(_v);
}
+ (int16_t) anInt16 {
int16_t r0 = var_getvars_AnInt16();
int16_t _r0 = (int16_t)r0;
return _r0;
}
+ (void) setAnInt32:(int32_t)v {
int32_t _v = (int32_t)v;
var_setvars_AnInt32(_v);
}
+ (int32_t) anInt32 {
int32_t r0 = var_getvars_AnInt32();
int32_t _r0 = (int32_t)r0;
return _r0;
}
+ (void) setAnInt64:(int64_t)v {
int64_t _v = (int64_t)v;
var_setvars_AnInt64(_v);
}
+ (int64_t) anInt64 {
int64_t r0 = var_getvars_AnInt64();
int64_t _r0 = (int64_t)r0;
return _r0;
}
+ (void) setAnInt8:(int8_t)v {
int8_t _v = (int8_t)v;
var_setvars_AnInt8(_v);
}
+ (int8_t) anInt8 {
int8_t r0 = var_getvars_AnInt8();
int8_t _r0 = (int8_t)r0;
return _r0;
}
+ (void) setAnInterface:(id<GoVarsI>)v {
int32_t _v;
if ([(id<NSObject>)(v) isKindOfClass:[GoVarsI class]]) {
id<goSeqRefInterface> v_proxy = (id<goSeqRefInterface>)(v);
_v = go_seq_go_to_refnum(v_proxy._ref);
} else {
_v = go_seq_to_refnum(v);
}
var_setvars_AnInterface(_v);
}
+ (id<GoVarsI>) anInterface {
int32_t r0 = var_getvars_AnInterface();
GoVarsI* _r0 = nil;
GoSeqRef* _r0_ref = go_seq_from_refnum(r0);
if (_r0_ref != NULL) {
_r0 = _r0_ref.obj;
if (_r0 == nil) {
_r0 = [[GoVarsI alloc] initWithRef:_r0_ref];
}
}
return _r0;
}
@end
__attribute__((constructor)) static void init() {
init_seq();
}