diff --git a/bind/bind_test.go b/bind/bind_test.go index 5313b4d..eb75115 100644 --- a/bind/bind_test.go +++ b/bind/bind_test.go @@ -30,6 +30,7 @@ var tests = []string{ "testdata/interfaces.go", "testdata/issue10788.go", "testdata/issue12328.go", + "testdata/issue12403.go", "testdata/try.go", } diff --git a/bind/genobjc.go b/bind/genobjc.go index 00b822c..fcc7350 100644 --- a/bind/genobjc.go +++ b/bind/genobjc.go @@ -597,7 +597,7 @@ func (g *objcGen) genInterfaceMethodProxy(obj *types.TypeName, s *funcSummary) { if s.returnsVal() { // len(s.retParams) == 1 && s.retParams[0] != error p := s.retParams[0] if stype := g.seqType(p.typ); stype == "Ref" { - g.Printf("if [(id)(returnVal) isKindOfClass:[%s class]]) {\n", g.refTypeBase(p.typ)) + g.Printf("if ([(id)(returnVal) isKindOfClass:[%s class]]) {\n", g.refTypeBase(p.typ)) g.Indent() g.Printf("idretVal_proxy = (id)(returnVal);\n") g.Printf("go_seq_writeRef(out, retVal_proxy.ref);\n") @@ -633,9 +633,9 @@ func (g *objcGen) genInterfaceMethodProxy(obj *types.TypeName, s *funcSummary) { g.Printf("go_seq_writeUTF8(out, %sDesc);\n", p.name) g.Outdent() g.Printf("}\n") - } else if seqTyp := g.seqType(p.typ); seqTyp != "Ref" { + } else if seqTyp := g.seqType(p.typ); seqTyp == "Ref" { // TODO(hyangah): NULL. - g.Printf("if [(id)(%s) isKindOfClass:[%s class]]) {\n", p.name, g.refTypeBase(p.typ)) + g.Printf("if ([(id)(%s) isKindOfClass:[%s class]]) {\n", p.name, g.refTypeBase(p.typ)) g.Indent() g.Printf("id%[1]s_proxy = (id)(%[1]s);\n", p.name) g.Printf("go_seq_writeRef(out, %s_proxy.ref);\n", p.name) @@ -735,6 +735,7 @@ func (g *objcGen) refTypeBase(typ types.Type) string { } // fallback to whatever objcType returns. This must not happen. + panic(fmt.Sprintf("wtf: %+T", typ)) return g.objcType(typ) } diff --git a/bind/objc/SeqTest.m b/bind/objc/SeqTest.m index 9de0dd9..2607a67 100644 --- a/bind/objc/SeqTest.m +++ b/bind/objc/SeqTest.m @@ -107,6 +107,18 @@ static int numI = 0; } @synthesize value; +- (BOOL)StringError:(NSString *)s + ret0_:(NSString **)ret0_ + error:(NSError **)error { + if ([s isEqualTo:@"number"]) { + if (ret0_ != NULL) { + *ret0_ = @"OK"; + } + return true; + } + return false; +} + - (BOOL)Error:(BOOL)triggerError error:(NSError **)error { if (!triggerError) { return YES; @@ -120,6 +132,7 @@ static int numI = 0; - (int64_t)Times:(int32_t)v { return v * value; } + - (void)dealloc { if (self.value == 0) { numI++; @@ -179,6 +192,28 @@ void testIssue12307() { } } +void testIssue12403() { + Number *num = [[Number alloc] init]; + num.value = 1024; + + NSString *ret; + NSError *error; + if (GoTestpkgCallIStringError(num, @"alphabet", &ret, &error) == YES) { + ERROR( + @"GoTestpkgCallIStringError(Number, 'alphabet') succeeded; want error"); + } + NSError *error2; + if (GoTestpkgCallIStringError(num, @"number", &ret, &error2) == NO) { + ERROR( + @"GoTestpkgCallIStringError(Number, 'number') failed(%@); want success", + error2); + } else if (![ret isEqualTo:@"OK"]) { + ERROR(@"GoTestpkgCallIStringError(Number, 'number') returned unexpected " + @"results %@", + ret); + } +} + // Invokes functions and object methods defined in Testpkg.h. // // TODO(hyangah): apply testing framework (e.g. XCTestCase) diff --git a/bind/objc/testpkg/go_testpkg/go_testpkg.go b/bind/objc/testpkg/go_testpkg/go_testpkg.go index 86d3beb..45a23da 100644 --- a/bind/objc/testpkg/go_testpkg/go_testpkg.go +++ b/bind/objc/testpkg/go_testpkg/go_testpkg.go @@ -33,6 +33,24 @@ func proxy_CallIError(out, in *seq.Buffer) { } } +func proxy_CallIStringError(out, in *seq.Buffer) { + var param_i testpkg.I + param_i_ref := in.ReadRef() + if param_i_ref.Num < 0 { // go object + param_i = param_i_ref.Get().(testpkg.I) + } else { // foreign object + param_i = (*proxyI)(param_i_ref) + } + param_s := in.ReadString() + res, err := testpkg.CallIStringError(param_i, param_s) + out.WriteString(res) + if err == nil { + out.WriteString("") + } else { + out.WriteString(err.Error()) + } +} + func proxy_CallSSum(out, in *seq.Buffer) { // Must be a Go object param_s_ref := in.ReadRef() @@ -63,9 +81,10 @@ func proxy_Hi(out, in *seq.Buffer) { } const ( - proxyI_Descriptor = "go.testpkg.I" - proxyI_Error_Code = 0x10a - proxyI_Times_Code = 0x20a + proxyI_Descriptor = "go.testpkg.I" + proxyI_Error_Code = 0x10a + proxyI_StringError_Code = 0x20a + proxyI_Times_Code = 0x30a ) func proxyI_Error(out, in *seq.Buffer) { @@ -80,6 +99,19 @@ func proxyI_Error(out, in *seq.Buffer) { } } +func proxyI_StringError(out, in *seq.Buffer) { + ref := in.ReadRef() + v := ref.Get().(testpkg.I) + param_s := in.ReadString() + res, err := v.StringError(param_s) + out.WriteString(res) + if err == nil { + out.WriteString("") + } else { + out.WriteString(err.Error()) + } +} + func proxyI_Times(out, in *seq.Buffer) { ref := in.ReadRef() v := ref.Get().(testpkg.I) @@ -90,6 +122,7 @@ func proxyI_Times(out, in *seq.Buffer) { func init() { seq.Register(proxyI_Descriptor, proxyI_Error_Code, proxyI_Error) + seq.Register(proxyI_Descriptor, proxyI_StringError_Code, proxyI_StringError) seq.Register(proxyI_Descriptor, proxyI_Times_Code, proxyI_Times) } @@ -103,6 +136,15 @@ func (p *proxyI) Error(triggerError bool) error { return res_0 } +func (p *proxyI) StringError(s string) (string, error) { + in := new(seq.Buffer) + in.WriteString(s) + out := seq.Transact((*seq.Ref)(p), "go.testpkg.I", proxyI_StringError_Code, in) + res_0 := out.ReadString() + res_1 := out.ReadError() + return res_0, res_1 +} + func (p *proxyI) Times(v int32) int64 { in := new(seq.Buffer) in.WriteInt32(v) @@ -285,18 +327,19 @@ func proxy_UnregisterI(out, in *seq.Buffer) { func init() { seq.Register("testpkg", 1, proxy_BytesAppend) seq.Register("testpkg", 2, proxy_CallIError) - seq.Register("testpkg", 3, proxy_CallSSum) - seq.Register("testpkg", 4, proxy_CollectS) - seq.Register("testpkg", 5, proxy_GC) - seq.Register("testpkg", 6, proxy_Hello) - seq.Register("testpkg", 7, proxy_Hi) - seq.Register("testpkg", 8, proxy_Int) - seq.Register("testpkg", 9, proxy_Multiply) - seq.Register("testpkg", 10, proxy_NewI) - seq.Register("testpkg", 11, proxy_NewNode) - seq.Register("testpkg", 12, proxy_NewS) - seq.Register("testpkg", 13, proxy_RegisterI) - seq.Register("testpkg", 14, proxy_ReturnsError) - seq.Register("testpkg", 15, proxy_Sum) - seq.Register("testpkg", 16, proxy_UnregisterI) + seq.Register("testpkg", 3, proxy_CallIStringError) + seq.Register("testpkg", 4, proxy_CallSSum) + seq.Register("testpkg", 5, proxy_CollectS) + seq.Register("testpkg", 6, proxy_GC) + seq.Register("testpkg", 7, proxy_Hello) + seq.Register("testpkg", 8, proxy_Hi) + seq.Register("testpkg", 9, proxy_Int) + seq.Register("testpkg", 10, proxy_Multiply) + seq.Register("testpkg", 11, proxy_NewI) + seq.Register("testpkg", 12, proxy_NewNode) + seq.Register("testpkg", 13, proxy_NewS) + seq.Register("testpkg", 14, proxy_RegisterI) + seq.Register("testpkg", 15, proxy_ReturnsError) + seq.Register("testpkg", 16, proxy_Sum) + seq.Register("testpkg", 17, proxy_UnregisterI) } diff --git a/bind/objc/testpkg/objc_testpkg/GoTestpkg.h b/bind/objc/testpkg/objc_testpkg/GoTestpkg.h index 141469d..224a18d 100644 --- a/bind/objc/testpkg/objc_testpkg/GoTestpkg.h +++ b/bind/objc/testpkg/objc_testpkg/GoTestpkg.h @@ -14,6 +14,7 @@ @protocol GoTestpkgI - (BOOL)Error:(BOOL)triggerError error:(NSError**)error; +- (BOOL)StringError:(NSString*)s ret0_:(NSString**)ret0_ error:(NSError**)error; - (int64_t)Times:(int32_t)v; @end @@ -45,6 +46,8 @@ FOUNDATION_EXPORT NSData* GoTestpkgBytesAppend(NSData* a, NSData* b); FOUNDATION_EXPORT BOOL GoTestpkgCallIError(id i, BOOL triggerError, NSError** error); +FOUNDATION_EXPORT BOOL GoTestpkgCallIStringError(id i, NSString* s, NSString** ret0_, NSError** error); + FOUNDATION_EXPORT double GoTestpkgCallSSum(GoTestpkgS* s); FOUNDATION_EXPORT int GoTestpkgCollectS(int want, int timeoutSec); diff --git a/bind/objc/testpkg/objc_testpkg/GoTestpkg.m b/bind/objc/testpkg/objc_testpkg/GoTestpkg.m index ef40f24..345ef21 100644 --- a/bind/objc/testpkg/objc_testpkg/GoTestpkg.m +++ b/bind/objc/testpkg/objc_testpkg/GoTestpkg.m @@ -17,24 +17,26 @@ static NSString* errDomain = @"go.golang.org/x/mobile/bind/objc/testpkg"; #define _CALL_BytesAppend_ 1 #define _CALL_CallIError_ 2 -#define _CALL_CallSSum_ 3 -#define _CALL_CollectS_ 4 -#define _CALL_GC_ 5 -#define _CALL_Hello_ 6 -#define _CALL_Hi_ 7 -#define _CALL_Int_ 8 -#define _CALL_Multiply_ 9 -#define _CALL_NewI_ 10 -#define _CALL_NewNode_ 11 -#define _CALL_NewS_ 12 -#define _CALL_RegisterI_ 13 -#define _CALL_ReturnsError_ 14 -#define _CALL_Sum_ 15 -#define _CALL_UnregisterI_ 16 +#define _CALL_CallIStringError_ 3 +#define _CALL_CallSSum_ 4 +#define _CALL_CollectS_ 5 +#define _CALL_GC_ 6 +#define _CALL_Hello_ 7 +#define _CALL_Hi_ 8 +#define _CALL_Int_ 9 +#define _CALL_Multiply_ 10 +#define _CALL_NewI_ 11 +#define _CALL_NewNode_ 12 +#define _CALL_NewS_ 13 +#define _CALL_RegisterI_ 14 +#define _CALL_ReturnsError_ 15 +#define _CALL_Sum_ 16 +#define _CALL_UnregisterI_ 17 #define _GO_testpkg_I_DESCRIPTOR_ "go.testpkg.I" #define _GO_testpkg_I_Error_ (0x10a) -#define _GO_testpkg_I_Times_ (0x20a) +#define _GO_testpkg_I_StringError_ (0x20a) +#define _GO_testpkg_I_Times_ (0x30a) @interface GoTestpkgI : NSObject { } @@ -42,6 +44,7 @@ static NSString* errDomain = @"go.golang.org/x/mobile/bind/objc/testpkg"; - (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 @@ -71,6 +74,27 @@ static NSString* errDomain = @"go.golang.org/x/mobile/bind/objc/testpkg"; return ([_error length] == 0); } +- (BOOL)StringError:(NSString*)s ret0_:(NSString**)ret0_ error:(NSError**)error { + GoSeq in_ = {}; + GoSeq out_ = {}; + go_seq_writeRef(&in_, self.ref); + go_seq_writeUTF8(&in_, s); + go_seq_send(_GO_testpkg_I_DESCRIPTOR_, _GO_testpkg_I_StringError_, &in_, &out_); + NSString* ret0__val = go_seq_readUTF8(&out_); + if (ret0_ != NULL) { + *ret0_ = ret0__val; + } + NSString* _error = go_seq_readUTF8(&out_); + if ([_error length] != 0 && error != nil) { + NSMutableDictionary* details = [NSMutableDictionary dictionary]; + [details setValue:_error forKey:NSLocalizedDescriptionKey]; + *error = [NSError errorWithDomain:errDomain code:1 userInfo:details]; + } + go_seq_free(&in_); + go_seq_free(&out_); + return ([_error length] == 0); +} + - (int64_t)Times:(int32_t)v { GoSeq in_ = {}; GoSeq out_ = {}; @@ -102,6 +126,23 @@ static void proxyGoTestpkgI(id obj, int code, GoSeq* in, GoSeq* out) { go_seq_writeUTF8(out, errorDesc); } } break; + case _GO_testpkg_I_StringError_: { + id o = (id)(obj); + NSString* s = go_seq_readUTF8(in); + NSString* ret0_; + NSError* error = NULL; + BOOL returnVal = [o StringError:s ret0_:&ret0_ error:&error]; + go_seq_writeUTF8(out, ret0_); + if (returnVal) { + go_seq_writeUTF8(out, NULL); + } else { + NSString* errorDesc = [error localizedDescription]; + if (errorDesc == NULL || errorDesc.length == 0) { + errorDesc = @"gobind: unknown error"; + } + go_seq_writeUTF8(out, errorDesc); + } + } break; case _GO_testpkg_I_Times_: { id o = (id)(obj); int32_t v = go_seq_readInt32(in); @@ -291,6 +332,32 @@ BOOL GoTestpkgCallIError(id i, BOOL triggerError, NSError** error) { return ([_error length] == 0); } +BOOL GoTestpkgCallIStringError(id i, NSString* s, NSString** ret0_, NSError** error) { + GoSeq in_ = {}; + GoSeq out_ = {}; + if ([(id)(i) isKindOfClass:[GoTestpkgI class]]) { + id i_proxy = (id)(i); + go_seq_writeRef(&in_, i_proxy.ref); + } else { + go_seq_writeObjcRef(&in_, i); + } + go_seq_writeUTF8(&in_, s); + go_seq_send(_DESCRIPTOR_, _CALL_CallIStringError_, &in_, &out_); + NSString* ret0__val = go_seq_readUTF8(&out_); + if (ret0_ != NULL) { + *ret0_ = ret0__val; + } + NSString* _error = go_seq_readUTF8(&out_); + if ([_error length] != 0 && error != nil) { + NSMutableDictionary* details = [NSMutableDictionary dictionary]; + [details setValue:_error forKey:NSLocalizedDescriptionKey]; + *error = [NSError errorWithDomain:errDomain code:1 userInfo:details]; + } + go_seq_free(&in_); + go_seq_free(&out_); + return ([_error length] == 0); +} + double GoTestpkgCallSSum(GoTestpkgS* s) { GoSeq in_ = {}; GoSeq out_ = {}; diff --git a/bind/objc/testpkg/testpkg.go b/bind/objc/testpkg/testpkg.go index 7238f47..d5c5218 100644 --- a/bind/objc/testpkg/testpkg.go +++ b/bind/objc/testpkg/testpkg.go @@ -17,6 +17,8 @@ import ( type I interface { Times(v int32) int64 Error(triggerError bool) error + + StringError(s string) (string, error) } type myI struct{} @@ -32,10 +34,18 @@ func (i *myI) Error(e bool) error { return nil } +func (i *myI) StringError(s string) (string, error) { + return s, nil +} + func CallIError(i I, triggerError bool) error { return i.Error(triggerError) } +func CallIStringError(i I, s string) (string, error) { + return i.StringError(s) +} + func NewI() I { return &myI{} } diff --git a/bind/testdata/interfaces.go.golden b/bind/testdata/interfaces.go.golden index fc2dc68..a3fa216 100644 --- a/bind/testdata/interfaces.go.golden +++ b/bind/testdata/interfaces.go.golden @@ -146,8 +146,6 @@ func (p *proxyI3) F() interfaces.I1 { res_0_ref := out.ReadRef() if res_0_ref.Num < 0 { // go object res_0 = res_0_ref.Get().(interfaces.I1) - } else { // foreign object - res_0 = (*proxyI1)(res_0_ref) } return res_0 } diff --git a/bind/testdata/interfaces.objc.h.golden b/bind/testdata/interfaces.objc.h.golden index 7f277d1..794deb0 100644 --- a/bind/testdata/interfaces.objc.h.golden +++ b/bind/testdata/interfaces.objc.h.golden @@ -8,6 +8,10 @@ #include +@class GoInterfacesI1; + +@class GoInterfacesI2; + @protocol GoInterfacesError - (BOOL)Err:(NSError**)error; @end @@ -35,7 +39,7 @@ @protocol GoInterfacesI3 -- (id)F; +- (GoInterfacesI1*)F; @end @protocol GoInterfacesWithParam diff --git a/bind/testdata/interfaces.objc.m.golden b/bind/testdata/interfaces.objc.m.golden index 06fc493..72dea5f 100644 --- a/bind/testdata/interfaces.objc.m.golden +++ b/bind/testdata/interfaces.objc.m.golden @@ -179,7 +179,7 @@ static void proxyGoInterfacesI(id obj, int code, GoSeq* in, GoSeq* out) { @property(strong, readonly) id ref; - (id)initWithRef:(id)ref; -- (id)F; +- (GoInterfacesI1*)F; @end @implementation GoInterfacesI3 { @@ -191,13 +191,13 @@ static void proxyGoInterfacesI(id obj, int code, GoSeq* in, GoSeq* out) { return self; } -- (id)F { +- (GoInterfacesI1*)F { GoSeq in_ = {}; GoSeq out_ = {}; go_seq_writeRef(&in_, self.ref); go_seq_send(_GO_interfaces_I3_DESCRIPTOR_, _GO_interfaces_I3_F_, &in_, &out_); GoSeqRef* ret0__ref = go_seq_readRef(&out_); - id ret0_ = ret0__ref.obj; + GoInterfacesI1* ret0_ = ret0__ref.obj; if (ret0_ == NULL) { ret0_ = [[GoInterfacesI1 alloc] initWithRef:ret0__ref]; } @@ -212,8 +212,8 @@ static void proxyGoInterfacesI3(id obj, int code, GoSeq* in, GoSeq* out) { switch (code) { case _GO_interfaces_I3_F_: { id o = (id)(obj); - id returnVal = [o F]; - if [(id)(returnVal) isKindOfClass:[GoInterfacesI1 class]]) { + GoInterfacesI1* returnVal = [o F]; + if ([(id)(returnVal) isKindOfClass:[GoInterfacesI1 class]]) { idretVal_proxy = (id)(returnVal); go_seq_writeRef(out, retVal_proxy.ref); } else { diff --git a/bind/testdata/issue12403.go b/bind/testdata/issue12403.go new file mode 100644 index 0000000..bf55567 --- /dev/null +++ b/bind/testdata/issue12403.go @@ -0,0 +1,6 @@ +package issue12403 + +type Parsable interface { + FromJSON(jstr string) string + ToJSON() (string, error) +} diff --git a/bind/testdata/issue12403.go.golden b/bind/testdata/issue12403.go.golden new file mode 100644 index 0000000..7708d5c --- /dev/null +++ b/bind/testdata/issue12403.go.golden @@ -0,0 +1,59 @@ +// Package go_issue12403 is an autogenerated binder stub for package issue12403. +// gobind -lang=go issue12403 +// +// File is generated by gobind. Do not edit. +package go_issue12403 + +import ( + "golang.org/x/mobile/bind/seq" + "issue12403" +) + +const ( + proxyParsable_Descriptor = "go.issue12403.Parsable" + proxyParsable_FromJSON_Code = 0x10a + proxyParsable_ToJSON_Code = 0x20a +) + +func proxyParsable_FromJSON(out, in *seq.Buffer) { + ref := in.ReadRef() + v := ref.Get().(issue12403.Parsable) + param_jstr := in.ReadString() + res := v.FromJSON(param_jstr) + out.WriteString(res) +} + +func proxyParsable_ToJSON(out, in *seq.Buffer) { + ref := in.ReadRef() + v := ref.Get().(issue12403.Parsable) + res, err := v.ToJSON() + out.WriteString(res) + if err == nil { + out.WriteString("") + } else { + out.WriteString(err.Error()) + } +} + +func init() { + seq.Register(proxyParsable_Descriptor, proxyParsable_FromJSON_Code, proxyParsable_FromJSON) + seq.Register(proxyParsable_Descriptor, proxyParsable_ToJSON_Code, proxyParsable_ToJSON) +} + +type proxyParsable seq.Ref + +func (p *proxyParsable) FromJSON(jstr string) string { + in := new(seq.Buffer) + in.WriteString(jstr) + out := seq.Transact((*seq.Ref)(p), "go.issue12403.Parsable", proxyParsable_FromJSON_Code, in) + res_0 := out.ReadString() + return res_0 +} + +func (p *proxyParsable) ToJSON() (string, error) { + in := new(seq.Buffer) + out := seq.Transact((*seq.Ref)(p), "go.issue12403.Parsable", proxyParsable_ToJSON_Code, in) + res_0 := out.ReadString() + res_1 := out.ReadError() + return res_0, res_1 +} diff --git a/bind/testdata/issue12403.java.golden b/bind/testdata/issue12403.java.golden new file mode 100644 index 0000000..e98508e --- /dev/null +++ b/bind/testdata/issue12403.java.golden @@ -0,0 +1,98 @@ +// Java class go.issue12403.Issue12403 is a proxy for talking to a Go program. +// gobind -lang=java issue12403 +// +// File is generated by gobind. Do not edit. +package go.issue12403; + +import go.Seq; + +public abstract class Issue12403 { + private Issue12403() {} // uninstantiable + + public interface Parsable extends go.Seq.Object { + public String FromJSON(String jstr); + + public String ToJSON() throws Exception; + + public static abstract class Stub implements Parsable { + static final String DESCRIPTOR = "go.issue12403.Parsable"; + + private final go.Seq.Ref ref; + public Stub() { + ref = go.Seq.createRef(this); + } + + public go.Seq.Ref ref() { return ref; } + + public void call(int code, go.Seq in, go.Seq out) { + switch (code) { + case Proxy.CALL_FromJSON: { + String param_jstr; + param_jstr = in.readString(); + String result = this.FromJSON(param_jstr); + out.writeString(result); + return; + } + case Proxy.CALL_ToJSON: { + try { + String result = this.ToJSON(); + out.writeString(result); + out.writeString(null); + } catch (Exception e) { + String result = null; + out.writeString(result); + out.writeString(e.getMessage()); + } + return; + } + default: + throw new RuntimeException("unknown code: "+ code); + } + } + } + + static final class Proxy implements Parsable { + static final String DESCRIPTOR = Stub.DESCRIPTOR; + + private go.Seq.Ref ref; + + Proxy(go.Seq.Ref ref) { this.ref = ref; } + + public go.Seq.Ref ref() { return ref; } + + public void call(int code, go.Seq in, go.Seq out) { + throw new RuntimeException("cycle: cannot call proxy"); + } + + public String FromJSON(String jstr) { + go.Seq _in = new go.Seq(); + go.Seq _out = new go.Seq(); + String _result; + _in.writeRef(ref); + _in.writeString(jstr); + Seq.send(DESCRIPTOR, CALL_FromJSON, _in, _out); + _result = _out.readString(); + return _result; + } + + public String ToJSON() throws Exception { + go.Seq _in = new go.Seq(); + go.Seq _out = new go.Seq(); + String _result; + _in.writeRef(ref); + Seq.send(DESCRIPTOR, CALL_ToJSON, _in, _out); + _result = _out.readString(); + String _err = _out.readString(); + if (_err != null) { + throw new Exception(_err); + } + return _result; + } + + static final int CALL_FromJSON = 0x10a; + static final int CALL_ToJSON = 0x20a; + } + } + + private static final String DESCRIPTOR = "issue12403"; +} diff --git a/bind/testdata/issue12403.objc.h.golden b/bind/testdata/issue12403.objc.h.golden new file mode 100644 index 0000000..391e988 --- /dev/null +++ b/bind/testdata/issue12403.objc.h.golden @@ -0,0 +1,16 @@ +// Objective-C API for talking to issue12403 Go package. +// gobind -lang=objc issue12403 +// +// File is generated by gobind. Do not edit. + +#ifndef __GoIssue12403_H__ +#define __GoIssue12403_H__ + +#include + +@protocol GoIssue12403Parsable +- (NSString*)FromJSON:(NSString*)jstr; +- (BOOL)ToJSON:(NSString**)ret0_ error:(NSError**)error; +@end + +#endif diff --git a/bind/testdata/issue12403.objc.m.golden b/bind/testdata/issue12403.objc.m.golden new file mode 100644 index 0000000..c95c045 --- /dev/null +++ b/bind/testdata/issue12403.objc.m.golden @@ -0,0 +1,106 @@ +// Objective-C API for talking to issue12403 Go package. +// gobind -lang=objc issue12403 +// +// File is generated by gobind. Do not edit. + +#include "GoIssue12403.h" +#include +#include "seq.h" + +static NSString* errDomain = @"go.issue12403"; + +@protocol goSeqRefInterface +-(GoSeqRef*) ref; +@end + +#define _DESCRIPTOR_ "issue12403" + + +#define _GO_issue12403_Parsable_DESCRIPTOR_ "go.issue12403.Parsable" +#define _GO_issue12403_Parsable_FromJSON_ (0x10a) +#define _GO_issue12403_Parsable_ToJSON_ (0x20a) + +@interface GoIssue12403Parsable : NSObject { +} +@property(strong, readonly) id ref; + +- (id)initWithRef:(id)ref; +- (NSString*)FromJSON:(NSString*)jstr; +- (BOOL)ToJSON:(NSString**)ret0_ error:(NSError**)error; +@end + +@implementation GoIssue12403Parsable { +} + +- (id)initWithRef:(id)ref { + self = [super init]; + if (self) { _ref = ref; } + return self; +} + +- (NSString*)FromJSON:(NSString*)jstr { + GoSeq in_ = {}; + GoSeq out_ = {}; + go_seq_writeRef(&in_, self.ref); + go_seq_writeUTF8(&in_, jstr); + go_seq_send(_GO_issue12403_Parsable_DESCRIPTOR_, _GO_issue12403_Parsable_FromJSON_, &in_, &out_); + NSString* ret0_ = go_seq_readUTF8(&out_); + go_seq_free(&in_); + go_seq_free(&out_); + return ret0_; +} + +- (BOOL)ToJSON:(NSString**)ret0_ error:(NSError**)error { + GoSeq in_ = {}; + GoSeq out_ = {}; + go_seq_writeRef(&in_, self.ref); + go_seq_send(_GO_issue12403_Parsable_DESCRIPTOR_, _GO_issue12403_Parsable_ToJSON_, &in_, &out_); + NSString* ret0__val = go_seq_readUTF8(&out_); + if (ret0_ != NULL) { + *ret0_ = ret0__val; + } + NSString* _error = go_seq_readUTF8(&out_); + if ([_error length] != 0 && error != nil) { + NSMutableDictionary* details = [NSMutableDictionary dictionary]; + [details setValue:_error forKey:NSLocalizedDescriptionKey]; + *error = [NSError errorWithDomain:errDomain code:1 userInfo:details]; + } + go_seq_free(&in_); + go_seq_free(&out_); + return ([_error length] == 0); +} + +@end + +static void proxyGoIssue12403Parsable(id obj, int code, GoSeq* in, GoSeq* out) { + switch (code) { + case _GO_issue12403_Parsable_FromJSON_: { + id o = (id)(obj); + NSString* jstr = go_seq_readUTF8(in); + NSString* returnVal = [o FromJSON:jstr]; + go_seq_writeUTF8(out, returnVal); + } break; + case _GO_issue12403_Parsable_ToJSON_: { + id o = (id)(obj); + NSString* ret0_; + NSError* error = NULL; + BOOL returnVal = [o ToJSON:&ret0_ error:&error]; + go_seq_writeUTF8(out, ret0_); + if (returnVal) { + go_seq_writeUTF8(out, NULL); + } else { + NSString* errorDesc = [error localizedDescription]; + if (errorDesc == NULL || errorDesc.length == 0) { + errorDesc = @"gobind: unknown error"; + } + go_seq_writeUTF8(out, errorDesc); + } + } break; + default: + NSLog(@"unknown code %x for _GO_issue12403_Parsable_DESCRIPTOR_", code); + } +} + +__attribute__((constructor)) static void init() { + go_seq_register_proxy("go.issue12403.Parsable", proxyGoIssue12403Parsable); +}