Ejemplo n.º 1
0
func benchCgoCall(b *testing.B) {
	const x = C.int(2)
	const y = C.int(3)
	for i := 0; i < b.N; i++ {
		C.add(x, y)
	}
}
Ejemplo n.º 2
0
// For all pixels and channels within the designated region, set dst to the sum of image A
// and image B. All of the images must have the same number of channels.
func Add(dst, a, b *ImageBuf, opts ...AlgoOpts) error {
	opt := flatAlgoOpts(opts)

	ok := C.add(dst.ptr, a.ptr, b.ptr, opt.ROI.validOrAllPtr(), C.int(opt.Threads))
	if !bool(ok) {
		return dst.LastError()
	}

	return nil
}
Ejemplo n.º 3
0
func main() {

	C.sayhello()
	i := 100
	ip := unsafe.Pointer(&i)
	C.add((*C.int)(ip))
	fmt.Println(i)
	C.say((*C.int)(ip))
	fmt.Println(i)
}
Ejemplo n.º 4
0
func main() {
	total := C.add(10, 20)
	fmt.Printf("Go says: result is %v\n", total)

	gostr := "Go can call C's puts from stdio"
	// C.CString uses C heap, we must free it
	var cstr *C.char = C.CString(gostr)
	// defer is convenient for clean-up
	defer C.free(unsafe.Pointer(cstr))
	C.puts(cstr)
}
Ejemplo n.º 5
0
func main() {
	fmt.Printf("Go says: calling C callback add..\n")

	// With cgo you can't call C function pointers directly,
	// but you can pass then to C functions that can call them
	C.add(40, 2, C.callback_fn(C.c_to_go_callback))
	fmt.Printf("Go says: 1st result is %d\n\n", total)

	fmt.Printf("Go says: calling add with Go callback..\n")
	C.add_with_go_callback(100, 1)
	fmt.Printf("Go says: 2nd result is %d\n", total)
}
Ejemplo n.º 6
0
// Add adds new credentials to the keychain.
func (h Secretservice) Add(creds *credentials.Credentials) error {
	if creds == nil {
		return errors.New("missing credentials")
	}
	server := C.CString(creds.ServerURL)
	defer C.free(unsafe.Pointer(server))
	username := C.CString(creds.Username)
	defer C.free(unsafe.Pointer(username))
	secret := C.CString(creds.Secret)
	defer C.free(unsafe.Pointer(secret))

	if err := C.add(server, username, secret); err != nil {
		defer C.g_error_free(err)
		errMsg := (*C.char)(unsafe.Pointer(err.message))
		return errors.New(C.GoString(errMsg))
	}
	return nil
}
Ejemplo n.º 7
0
func main() {
	fmt.Println("helloworld")
	db, err := sql.Open("mysql", "test:123456@tcp(www.teelet.com:3306)/test?charset=utf8")
	defer db.Close()
	checkErr(err)
	err = db.Ping()
	checkErr(err)
	stmt, err := db.Prepare("select * from test limit 10")
	checkErr(err)
	rows, err := stmt.Query()
	checkErr(err)
	for rows.Next() {
		i := new(item)
		rows.Scan(&(i.id), &(i.name))
		fmt.Println(strconv.Itoa(i.id) + " : " + i.name)
	}

	//测试动态链接库
	sum := C.add(1, 2)
	fmt.Printf("sum = %d \n", sum)
}
Ejemplo n.º 8
0
Archivo: cgoonly.go Proyecto: tajoy/gb
func Add(x, y int) int {
	return int(C.add(_Ctype_int(x), _Ctype_int(y)))
}
Ejemplo n.º 9
0
/**
 * Wraps up our C add function
 */
func GoAdd(a int, b int) int {
	return int(C.add(C.int(a), C.int(b)))
}