Example #1
0
func interfaceToPyObj(o interface{}) *C.PyObject {
	switch o.(type) {
	case int:
		return C.PyInt_FromLong(C.long(o.(int)))
	case int64:
		return C.PyInt_FromLong(C.long(o.(int64)))
	case string:
		strvalue := C.CString(o.(string))
		defer C.free(unsafe.Pointer(strvalue))
		return C.PyString_FromStringAndSize(strvalue, C.Py_ssize_t(len(o.(string))))
	case map[interface{}]interface{}:
		dict := C.PyDict_New()
		for key, value := range o.(map[interface{}]interface{}) {
			dictAddItem(dict, key, value)
		}
		return dict
	case map[string]string:
		dict := C.PyDict_New()
		for key, value := range o.(map[string]string) {
			dictAddItem(dict, key, value)
		}
		return dict
	case map[string]interface{}:
		dict := C.PyDict_New()
		for key, value := range o.(map[string]interface{}) {
			dictAddItem(dict, key, value)
		}
		return dict
	default:
		return C.PyNone()
	}
}
Example #2
0
func RbString(str string) C.VALUE {
	if len(str) == 0 {
		return C.rb_utf8_str_new(nil, C.long(0))
	}
	cstr := (*C.char)(unsafe.Pointer(&(*(*[]byte)(unsafe.Pointer(&str)))[0]))
	return C.rb_utf8_str_new(cstr, C.long(len(str)))
}
func BeginDatastoreSegment(
	txnID int64,
	parentID int64,
	table string,
	operation string,
	sql string,
	rollupName string,
) int64 {
	ctable := C.CString(table)
	defer C.free(unsafe.Pointer(ctable))
	coperation := C.CString(operation)
	defer C.free(unsafe.Pointer(coperation))
	csql := C.CString(sql)
	defer C.free(unsafe.Pointer(csql))
	crollupName := C.CString(rollupName)
	defer C.free(unsafe.Pointer(crollupName))
	id := C.newrelic_segment_datastore_begin(
		C.long(txnID),
		C.long(parentID),
		ctable,
		coperation,
		csql,
		crollupName,
		(*[0]byte)(C.newrelic_basic_literal_replacement_obfuscator),
	)
	return int64(id)
}
Example #4
0
func (easy *Easy) SetOpt(opt EasyOption, param interface{}) error {
	switch {
	case opt >= C.CURLOPTTYPE_OFF_T:
		return easy.getError(C.my_esetoptl(easy.cptr, C.CURLoption(opt), C.long(param.(int))))
	case opt >= C.CURLOPTTYPE_FUNCTIONPOINT:
		return errors.New("function options not supported by SetOpt()")
	case opt >= C.CURLOPTTYPE_OBJECTPOINT:
		if isStringOption(opt) {
			c_param := C.CString(param.(string))
			defer C.free(unsafe.Pointer(c_param))
			return easy.getError(C.my_esetoptc(easy.cptr, C.CURLoption(opt), c_param))
		} else {
			return fmt.Errorf("option %d not supported", opt)
		}
	case opt >= C.CURLOPTTYPE_LONG:
		var val C.long
		switch t := param.(type) {
		case bool:
			if t {
				val = C.long(1)
			}
		case int:
			val = C.long(t)
		case int32:
			val = C.long(t)
		case int64:
			val = C.long(t)
		default:
			panic("CURLOPTTYPE_LONG param must be of golang type bool, int, int32, or int64")
		}
		return easy.getError(C.my_esetoptl(easy.cptr, C.CURLoption(opt), val))
	}
	return nil
}
Example #5
0
func (mcurl *CURLM) Setopt(opt int, param interface{}) error {
	p := mcurl.handle
	if param == nil {
		return newCurlMultiError(C.curl_multi_setopt_pointer(p, C.CURLMoption(opt), nil))
	}
	switch {
	//  currently cannot support these option
	//	case MOPT_SOCKETFUNCTION, MOPT_SOCKETDATA, MOPT_TIMERFUNCTION, MOPT_TIMERDATA:
	//		panic("not supported CURLM.Setopt opt")
	case opt >= C.CURLOPTTYPE_LONG:
		val := C.long(0)
		switch t := param.(type) {
		case int:
			val := C.long(t)
			return newCurlMultiError(C.curl_multi_setopt_long(p, C.CURLMoption(opt), val))
		case bool:
			val = C.long(0)
			if t {
				val = C.long(1)
			}
			return newCurlMultiError(C.curl_multi_setopt_long(p, C.CURLMoption(opt), val))
		}
	}
	panic("not supported CURLM.Setopt opt or param")
	return nil
}
Example #6
0
func (t *textEntry) SetSelection(from int, to int) {
	p := C.WxTextEntryPtr(pointer(t))
	if p == nil {
		return
	}
	C.wxTextEntry_SetSelection(p, C.long(from), C.long(to))
}
Example #7
0
// NewNode returns new Node with a given Logger.
func NewNodeConfig(logfile string, level string, cfg *NodeConfig) (node *Node, err error) {
	clevel := C.CString(level)
	defer C.free(unsafe.Pointer(clevel))

	clogfile := C.CString(logfile)
	defer C.free(unsafe.Pointer(clogfile))

	var dcfg C.struct_dnet_config
	C.memset(unsafe.Pointer(&dcfg), 0, C.sizeof_struct_dnet_config)

	dcfg.io_thread_num = C.int(cfg.IOThreadNum)
	dcfg.nonblocking_io_thread_num = C.int(cfg.NonBlockingIOThreadNum)
	dcfg.net_thread_num = C.int(cfg.NetThreadNum)
	dcfg.wait_timeout = C.long(cfg.WaitTimeout)
	dcfg.check_timeout = C.long(cfg.CheckTimeout)
	dcfg.flags = C.int(cfg.Flags)
	dcfg.stall_count = C.long(cfg.StallCount)

	cnode := C.new_node_config(clogfile, clevel, &dcfg)
	if cnode == nil {
		err = fmt.Errorf("could not create node, please check stderr output")
		return
	}
	node = &Node{cnode}
	return
}
Example #8
0
func (t *textEntry) Replace(from int, to int, value string) {
	p := C.WxTextEntryPtr(pointer(t))
	if p == nil {
		return
	}
	C.wxTextEntry_Replace(p, C.long(from), C.long(to), cString(&value))
}
Example #9
0
func (t *textEntry) Remove(from int, to int) {
	p := C.WxTextEntryPtr(pointer(t))
	if p == nil {
		return
	}
	C.wxTextEntry_Remove(p, C.long(from), C.long(to))
}
Example #10
0
func (t *textEntry) Range(from int, to int) string {
	p := C.WxTextEntryPtr(pointer(t))
	if p == nil {
		return ""
	}
	return goString(C.wxTextEntry_GetRange(p, C.long(from), C.long(to)))
}
Example #11
0
// Extracts a region from the canvas.
func (cv Canvas) Crop(x int, y int, width uint, height uint) bool {
	status := C.MagickCropImage(cv.wand, C.ulong(width), C.ulong(height), C.long(x), C.long(y))
	if status == C.MagickFalse {
		return false
	}
	return true
}
Example #12
0
func RbBytes(bytes []byte) C.VALUE {
	if len(bytes) == 0 {
		return C.rb_str_new(nil, C.long(0))
	}
	cstr := (*C.char)(unsafe.Pointer(&bytes[0]))
	return C.rb_str_new(cstr, C.long(len(bytes)))
}
func BeginExternalSegment(txnID int64, parentID int64, host string, name string) int64 {
	chost := C.CString(host)
	defer C.free(unsafe.Pointer(chost))
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))
	id := C.newrelic_segment_external_begin(C.long(txnID), C.long(parentID), chost, cname)
	return int64(id)
}
Example #14
0
func transform(srcpj, dstpj *Proj, x, y, z []float64) ([]float64, []float64, []float64, error) {
	if !(srcpj.opened && dstpj.opened) {
		return []float64{}, []float64{}, []float64{}, errors.New("projection is closed")
	}

	var x1, y1, z1 []C.double

	ln := len(x)
	if len(y) < ln {
		ln = len(y)
	}
	if z != nil && len(z) < ln {
		ln = len(z)
	}

	if ln == 0 {
		return []float64{}, []float64{}, []float64{}, nil
	}

	x1 = make([]C.double, ln)
	y1 = make([]C.double, ln)
	if z != nil {
		z1 = make([]C.double, ln)
	}
	for i := 0; i < ln; i++ {
		x1[i] = C.double(x[i])
		y1[i] = C.double(y[i])
		if z != nil {
			z1[i] = C.double(z[i])
		}
	}

	var e *C.char
	if z != nil {
		e = C.transform(srcpj.pj, dstpj.pj, C.long(ln), &x1[0], &y1[0], &z1[0])
	} else {
		e = C.transform(srcpj.pj, dstpj.pj, C.long(ln), &x1[0], &y1[0], nil)
	}

	if e != nil {
		return []float64{}, []float64{}, []float64{}, errors.New(C.GoString(e))
	}

	var x2, y2, z2 []float64
	x2 = make([]float64, ln)
	y2 = make([]float64, ln)
	if z != nil {
		z2 = make([]float64, ln)
	}
	for i := 0; i < ln; i++ {
		x2[i] = float64(x1[i])
		y2[i] = float64(y1[i])
		if z != nil {
			z2[i] = float64(z1[i])
		}
	}
	return x2, y2, z2, nil
}
Example #15
0
func (p *VideoInput) SetVideoSettingCameraPct(deviceID int,
	Property int32, pctValue float32, Flags int32,
) bool {
	rv := C.vi_device_setVideoSettingCameraPct(p.vi,
		C.int(deviceID),
		C.long(Property), C.float(pctValue), C.long(Flags),
	)
	return rv != 0
}
Example #16
0
/*
 * Identify the beginning of a segment that performs an external service.
 *
 * @param transaction_id  id of transaction
 * @param parent_segment_id  id of parent segment
 * @param host  name of the host of the external call
 * @param name  name of the external transaction
 * @return  segment id on success, else negative warning code or error code
 */
func SegmentExternalBegin(id, parent int64, host, name string) (int64, error) {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	chost := C.CString(host)
	defer C.free(unsafe.Pointer(chost))

	return errNoLong(C.newrelic_segment_external_begin(C.long(id), C.long(parent), chost, cname))
}
Example #17
0
File: osr.go Project: sn-amber/gdal
// Import coordinate system from USGS projection definition
func (sr SpatialReference) FromUSGS(projsys, zone int, params []float64, datum int) error {
	return C.OSRImportFromUSGS(
		sr.cval,
		C.long(projsys),
		C.long(zone),
		(*C.double)(unsafe.Pointer(&params[0])),
		C.long(datum),
	).Err()
}
Example #18
0
// Extracts a region from the canvas.
func (self Canvas) Crop(x int, y int, width uint, height uint) error {
	success := C.MagickCropImage(self.wand, C.ulong(width), C.ulong(height), C.long(x), C.long(y))

	if success == C.MagickFalse {
		return fmt.Errorf("Could not crop: %s", self.Error())
	}

	return nil
}
Example #19
0
func (im *Image) setPixels(r *Rect, src *C.PixelPacket, ex *C.ExceptionInfo) bool {
	dst := C.SetImagePixelsEx(im.image, C.long(r.X), C.long(r.Y), C.ulong(r.Width), C.ulong(r.Height), ex)
	if dst == nil {
		return false
	}
	C.copy_pixel_packets(src, dst, C.int(r.Width*r.Height))
	if C.SyncImagePixelsEx(im.image, ex) != C.MagickPass {
		return false
	}
	return true
}
Example #20
0
func (p *VideoInput) SetVideoSettingCamera(deviceID int,
	Property, lValue, Flags int32,
	useDefaultValue bool,
) bool {
	rv := C.vi_device_setVideoSettingCamera(p.vi,
		C.int(deviceID),
		C.long(Property), C.long(lValue), C.long(Flags),
		viToBoolT(useDefaultValue),
	)
	return rv != 0
}
Example #21
0
func (p poller) timespec(d time.Duration) *C.struct_timespec {
	if d < 0 {
		// a NULL timespec tells kqueue to wait forever
		return nil
	}
	t := syscall.NsecToTimespec(d.Nanoseconds())
	// darwin defines tv_sec as __darwin_time_t, so we
	// need to to some indirection to let C do the implicit
	// type conversion.
	ts := C.make_timespec(C.long(t.Sec), C.long(t.Nsec))
	return &ts
}
Example #22
0
File: osr.go Project: kikht/gdal
// Import coordinate system from USGS projection definition
func (sr SpatialReference) FromUSGS(projsys, zone int, params []float64, datum int) error {
	err := C.OSRImportFromUSGS(
		sr.cval,
		C.long(projsys),
		C.long(zone),
		(*C.double)(unsafe.Pointer(&params[0])),
		C.long(datum))
	if err != 0 {
		return error(err)
	}

	return nil
}
Example #23
0
//export sourceSkip
func sourceSkip(dinfo *C.struct_jpeg_decompress_struct, bytes C.long) {
	mgr := getSourceManager(dinfo)
	if bytes > 0 {
		for bytes >= C.long(mgr.pub.bytes_in_buffer) {
			bytes -= C.long(mgr.pub.bytes_in_buffer)
			sourceFill(dinfo)
		}
	}
	mgr.pub.bytes_in_buffer -= C.size_t(bytes)
	if mgr.pub.bytes_in_buffer != 0 {
		mgr.pub.next_input_byte = (*C.JOCTET)(&mgr.buffer[mgr.currentSize-int(mgr.pub.bytes_in_buffer)])
	}
}
Example #24
0
func (w *win) showCursor(r *nrefs, show bool) {
	tf1 := 0
	if show {
		tf1 = 1
	}
	C.gs_show_cursor(C.long(r.display), C.uchar(tf1))
}
Example #25
0
File: event.go Project: nzlov/wxgo
func (e *event) SetTimestamp(timestamp int64) {
	p := ptr(e)
	if p == nil {
		return
	}
	C.wxEvent_SetTimestamp(p, C.long(timestamp))
}
Example #26
0
func saveFunc(f interface{}) *C.PyObject {
	funcLock.Lock()
	defer funcLock.Unlock()

	funcs = append(funcs, f)
	return C.PyInt_FromLong(C.long(len(funcs) - 1))
}
Example #27
0
func (p *Poller) poll(timeout time.Duration, all bool) ([]Polled, error) {
	lst := make([]Polled, 0, len(p.items))

	for _, soc := range p.socks {
		if !soc.opened {
			return lst, ErrorSocketClosed
		}
	}

	t := timeout
	if t > 0 {
		t = t / time.Millisecond
	}
	if t < 0 {
		t = -1
	}
	rv, err := C.zmq_poll(&p.items[0], C.int(len(p.items)), C.long(t))
	if rv < 0 {
		return lst, errget(err)
	}
	for i, it := range p.items {
		if all || it.events&it.revents != 0 {
			lst = append(lst, Polled{p.socks[i], State(it.revents)})
		}
	}
	return lst, nil
}
Example #28
0
File: sizer.go Project: nzlov/wxgo
func (s *sizer) Show(index int, show bool) bool {
	p := s.ptr()
	if p == nil {
		return false
	}
	return goBool(C.wxSizer_Show(p, C.long(index), cBool(show)))
}
Example #29
0
func StrSlice2RbArray(slice []string) C.VALUE {
	ary := C.rb_ary_new_capa(C.long(len(slice)))
	for _, val := range slice {
		C.rb_ary_push(ary, RbString(val))
	}
	return ary
}
Example #30
0
// Blocks the the programm until the given jobs left the system or
// a specific timeout is reached.
func (s *Session) Synchronize(jobIds []string, timeout int64, dispose bool) *Error {
	// TODO handle special string: DRMAA_ID_SESSION_ALL
	diag := C.makeString(stringSize)
	defer C.free(unsafe.Pointer(diag))

	job_ids := C.makeStringArray(C.int(len(jobIds) + 1))

	for i, jobid := range jobIds {
		C.setString(job_ids, C.CString(jobid), C.int(i))
	}
	C.setString(job_ids, nil, C.int(len(jobIds)))

	var disp C.int
	if dispose {
		disp = C.int(1)
	} else {
		disp = C.int(0)
	}

	if errNumber := C.drmaa_synchronize(job_ids, C.long(timeout), disp,
		diag, stringSize); errNumber != C.DRMAA_ERRNO_SUCCESS {
		ce := makeError(C.GoString(diag), errorId[errNumber])
		return &ce
	}

	return nil
}