int callGoReturnVal(void);
int returnAfterGrow(void);
int returnAfterGrowFromGo(void);
+void callGoWithString(void);
*/
import "C"
return
}
+// Test that C can pass in a Go string from a string constant.
+func testCallGoWithString(t *testing.T) {
+ C.callGoWithString()
+ want := "string passed from C to Go"
+ if stringFromGo != want {
+ t.Errorf("string passed through C is %s, want %s", stringFromGo, want)
+ }
+}
+
+var stringFromGo string
+
+//export goWithString
+func goWithString(s string) {
+ stringFromGo = s
+}
+
func testCallbackStack(t *testing.T) {
// Make cgo call and callback with different amount of stack stack available.
// We do not do any explicit checks, just ensure that it does not crash.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "_cgo_export.h"
return goReturnVal();
}
+void
+callGoWithString(void)
+{
+ extern void goWithString(GoString);
+ const char *str = "string passed from C to Go";
+ goWithString((GoString){str, strlen(str)});
+}
func Test11925(t *testing.T) { test11925(t) }
func Test12030(t *testing.T) { test12030(t) }
func TestGCC68255(t *testing.T) { testGCC68255(t) }
+func TestCallGoWithString(t *testing.T) { testCallGoWithString(t) }
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
*/
typedef char _check_for_GOINTBITS_bit_pointer_matching_GoInt[sizeof(void*)==GOINTBITS/8 ? 1:-1];
-typedef struct { char *p; GoInt n; } GoString;
+typedef struct { const char *p; GoInt n; } GoString;
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;