mirror of https://github.com/perkeep/perkeep.git
cgo test dir
Change-Id: Id4c17b85124c40b00e3c88b7d052c2158bfb79a5
This commit is contained in:
parent
a558c9ca57
commit
936d9e27c7
|
@ -0,0 +1,13 @@
|
|||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=camdev/ctest
|
||||
|
||||
CGOFILES=\
|
||||
callback.go\
|
||||
|
||||
CGO_OFILES=\
|
||||
callback_c.o\
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package ctest
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "cstuff.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import "unsafe"
|
||||
|
||||
//export GoFoo
|
||||
func GoFoo(c *C.char) {
|
||||
gstr := C.GoString(c)
|
||||
println("I AM GO", gstr)
|
||||
}
|
||||
|
||||
func CallC(s string) {
|
||||
cstr := C.CString(s)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
C.CFoo(cstr)
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
int CFoo(const char* c) {
|
||||
GoFoo(c);
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
extern void CFoo(const char* c);
|
|
@ -0,0 +1,6 @@
|
|||
package main
|
||||
|
||||
func main() {
|
||||
CallC()
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"camdev/ctest"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctest.CallC("foo")
|
||||
}
|
||||
|
Loading…
Reference in New Issue