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>
89 lines
2.4 KiB
Plaintext
89 lines
2.4 KiB
Plaintext
// Objective-C API for talking to issue12403 Go package.
|
|
// gobind -lang=objc issue12403
|
|
//
|
|
// File is generated by gobind. Do not edit.
|
|
|
|
#include <Foundation/Foundation.h>
|
|
#include "seq.h"
|
|
#include "_cgo_export.h"
|
|
#include "GoIssue12403.h"
|
|
|
|
@implementation GoIssue12403Parsable {
|
|
}
|
|
|
|
- (instancetype)initWithRef:(id)ref {
|
|
self = [super init];
|
|
if (self) { __ref = ref; }
|
|
return self;
|
|
}
|
|
|
|
- (NSString*)fromJSON:(NSString*)jstr {
|
|
int32_t refnum = go_seq_go_to_refnum(self._ref);
|
|
nstring _jstr = go_seq_from_objc_string(jstr);
|
|
nstring r0 = proxyissue12403_Parsable_FromJSON(refnum, _jstr);
|
|
NSString *_ret0_ = go_seq_to_objc_string(r0);
|
|
return _ret0_;
|
|
}
|
|
|
|
- (BOOL)toJSON:(NSString**)ret0_ error:(NSError**)error {
|
|
int32_t refnum = go_seq_go_to_refnum(self._ref);
|
|
struct proxyissue12403_Parsable_ToJSON_return res = proxyissue12403_Parsable_ToJSON(refnum);
|
|
NSString *_ret0_ = go_seq_to_objc_string(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);
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
nstring cproxyissue12403_Parsable_FromJSON(int32_t refnum, nstring jstr) {
|
|
@autoreleasepool {
|
|
GoIssue12403Parsable* o = go_seq_objc_from_refnum(refnum);
|
|
NSString *_jstr = go_seq_to_objc_string(jstr);
|
|
NSString* returnVal = [o fromJSON:_jstr];
|
|
nstring _returnVal = go_seq_from_objc_string(returnVal);
|
|
return _returnVal;
|
|
}
|
|
}
|
|
|
|
struct cproxyissue12403_Parsable_ToJSON_return cproxyissue12403_Parsable_ToJSON(int32_t refnum) {
|
|
@autoreleasepool {
|
|
GoIssue12403Parsable* o = go_seq_objc_from_refnum(refnum);
|
|
NSString* ret0_;
|
|
NSError* error = nil;
|
|
BOOL returnVal = [o toJSON:&ret0_ error:&error];
|
|
nstring _ret0_ = go_seq_from_objc_string(ret0_);
|
|
id<GoUniverseerror> _error = nil;
|
|
if (!returnVal) {
|
|
_error = error;
|
|
}
|
|
int32_t __error;
|
|
if ([(id<NSObject>)(_error) isKindOfClass:[GoUniverseerror class]]) {
|
|
id<goSeqRefInterface> _error_proxy = (id<goSeqRefInterface>)(_error);
|
|
__error = go_seq_go_to_refnum(_error_proxy._ref);
|
|
} else {
|
|
__error = go_seq_to_refnum(_error);
|
|
}
|
|
cproxyissue12403_Parsable_ToJSON_return _sres = {
|
|
_ret0_, __error
|
|
};
|
|
return _sres;
|
|
}
|
|
}
|
|
|
|
__attribute__((constructor)) static void init() {
|
|
init_seq();
|
|
}
|