func (s *driverStmt) exec(params []driver.Value) *C.PGresult { stmtName := C.CString(s.name) defer C.free(unsafe.Pointer(stmtName)) cparams := buildCArgs(params) defer C.freeCharArray(cparams, C.int(len(params))) return C.PQexecPrepared(s.db, stmtName, C.int(len(params)), cparams, nil, nil, 0) }
func CreateProgram(context *Context, sources []string) *Program { runtime.LockOSThread() var program Program var error C.cl_int csources := C.makeCharArray(C.int(len(sources))) clenghts := make([]C.size_t, len(sources)) defer C.freeCharArray(csources, C.int(len(sources))) for i := 0; i < len(sources); i++ { C.setArrayString(csources, C.CString(sources[i]), C.int(i)) clenghts[i] = C.size_t(len(sources[i])) fmt.Printf("Program log:%d %s\n", clenghts[i], sources[i]) } program.item = C.clCreateProgramWithSource( context.item, C.cl_uint(len(sources)), csources, &clenghts[0], &error) fmt.Printf("Program error:%d\n", error) return &program }
func (s *Statement) exec(params ...interface{}) *C.PGresult { stmtName := C.CString(s.name) defer C.free(unsafe.Pointer(stmtName)) cparams := buildCArgs(params...) defer C.freeCharArray(cparams, C.int(len(params))) return C.PQexecPrepared(s.db, stmtName, C.int(len(params)), cparams, nil, nil, 0) }
func AcquirePlanes(planes []string, callback PlanesAvailable, ref interface{}) int { cAircrafts := C.makeCharArray(C.int(len(planes))) defer C.freeCharArray(cAircrafts, C.int(len(planes))) for i, s := range planes { C.setArrayString(cAircrafts, C.CString(s), C.int(i)) } reg:=®Info{callback,ref} return int(C.XPLMAcquirePlanes(cAircrafts,C.XPLMPlanesAvailable_f(unsafe.Pointer(C.planesAvailableCallback)),unsafe.Pointer(reg))) }
func (c *driverConn) exec(stmt string, args []driver.Value) (cres *C.PGresult) { stmtstr := C.CString(stmt) defer C.free(unsafe.Pointer(stmtstr)) if len(args) == 0 { cres = C.PQexec(c.db, stmtstr) } else { cargs := buildCArgs(args) defer C.freeCharArray(cargs, C.int(len(args))) cres = C.PQexecParams(c.db, stmtstr, C.int(len(args)), nil, cargs, nil, nil, 0) } return cres }
func (c *Conn) exec(stmt string, params ...interface{}) (cres *C.PGresult) { stmtstr := C.CString(stmt) defer C.free(unsafe.Pointer(stmtstr)) if len(params) == 0 { cres = C.PQexec(c.db, stmtstr) } else { cparams := buildCArgs(params...) defer C.freeCharArray(cparams, C.int(len(params))) cres = C.PQexecParams(c.db, stmtstr, C.int(len(params)), nil, cparams, nil, nil, 0) } return cres }
// Generic channel shuffling: copy src to dst, but with channels in the order specified by // ChannelOpts.Order[0..nchannels-1]. Does not support in-place operation. // // See ChannelOpts docs for more details on the options. func Channels(dst, src *ImageBuf, nchannels int, opts ...*ChannelOpts) error { var ( order *C.int32_t values *C.float newNames **C.char shuffle C.bool = C.bool(false) ) var opt *ChannelOpts if len(opts) > 0 { opt = opts[len(opts)-1] } if opt != nil { shuffle = C.bool(opt.ShuffleNames) if opt.Order != nil { if len(opt.Order) < nchannels { return fmt.Errorf("ChannelOpts.Order length %d is less than nchannels %d", len(opt.Order), nchannels) } order = (*C.int32_t)(unsafe.Pointer(&opt.Order[0])) } if opt.Values != nil { if len(opt.Values) < nchannels { return fmt.Errorf("ChannelOpts.Values length %d is less than nchannels %d", len(opt.Values), nchannels) } values = (*C.float)(unsafe.Pointer(&opt.Values[0])) } if opt.NewNames != nil { if len(opt.NewNames) < nchannels { return fmt.Errorf("ChannelOpts.NewNames length %d is less than nchannels %d", len(opt.NewNames), nchannels) } nameSize := len(opt.NewNames) newNames = C.makeCharArray(C.int(nameSize)) defer C.freeCharArray(newNames, C.int(nameSize)) for i, s := range opt.NewNames { C.setArrayString(newNames, C.CString(s), C.int(i)) } } } ok := C.channels(dst.ptr, src.ptr, C.int(nchannels), order, values, newNames, shuffle) if !bool(ok) { return dst.LastError() } return nil }
func MoveToTrash(filePath string) (string, error) { files := []string{filePath} C_files := C.makeCharArray(C.int(len(files))) defer C.freeCharArray(C_files, C.int(len(files))) for i, s := range files { C.setArrayString(C_files, C.CString(s), C.int(i)) } success := C.RecycleFiles(C_files, C.int(len(files)), C.int(0)) if success != 1 { return "", errors.New("file could not be recycled") } return "", nil }
func convertArgs(cArgs **C.char) []string { if cArgs == nil { return nil } var s []string // duplicate for p := uintptr(unsafe.Pointer(cArgs)); sptr(p) != nil; p += unsafe.Sizeof(uintptr(0)) { s = append(s, C.GoString(sptr(p))) } // free the original C.freeCharArray(cArgs, C.int(len(s))) return s }
func (node *Node) AddRemotes(addrs []string) (err error) { if len(addrs) == 0 { return fmt.Errorf("list of remotes is empty") } cargs := C.makeCharArray(C.int(len(addrs))) defer C.freeCharArray(cargs, C.int(len(addrs))) for i, s := range addrs { C.setArrayString(cargs, C.CString(s), C.int(i)) } err = nil c_err := C.node_add_remote_array(node.node, cargs, C.int(len(addrs))) if c_err < 0 { err = syscall.Errno(-c_err) } return }
func convertNArgs(cArgs **C.char, size int) []string { if cArgs == nil || size <= 0 { return nil } var s []string // duplicate p := uintptr(unsafe.Pointer(cArgs)) for i := 0; i < size; i++ { s = append(s, C.GoString(sptr(p))) p += unsafe.Sizeof(uintptr(0)) } // free the original C.freeCharArray(cArgs, C.int(size)) return s }
func convertNArgs(cArgs **C.char, size int) []string { if cArgs == nil || size <= 0 { return nil } var A []*C.char hdr := reflect.SliceHeader{ Data: uintptr(unsafe.Pointer(cArgs)), Len: size, Cap: size, } cArgsInterface := reflect.NewAt(reflect.TypeOf(A), unsafe.Pointer(&hdr)).Elem().Interface() result := make([]string, size) for i := 0; i < size; i++ { result[i] = C.GoString(cArgsInterface.([]*C.char)[i]) } C.freeCharArray(cArgs, C.size_t(size)) return result }
// Simple is the 'simple' interface. // If port is 0, the default remctl port is used // If principal is "", the default principal of "host/<hostname>" is used // // For more control of how the call is made, use the more 'complex' // interface. func Simple(host string, port uint16, principal string, command []string) (*RemctlResult, error) { var res *C.struct_remctl_result host_c := C.CString(host) defer C.free(unsafe.Pointer(host_c)) var principal_c *_Ctype_char if principal != "" { principal_c = C.CString(principal) defer C.free(unsafe.Pointer(principal_c)) } command_len := len(command) command_c := C.makeCharArray(C.int(command_len)) defer C.freeCharArray(command_c, C.int(command_len)) for i, s := range command { C.setArrayString(command_c, C.CString(s), C.int(i)) } res, err := C.remctl(host_c, C.ushort(port), principal_c, command_c) if res == nil { return nil, err } else { defer C.remctl_result_free((*C.struct_remctl_result)(unsafe.Pointer(res))) result := &RemctlResult{} stdout_len := (C.int)(res.stdout_len) stderr_len := (C.int)(res.stderr_len) result.Stdout = C.GoStringN(res.stdout_buf, stdout_len) result.Stderr = C.GoStringN(res.stderr_buf, stderr_len) result.Status = (int)(res.status) if res.error != nil { return nil, errors.New(C.GoString(res.error)) } return result, nil } }
func freeNullTerminatedArgs(cArgs **C.char, length int) { C.freeCharArray(cArgs, C.int(length+1)) }