]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/test: check API compatibility for cgo pseudo-functions
authorShenghou Ma <minux.ma@gmail.com>
Wed, 29 May 2013 18:59:57 +0000 (02:59 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Wed, 29 May 2013 18:59:57 +0000 (02:59 +0800)
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/9826043

misc/cgo/test/api.go [new file with mode: 0644]

diff --git a/misc/cgo/test/api.go b/misc/cgo/test/api.go
new file mode 100644 (file)
index 0000000..f5a8594
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2013 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// API Compatibility Checks for cgo
+
+package cgotest
+
+// #include <stdlib.h>
+// const char *api_hello = "hello!";
+import "C"
+import "unsafe"
+
+func testAPI() {
+       var cs *C.char
+       cs = C.CString("hello")
+       defer C.free(unsafe.Pointer(cs))
+       var s string
+       s = C.GoString((*C.char)(C.api_hello))
+       s = C.GoStringN((*C.char)(C.api_hello), C.int(6))
+       var b []byte
+       b = C.GoBytes(unsafe.Pointer(C.api_hello), C.int(6))
+       _, _ = s, b
+}