From a307c5c9b700f80b396e5cc6b4b8cfb74d96c770 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Thu, 30 May 2013 02:59:57 +0800 Subject: [PATCH] misc/cgo/test: check API compatibility for cgo pseudo-functions R=golang-dev, iant CC=golang-dev https://golang.org/cl/9826043 --- misc/cgo/test/api.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 misc/cgo/test/api.go diff --git a/misc/cgo/test/api.go b/misc/cgo/test/api.go new file mode 100644 index 0000000000..f5a85946fb --- /dev/null +++ b/misc/cgo/test/api.go @@ -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 +// 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 +} -- 2.48.1