github.com/MangoDowner/go-gm@v0.0.0-20180818020936-8baa2bd4408c/misc/cgo/test/api.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // API Compatibility Checks for cgo
     6  
     7  package cgotest
     8  
     9  // #include <stdlib.h>
    10  //
    11  // // Test for issue 17723.
    12  // typedef char *cstring_pointer;
    13  // static void cstring_pointer_fun(cstring_pointer dummy) { }
    14  //
    15  // const char *api_hello = "hello!";
    16  import "C"
    17  import "unsafe"
    18  
    19  func testAPI() {
    20  	var cs *C.char
    21  	cs = C.CString("hello")
    22  	defer C.free(unsafe.Pointer(cs))
    23  	var s string
    24  	s = C.GoString((*C.char)(C.api_hello))
    25  	s = C.GoStringN((*C.char)(C.api_hello), C.int(6))
    26  	var b []byte
    27  	b = C.GoBytes(unsafe.Pointer(C.api_hello), C.int(6))
    28  	_, _ = s, b
    29  	C.cstring_pointer_fun(nil)
    30  }