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

83 lines
2.7 KiB
Plaintext

// Objective-C API for talking to basictypes Go package.
// gobind -lang=objc basictypes
//
// File is generated by gobind. Do not edit.
#include <Foundation/Foundation.h>
#include "seq.h"
#include "_cgo_export.h"
#include "GoBasictypes.h"
const BOOL GoBasictypesABool = YES;
const double GoBasictypesAFloat = 0.2015;
NSString* const GoBasictypesALongString = @"LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString";
const int32_t GoBasictypesARune = 32;
NSString* const GoBasictypesAString = @"a string";
const int64_t GoBasictypesAnInt = 7LL;
const int64_t GoBasictypesAnInt2 = 9223372036854775807LL;
BOOL GoBasictypesBool(BOOL p0) {
char _p0 = (char)p0;
char r0 = proxybasictypes__Bool(_p0);
BOOL _ret0_ = r0 ? YES : NO;
return _ret0_;
}
NSData* GoBasictypesByteArrays(NSData* x) {
nbyteslice _x = go_seq_from_objc_bytearray(x, 0);
nbyteslice r0 = proxybasictypes__ByteArrays(_x);
if (![x isKindOfClass:[NSMutableData class]]) {
free(_x.ptr);
}
NSData *_ret0_ = go_seq_to_objc_bytearray(r0, 1);
return _ret0_;
}
BOOL GoBasictypesError(NSError** error) {
int32_t r0 = proxybasictypes__Error();
GoUniverseerror* _error = nil;
GoSeqRef* _error_ref = go_seq_from_refnum(r0);
if (_error_ref != NULL) {
_error = _error_ref.obj;
if (_error == nil) {
_error = [[GoUniverseerror alloc] initWithRef:_error_ref];
}
}
if (_error != nil && error != nil) {
*error = _error;
}
return (_error == nil);
}
BOOL GoBasictypesErrorPair(long* ret0_, NSError** error) {
struct proxybasictypes__ErrorPair_return res = proxybasictypes__ErrorPair();
long _ret0_ = (long)res.r0;
GoUniverseerror* _error = nil;
GoSeqRef* _error_ref = go_seq_from_refnum(res.r1);
if (_error_ref != NULL) {
_error = _error_ref.obj;
if (_error == nil) {
_error = [[GoUniverseerror alloc] initWithRef:_error_ref];
}
}
*ret0_ = _ret0_;
if (_error != nil && error != nil) {
*error = _error;
}
return (_error == nil);
}
void GoBasictypesInts(int8_t x, int16_t y, int32_t z, int64_t t, long u) {
int8_t _x = (int8_t)x;
int16_t _y = (int16_t)y;
int32_t _z = (int32_t)z;
int64_t _t = (int64_t)t;
nint _u = (nint)u;
proxybasictypes__Ints(_x, _y, _z, _t, _u);
}
__attribute__((constructor)) static void init() {
init_seq();
}