bind/objc: correct handling of empty string return value.
Fixes golang/go#13087
Change-Id: I9d7319d9ed3eee73e6479510911f796ab0607bd2
Reviewed-on: https://go-review.googlesource.com/16452
Reviewed-by: David Crawshaw <crawshaw@golang.org>
diff --git a/bind/objc/SeqTest.m b/bind/objc/SeqTest.m
index de2a21f..10b3541 100644
--- a/bind/objc/SeqTest.m
+++ b/bind/objc/SeqTest.m
@@ -84,6 +84,20 @@
}
}
+void testString() {
+ NSString *input = @"";
+ NSString *got = GoTestpkgEcho(input);
+ if (!got || ![got isEqualToString:input]) {
+ ERROR(@"want %@\nGoTestpkgEcho(%@)= %@", input, input, got);
+ }
+
+ input = @"FOO";
+ got = GoTestpkgEcho(input);
+ if (!got || ![got isEqualToString:input]) {
+ ERROR(@"want %@\nGoTestpkgEcho(%@)= %@", input, input, got);
+ }
+}
+
void testBytesAppend(NSString *a, NSString *b) {
NSData *data_a = [a dataUsingEncoding:NSUTF8StringEncoding];
NSData *data_b = [b dataUsingEncoding:NSUTF8StringEncoding];
@@ -338,6 +352,8 @@
testHello(@"세계"); // korean, utf-8, world.
+ testString();
+
unichar t[] = {
0xD83D, 0xDCA9,
}; // utf-16, pile of poo.
diff --git a/bind/objc/seq_darwin.m b/bind/objc/seq_darwin.m
index 009933e..a87d7a5 100644
--- a/bind/objc/seq_darwin.m
+++ b/bind/objc/seq_darwin.m
@@ -247,8 +247,8 @@
NSString *go_seq_readUTF8(GoSeq *seq) {
int32_t len = *MEM_READ(seq, int32_t);
- if (len == 0) {
- return NULL;
+ if (len == 0) { // empty string.
+ return @"";
}
const void *buf = (const void *)mem_read(seq, len, 1);
return [[NSString alloc] initWithBytes:buf
diff --git a/bind/objc/testpkg/go_testpkg/go_testpkg.go b/bind/objc/testpkg/go_testpkg/go_testpkg.go
index 577513a..cf3760b 100644
--- a/bind/objc/testpkg/go_testpkg/go_testpkg.go
+++ b/bind/objc/testpkg/go_testpkg/go_testpkg.go
@@ -66,6 +66,12 @@
out.WriteInt(res)
}
+func proxy_Echo(out, in *seq.Buffer) {
+ param_s := in.ReadString()
+ res := testpkg.Echo(param_s)
+ out.WriteString(res)
+}
+
func proxy_GC(out, in *seq.Buffer) {
testpkg.GC()
}
@@ -404,18 +410,19 @@
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)
+ seq.Register("testpkg", 6, proxy_Echo)
+ seq.Register("testpkg", 7, proxy_GC)
+ seq.Register("testpkg", 8, proxy_Hello)
+ seq.Register("testpkg", 9, proxy_Hi)
+ seq.Register("testpkg", 10, proxy_Int)
+ seq.Register("testpkg", 11, proxy_Multiply)
+ seq.Register("testpkg", 12, proxy_NewI)
+ seq.Register("testpkg", 13, proxy_NewNode)
+ seq.Register("testpkg", 14, proxy_NewS)
+ seq.Register("testpkg", 15, proxy_RegisterI)
+ seq.Register("testpkg", 16, proxy_ReturnsError)
+ seq.Register("testpkg", 17, proxy_Sum)
+ seq.Register("testpkg", 18, proxy_UnregisterI)
}
func init() {
seq.Register("testpkg.IntVar", 1, var_setIntVar)
diff --git a/bind/objc/testpkg/objc_testpkg/GoTestpkg.h b/bind/objc/testpkg/objc_testpkg/GoTestpkg.h
index 542e11a..1164f53 100644
--- a/bind/objc/testpkg/objc_testpkg/GoTestpkg.h
+++ b/bind/objc/testpkg/objc_testpkg/GoTestpkg.h
@@ -97,6 +97,8 @@
FOUNDATION_EXPORT int GoTestpkgCollectS(int want, int timeoutSec);
+FOUNDATION_EXPORT NSString* GoTestpkgEcho(NSString* s);
+
FOUNDATION_EXPORT void GoTestpkgGC();
FOUNDATION_EXPORT NSString* GoTestpkgHello(NSString* s);
diff --git a/bind/objc/testpkg/objc_testpkg/GoTestpkg.m b/bind/objc/testpkg/objc_testpkg/GoTestpkg.m
index aa8980e..362c891 100644
--- a/bind/objc/testpkg/objc_testpkg/GoTestpkg.m
+++ b/bind/objc/testpkg/objc_testpkg/GoTestpkg.m
@@ -472,18 +472,19 @@
#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 _CALL_Echo_ 6
+#define _CALL_GC_ 7
+#define _CALL_Hello_ 8
+#define _CALL_Hi_ 9
+#define _CALL_Int_ 10
+#define _CALL_Multiply_ 11
+#define _CALL_NewI_ 12
+#define _CALL_NewNode_ 13
+#define _CALL_NewS_ 14
+#define _CALL_RegisterI_ 15
+#define _CALL_ReturnsError_ 16
+#define _CALL_Sum_ 17
+#define _CALL_UnregisterI_ 18
NSData* GoTestpkgBytesAppend(NSData* a, NSData* b) {
GoSeq in_ = {};
@@ -573,6 +574,17 @@
return ret0_;
}
+NSString* GoTestpkgEcho(NSString* s) {
+ GoSeq in_ = {};
+ GoSeq out_ = {};
+ go_seq_writeUTF8(&in_, s);
+ go_seq_send(_DESCRIPTOR_, _CALL_Echo_, &in_, &out_);
+ NSString* ret0_ = go_seq_readUTF8(&out_);
+ go_seq_free(&in_);
+ go_seq_free(&out_);
+ return ret0_;
+}
+
void GoTestpkgGC() {
GoSeq in_ = {};
GoSeq out_ = {};
diff --git a/bind/objc/testpkg/testpkg.go b/bind/objc/testpkg/testpkg.go
index 8d69073..ff68a91 100644
--- a/bind/objc/testpkg/testpkg.go
+++ b/bind/objc/testpkg/testpkg.go
@@ -186,3 +186,7 @@
type Z interface {
}
+
+func Echo(s string) string {
+ return s
+}