2
0
mirror of synced 2025-02-24 23:38:22 +00:00
Elias Naur 6fca37c69e mobile/bind: replace seq serialization with direct calls
The seq serialization machinery is a historic artifact from when Go
mobile code had to run in a separate process. Now that Go code is running
in-process, replace the explicit serialization with direct calls and pass
arguments on the stack.

The benefits are a much smaller bind runtime, much less garbage (and, in
Java, fewer objects with finalizers), less argument copying, and faster
cross-language calls.
The cost is a more complex generator, because some of the work from the
bind runtime is moved to generated code. Generated code now handles
conversion between Go and Java/ObjC types, multiple return values and memory
management of byte slice and string arguments.

To overcome the lack of calling C code between Go packages, all bound
packages now end up in the same (fake) package, "gomobile_bind", instead of
separate packages (go_<pkgname>). To avoid name clashes, the package name is
added as a prefix to generated functions and types.

Also, don't copy byte arrays passed to Go, saving call time and
allowing read([]byte)-style interfaces to foreign callers (#12113).

Finally, add support for nil interfaces and struct pointers to objc.

This is a large CL, but most of the changes stem from changing testdata.

The full benchcmp output on the CL/20095 benchmarks on my Nexus 5 is
reproduced below. Note that the savings for the JavaSlice* benchmarks are
skewed because byte slices are no longer copied before passing them to Go.

benchmark                                 old ns/op     new ns/op     delta
BenchmarkJavaEmpty                        26.0          19.0          -26.92%
BenchmarkJavaEmptyDirect                  23.0          22.0          -4.35%
BenchmarkJavaNoargs                       7685          2339          -69.56%
BenchmarkJavaNoargsDirect                 17405         8041          -53.80%
BenchmarkJavaOnearg                       26887         2366          -91.20%
BenchmarkJavaOneargDirect                 34266         7910          -76.92%
BenchmarkJavaOneret                       38325         2245          -94.14%
BenchmarkJavaOneretDirect                 46265         7708          -83.34%
BenchmarkJavaManyargs                     41720         2535          -93.92%
BenchmarkJavaManyargsDirect               51026         8373          -83.59%
BenchmarkJavaRefjava                      38139         21260         -44.26%
BenchmarkJavaRefjavaDirect                42706         28150         -34.08%
BenchmarkJavaRefgo                        34403         6843          -80.11%
BenchmarkJavaRefgoDirect                  40193         16582         -58.74%
BenchmarkJavaStringShort                  32366         9323          -71.20%
BenchmarkJavaStringShortDirect            41973         19118         -54.45%
BenchmarkJavaStringLong                   127879        94420         -26.16%
BenchmarkJavaStringLongDirect             133776        114760        -14.21%
BenchmarkJavaStringShortUnicode           32562         9221          -71.68%
BenchmarkJavaStringShortUnicodeDirect     41464         19094         -53.95%
BenchmarkJavaStringLongUnicode            131015        89401         -31.76%
BenchmarkJavaStringLongUnicodeDirect      134130        90786         -32.31%
BenchmarkJavaSliceShort                   42462         7538          -82.25%
BenchmarkJavaSliceShortDirect             52940         17017         -67.86%
BenchmarkJavaSliceLong                    138391        8466          -93.88%
BenchmarkJavaSliceLongDirect              205804        15666         -92.39%
BenchmarkGoEmpty                          3.00          3.00          +0.00%
BenchmarkGoEmptyDirect                    3.00          3.00          +0.00%
BenchmarkGoNoarg                          40342         13716         -66.00%
BenchmarkGoNoargDirect                    46691         13569         -70.94%
BenchmarkGoOnearg                         43529         13757         -68.40%
BenchmarkGoOneargDirect                   44867         14078         -68.62%
BenchmarkGoOneret                         45456         13559         -70.17%
BenchmarkGoOneretDirect                   44694         13442         -69.92%
BenchmarkGoRefjava                        55111         28071         -49.06%
BenchmarkGoRefjavaDirect                  60883         26872         -55.86%
BenchmarkGoRefgo                          57038         29223         -48.77%
BenchmarkGoRefgoDirect                    56153         27812         -50.47%
BenchmarkGoManyargs                       67967         17398         -74.40%
BenchmarkGoManyargsDirect                 60617         16998         -71.96%
BenchmarkGoStringShort                    57538         22600         -60.72%
BenchmarkGoStringShortDirect              52627         22704         -56.86%
BenchmarkGoStringLong                     128485        52530         -59.12%
BenchmarkGoStringLongDirect               138377        52079         -62.36%
BenchmarkGoStringShortUnicode             57062         22994         -59.70%
BenchmarkGoStringShortUnicodeDirect       62563         22938         -63.34%
BenchmarkGoStringLongUnicode              139913        55553         -60.29%
BenchmarkGoStringLongUnicodeDirect        150863        57791         -61.69%
BenchmarkGoSliceShort                     59279         20215         -65.90%
BenchmarkGoSliceShortDirect               60160         21136         -64.87%
BenchmarkGoSliceLong                      411225        301870        -26.59%
BenchmarkGoSliceLongDirect                399029        298915        -25.09%

Fixes golang/go#12619
Fixes golang/go#12113
Fixes golang/go#13033

Change-Id: I2b45e9e98a1248e3c23a5137f775f7364908bec7
Reviewed-on: https://go-review.googlesource.com/19821
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-03-03 15:03:45 +00:00

726 lines
20 KiB
Objective-C

// Objective-C API for talking to golang.org/x/mobile/bind/objc/testpkg Go package.
// gobind -lang=objc golang.org/x/mobile/bind/objc/testpkg
//
// File is generated by gobind. Do not edit.
#include "GoTestpkg.h"
#include <Foundation/Foundation.h>
#include "seq.h"
#include "_cgo_export.h"
static NSString* errDomain = @"go.golang.org/x/mobile/bind/objc/testpkg";
@protocol goSeqRefInterface
-(GoSeqRef*) _ref;
@end
@class GoTestpkgI;
@class GoTestpkgNullTest;
@class GoTestpkgZ;
@interface GoTestpkgI : NSObject <GoTestpkgI> {
}
@property(strong, readonly) id _ref;
- (id)initWithRef:(id)ref;
- (BOOL)error:(BOOL)triggerError error:(NSError**)error;
- (BOOL)stringError:(NSString*)s ret0_:(NSString**)ret0_ error:(NSError**)error;
- (int64_t)times:(int32_t)v;
@end
@interface GoTestpkgNullTest : NSObject <GoTestpkgNullTest> {
}
@property(strong, readonly) id _ref;
- (id)initWithRef:(id)ref;
- (id<GoTestpkgNullTest>)null;
@end
@interface GoTestpkgZ : NSObject <GoTestpkgZ> {
}
@property(strong, readonly) id _ref;
- (id)initWithRef:(id)ref;
@end
@implementation GoTestpkgNode {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (NSString*)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring r0 = proxytestpkg_Node_V_Get(refnum);
NSString *_r0 = go_seq_to_objc_string(r0);
return _r0;
}
- (void)setV:(NSString*)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring _v = go_seq_from_objc_string(v);
proxytestpkg_Node_V_Set(refnum, _v);
}
- (NSString*)err {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring r0 = proxytestpkg_Node_Err_Get(refnum);
NSString *_r0 = go_seq_to_objc_string(r0);
return _r0;
}
- (void)setErr:(NSString*)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring _v = go_seq_from_objc_string(v);
proxytestpkg_Node_Err_Set(refnum, _v);
}
@end
@implementation GoTestpkgNullFieldStruct {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (GoTestpkgS*)f {
int32_t refnum = go_seq_go_to_refnum(self._ref);
int32_t r0 = proxytestpkg_NullFieldStruct_F_Get(refnum);
GoTestpkgS* _r0 = nil;
GoSeqRef* _r0_ref = go_seq_from_refnum(r0);
if (_r0_ref != NULL) {
_r0 = _r0_ref.obj;
if (_r0 == nil) {
_r0 = [[GoTestpkgS alloc] initWithRef:_r0_ref];
}
}
return _r0;
}
- (void)setF:(GoTestpkgS*)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
int32_t _v;
if ([(id<NSObject>)(v) isKindOfClass:[GoTestpkgS class]]) {
id<goSeqRefInterface> v_proxy = (id<goSeqRefInterface>)(v);
_v = go_seq_go_to_refnum(v_proxy._ref);
} else {
_v = go_seq_to_refnum(v);
}
proxytestpkg_NullFieldStruct_F_Set(refnum, _v);
}
@end
@implementation GoTestpkgS {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (double)x {
int32_t refnum = go_seq_go_to_refnum(self._ref);
double r0 = proxytestpkg_S_X_Get(refnum);
double _r0 = (double)r0;
return _r0;
}
- (void)setX:(double)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
double _v = (double)v;
proxytestpkg_S_X_Set(refnum, _v);
}
- (double)y {
int32_t refnum = go_seq_go_to_refnum(self._ref);
double r0 = proxytestpkg_S_Y_Get(refnum);
double _r0 = (double)r0;
return _r0;
}
- (void)setY:(double)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
double _v = (double)v;
proxytestpkg_S_Y_Set(refnum, _v);
}
- (double)sum {
int32_t refnum = go_seq_go_to_refnum(self._ref);
double r0 = proxytestpkg_S_Sum(refnum);
double _ret0_ = (double)r0;
return _ret0_;
}
- (NSString*)tryTwoStrings:(NSString*)first second:(NSString*)second {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring _first = go_seq_from_objc_string(first);
nstring _second = go_seq_from_objc_string(second);
nstring r0 = proxytestpkg_S_TryTwoStrings(refnum, _first, _second);
NSString *_ret0_ = go_seq_to_objc_string(r0);
return _ret0_;
}
@end
@implementation GoTestpkgStructThatStartsWithLetterBeforeZ {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (id<GoTestpkgZ>)value {
int32_t refnum = go_seq_go_to_refnum(self._ref);
int32_t r0 = proxytestpkg_StructThatStartsWithLetterBeforeZ_Value_Get(refnum);
id<GoTestpkgZ> _r0 = nil;
GoSeqRef* _r0_ref = go_seq_from_refnum(r0);
if (_r0_ref != NULL) {
_r0 = _r0_ref.obj;
if (_r0 == nil) {
_r0 = [[GoTestpkgZ alloc] initWithRef:_r0_ref];
}
}
return _r0;
}
- (void)setValue:(id<GoTestpkgZ>)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
int32_t _v;
if ([(id<NSObject>)(v) isKindOfClass:[GoTestpkgZ class]]) {
id<goSeqRefInterface> v_proxy = (id<goSeqRefInterface>)(v);
_v = go_seq_go_to_refnum(v_proxy._ref);
} else {
_v = go_seq_to_refnum(v);
}
proxytestpkg_StructThatStartsWithLetterBeforeZ_Value_Set(refnum, _v);
}
@end
@implementation GoTestpkgI {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (BOOL)error:(BOOL)triggerError error:(NSError**)error {
int32_t refnum = go_seq_go_to_refnum(self._ref);
char _triggerError = (char)triggerError;
nstring r0 = proxytestpkg_I_Error(refnum, _triggerError);
NSString *_error = go_seq_to_objc_string(r0);
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
return ([_error length] == 0);
}
- (BOOL)stringError:(NSString*)s ret0_:(NSString**)ret0_ error:(NSError**)error {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring _s = go_seq_from_objc_string(s);
struct proxytestpkg_I_StringError_return res = proxytestpkg_I_StringError(refnum, _s);
NSString *_ret0_ = go_seq_to_objc_string(res.r0);
NSString *_error = go_seq_to_objc_string(res.r1);
*ret0_ = _ret0_;
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
return ([_error length] == 0);
}
- (int64_t)times:(int32_t)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
int32_t _v = (int32_t)v;
int64_t r0 = proxytestpkg_I_Times(refnum, _v);
int64_t _ret0_ = (int64_t)r0;
return _ret0_;
}
@end
@implementation GoTestpkgNullTest {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (id<GoTestpkgNullTest>)null {
int32_t refnum = go_seq_go_to_refnum(self._ref);
int32_t r0 = proxytestpkg_NullTest_Null(refnum);
id<GoTestpkgNullTest> _ret0_ = nil;
GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
if (_ret0__ref != NULL) {
_ret0_ = _ret0__ref.obj;
if (_ret0_ == nil) {
_ret0_ = [[GoTestpkgNullTest alloc] initWithRef:_ret0__ref];
}
}
return _ret0_;
}
@end
@implementation GoTestpkgZ {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
@end
const BOOL GoTestpkgABool = YES;
const double GoTestpkgAFloat = 0.12345;
NSString* const GoTestpkgALongString = @"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";
NSString* const GoTestpkgAString = @"a string";
const int64_t GoTestpkgAnInt = 7LL;
const double GoTestpkgLog2E = 1.4426950408889634;
const float GoTestpkgMaxFloat32 = 3.4028234663852886e+38;
const double GoTestpkgMaxFloat64 = 1.7976931348623157e+308;
const int32_t GoTestpkgMaxInt32 = 2147483647;
const int64_t GoTestpkgMaxInt64 = 9223372036854775807LL;
const int32_t GoTestpkgMinInt32 = -2147483648;
const int64_t GoTestpkgMinInt64 = -9223372036854775807LL-1;
const float GoTestpkgSmallestNonzeroFloat32 = 0;
const double GoTestpkgSmallestNonzeroFloat64 = 5e-324;
@implementation GoTestpkg
+ (void) setIntVar:(int)v {
nint _v = (nint)v;
var_settestpkg_IntVar(_v);
}
+ (int) intVar {
nint r0 = var_gettestpkg_IntVar();
int _r0 = (int)r0;
return _r0;
}
+ (void) setInterfaceVar:(id<GoTestpkgI>)v {
int32_t _v;
if ([(id<NSObject>)(v) isKindOfClass:[GoTestpkgI 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_settestpkg_InterfaceVar(_v);
}
+ (id<GoTestpkgI>) interfaceVar {
int32_t r0 = var_gettestpkg_InterfaceVar();
id<GoTestpkgI> _r0 = nil;
GoSeqRef* _r0_ref = go_seq_from_refnum(r0);
if (_r0_ref != NULL) {
_r0 = _r0_ref.obj;
if (_r0 == nil) {
_r0 = [[GoTestpkgI alloc] initWithRef:_r0_ref];
}
}
return _r0;
}
+ (void) setStringVar:(NSString*)v {
nstring _v = go_seq_from_objc_string(v);
var_settestpkg_StringVar(_v);
}
+ (NSString*) stringVar {
nstring r0 = var_gettestpkg_StringVar();
NSString *_r0 = go_seq_to_objc_string(r0);
return _r0;
}
+ (void) setStructVar:(GoTestpkgNode*)v {
int32_t _v;
if ([(id<NSObject>)(v) isKindOfClass:[GoTestpkgNode 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_settestpkg_StructVar(_v);
}
+ (GoTestpkgNode*) structVar {
int32_t r0 = var_gettestpkg_StructVar();
GoTestpkgNode* _r0 = nil;
GoSeqRef* _r0_ref = go_seq_from_refnum(r0);
if (_r0_ref != NULL) {
_r0 = _r0_ref.obj;
if (_r0 == nil) {
_r0 = [[GoTestpkgNode alloc] initWithRef:_r0_ref];
}
}
return _r0;
}
@end
NSData* GoTestpkgBytesAppend(NSData* a, NSData* b) {
nbyteslice _a = go_seq_from_objc_bytearray(a, 0);
nbyteslice _b = go_seq_from_objc_bytearray(b, 0);
nbyteslice r0 = proxytestpkg__BytesAppend(_a, _b);
if (![a isKindOfClass:[NSMutableData class]]) {
free(_a.ptr);
}
if (![b isKindOfClass:[NSMutableData class]]) {
free(_b.ptr);
}
NSData *_ret0_ = go_seq_to_objc_bytearray(r0, 1);
return _ret0_;
}
BOOL GoTestpkgCallIError(id<GoTestpkgI> i, BOOL triggerError, NSError** error) {
int32_t _i;
if ([(id<NSObject>)(i) isKindOfClass:[GoTestpkgI class]]) {
id<goSeqRefInterface> i_proxy = (id<goSeqRefInterface>)(i);
_i = go_seq_go_to_refnum(i_proxy._ref);
} else {
_i = go_seq_to_refnum(i);
}
char _triggerError = (char)triggerError;
nstring r0 = proxytestpkg__CallIError(_i, _triggerError);
NSString *_error = go_seq_to_objc_string(r0);
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
return ([_error length] == 0);
}
BOOL GoTestpkgCallIStringError(id<GoTestpkgI> i, NSString* s, NSString** ret0_, NSError** error) {
int32_t _i;
if ([(id<NSObject>)(i) isKindOfClass:[GoTestpkgI class]]) {
id<goSeqRefInterface> i_proxy = (id<goSeqRefInterface>)(i);
_i = go_seq_go_to_refnum(i_proxy._ref);
} else {
_i = go_seq_to_refnum(i);
}
nstring _s = go_seq_from_objc_string(s);
struct proxytestpkg__CallIStringError_return res = proxytestpkg__CallIStringError(_i, _s);
NSString *_ret0_ = go_seq_to_objc_string(res.r0);
NSString *_error = go_seq_to_objc_string(res.r1);
*ret0_ = _ret0_;
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
return ([_error length] == 0);
}
double GoTestpkgCallSSum(GoTestpkgS* s) {
int32_t _s;
if ([(id<NSObject>)(s) isKindOfClass:[GoTestpkgS class]]) {
id<goSeqRefInterface> s_proxy = (id<goSeqRefInterface>)(s);
_s = go_seq_go_to_refnum(s_proxy._ref);
} else {
_s = go_seq_to_refnum(s);
}
double r0 = proxytestpkg__CallSSum(_s);
double _ret0_ = (double)r0;
return _ret0_;
}
BOOL GoTestpkgCallWithNull(id<GoTestpkgNullTest> p0, id<GoTestpkgNullTest> nuller) {
int32_t _p0;
if ([(id<NSObject>)(p0) isKindOfClass:[GoTestpkgNullTest class]]) {
id<goSeqRefInterface> p0_proxy = (id<goSeqRefInterface>)(p0);
_p0 = go_seq_go_to_refnum(p0_proxy._ref);
} else {
_p0 = go_seq_to_refnum(p0);
}
int32_t _nuller;
if ([(id<NSObject>)(nuller) isKindOfClass:[GoTestpkgNullTest class]]) {
id<goSeqRefInterface> nuller_proxy = (id<goSeqRefInterface>)(nuller);
_nuller = go_seq_go_to_refnum(nuller_proxy._ref);
} else {
_nuller = go_seq_to_refnum(nuller);
}
char r0 = proxytestpkg__CallWithNull(_p0, _nuller);
BOOL _ret0_ = r0 ? YES : NO;
return _ret0_;
}
int GoTestpkgCollectS(int want, int timeoutSec) {
nint _want = (nint)want;
nint _timeoutSec = (nint)timeoutSec;
nint r0 = proxytestpkg__CollectS(_want, _timeoutSec);
int _ret0_ = (int)r0;
return _ret0_;
}
NSString* GoTestpkgEcho(NSString* s) {
nstring _s = go_seq_from_objc_string(s);
nstring r0 = proxytestpkg__Echo(_s);
NSString *_ret0_ = go_seq_to_objc_string(r0);
return _ret0_;
}
void GoTestpkgGC() {
proxytestpkg__GC();
}
NSString* GoTestpkgHello(NSString* s) {
nstring _s = go_seq_from_objc_string(s);
nstring r0 = proxytestpkg__Hello(_s);
NSString *_ret0_ = go_seq_to_objc_string(r0);
return _ret0_;
}
void GoTestpkgHi() {
proxytestpkg__Hi();
}
void GoTestpkgInt(int32_t x) {
int32_t _x = (int32_t)x;
proxytestpkg__Int(_x);
}
int64_t GoTestpkgMultiply(int32_t idx, int32_t val) {
int32_t _idx = (int32_t)idx;
int32_t _val = (int32_t)val;
int64_t r0 = proxytestpkg__Multiply(_idx, _val);
int64_t _ret0_ = (int64_t)r0;
return _ret0_;
}
id<GoTestpkgI> GoTestpkgNewI() {
int32_t r0 = proxytestpkg__NewI();
id<GoTestpkgI> _ret0_ = nil;
GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
if (_ret0__ref != NULL) {
_ret0_ = _ret0__ref.obj;
if (_ret0_ == nil) {
_ret0_ = [[GoTestpkgI alloc] initWithRef:_ret0__ref];
}
}
return _ret0_;
}
GoTestpkgNode* GoTestpkgNewNode(NSString* name) {
nstring _name = go_seq_from_objc_string(name);
int32_t r0 = proxytestpkg__NewNode(_name);
GoTestpkgNode* _ret0_ = nil;
GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
if (_ret0__ref != NULL) {
_ret0_ = _ret0__ref.obj;
if (_ret0_ == nil) {
_ret0_ = [[GoTestpkgNode alloc] initWithRef:_ret0__ref];
}
}
return _ret0_;
}
GoTestpkgNullFieldStruct* GoTestpkgNewNullFieldStruct() {
int32_t r0 = proxytestpkg__NewNullFieldStruct();
GoTestpkgNullFieldStruct* _ret0_ = nil;
GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
if (_ret0__ref != NULL) {
_ret0_ = _ret0__ref.obj;
if (_ret0_ == nil) {
_ret0_ = [[GoTestpkgNullFieldStruct alloc] initWithRef:_ret0__ref];
}
}
return _ret0_;
}
id<GoTestpkgI> GoTestpkgNewNullInterface() {
int32_t r0 = proxytestpkg__NewNullInterface();
id<GoTestpkgI> _ret0_ = nil;
GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
if (_ret0__ref != NULL) {
_ret0_ = _ret0__ref.obj;
if (_ret0_ == nil) {
_ret0_ = [[GoTestpkgI alloc] initWithRef:_ret0__ref];
}
}
return _ret0_;
}
GoTestpkgS* GoTestpkgNewNullStruct() {
int32_t r0 = proxytestpkg__NewNullStruct();
GoTestpkgS* _ret0_ = nil;
GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
if (_ret0__ref != NULL) {
_ret0_ = _ret0__ref.obj;
if (_ret0_ == nil) {
_ret0_ = [[GoTestpkgS alloc] initWithRef:_ret0__ref];
}
}
return _ret0_;
}
GoTestpkgS* GoTestpkgNewS(double x, double y) {
double _x = (double)x;
double _y = (double)y;
int32_t r0 = proxytestpkg__NewS(_x, _y);
GoTestpkgS* _ret0_ = nil;
GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
if (_ret0__ref != NULL) {
_ret0_ = _ret0__ref.obj;
if (_ret0_ == nil) {
_ret0_ = [[GoTestpkgS alloc] initWithRef:_ret0__ref];
}
}
return _ret0_;
}
BOOL GoTestpkgReadIntoByteArray(NSData* s, int* ret0_, NSError** error) {
nbyteslice _s = go_seq_from_objc_bytearray(s, 0);
struct proxytestpkg__ReadIntoByteArray_return res = proxytestpkg__ReadIntoByteArray(_s);
if (![s isKindOfClass:[NSMutableData class]]) {
free(_s.ptr);
}
int _ret0_ = (int)res.r0;
NSString *_error = go_seq_to_objc_string(res.r1);
*ret0_ = _ret0_;
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
return ([_error length] == 0);
}
void GoTestpkgRegisterI(int32_t idx, id<GoTestpkgI> i) {
int32_t _idx = (int32_t)idx;
int32_t _i;
if ([(id<NSObject>)(i) isKindOfClass:[GoTestpkgI class]]) {
id<goSeqRefInterface> i_proxy = (id<goSeqRefInterface>)(i);
_i = go_seq_go_to_refnum(i_proxy._ref);
} else {
_i = go_seq_to_refnum(i);
}
proxytestpkg__RegisterI(_idx, _i);
}
BOOL GoTestpkgReturnsError(BOOL b, NSString** ret0_, NSError** error) {
char _b = (char)b;
struct proxytestpkg__ReturnsError_return res = proxytestpkg__ReturnsError(_b);
NSString *_ret0_ = go_seq_to_objc_string(res.r0);
NSString *_error = go_seq_to_objc_string(res.r1);
*ret0_ = _ret0_;
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
return ([_error length] == 0);
}
NSString* GoTestpkgStringDup(NSString* s) {
nstring _s = go_seq_from_objc_string(s);
nstring r0 = proxytestpkg__StringDup(_s);
NSString *_ret0_ = go_seq_to_objc_string(r0);
return _ret0_;
}
int64_t GoTestpkgSum(int64_t x, int64_t y) {
int64_t _x = (int64_t)x;
int64_t _y = (int64_t)y;
int64_t r0 = proxytestpkg__Sum(_x, _y);
int64_t _ret0_ = (int64_t)r0;
return _ret0_;
}
void GoTestpkgUnregisterI(int32_t idx) {
int32_t _idx = (int32_t)idx;
proxytestpkg__UnregisterI(_idx);
}
nstring cproxytestpkg_I_Error(int32_t refnum, char triggerError) {
id<GoTestpkgI> o = go_seq_objc_from_refnum(refnum);
BOOL _triggerError = triggerError ? YES : NO;
NSError* error = nil;
BOOL returnVal = [o error:_triggerError error:&error];
NSString *error_str = nil;
if (!returnVal) {
error_str = [error localizedDescription];
if (error_str == nil || error_str.length == 0) {
error_str = @"gobind: unknown error";
}
}
nstring _error_str = go_seq_from_objc_string(error_str);
return _error_str;
}
struct cproxytestpkg_I_StringError_return cproxytestpkg_I_StringError(int32_t refnum, nstring s) {
id<GoTestpkgI> o = go_seq_objc_from_refnum(refnum);
NSString *_s = go_seq_to_objc_string(s);
NSString* ret0_;
NSError* error = nil;
BOOL returnVal = [o stringError:_s ret0_:&ret0_ error:&error];
nstring _ret0_ = go_seq_from_objc_string(ret0_);
NSString *error_str = nil;
if (!returnVal) {
error_str = [error localizedDescription];
if (error_str == nil || error_str.length == 0) {
error_str = @"gobind: unknown error";
}
}
nstring _error_str = go_seq_from_objc_string(error_str);
cproxytestpkg_I_StringError_return _sres = {
_ret0_, _error_str
};
return _sres;
}
int64_t cproxytestpkg_I_Times(int32_t refnum, int32_t v) {
id<GoTestpkgI> o = go_seq_objc_from_refnum(refnum);
int32_t _v = (int32_t)v;
int64_t returnVal = [o times:_v];
int64_t _returnVal = (int64_t)returnVal;
return _returnVal;
}
int32_t cproxytestpkg_NullTest_Null(int32_t refnum) {
id<GoTestpkgNullTest> o = go_seq_objc_from_refnum(refnum);
id<GoTestpkgNullTest> returnVal = [o null];
int32_t _returnVal;
if ([(id<NSObject>)(returnVal) isKindOfClass:[GoTestpkgNullTest class]]) {
id<goSeqRefInterface> returnVal_proxy = (id<goSeqRefInterface>)(returnVal);
_returnVal = go_seq_go_to_refnum(returnVal_proxy._ref);
} else {
_returnVal = go_seq_to_refnum(returnVal);
}
return _returnVal;
}
__attribute__((constructor)) static void init() {
init_seq();
}