Example #1
0
func getOffsetByUSec(zone string, timestamp int64) int32 {
	czone := C.CString(zone)
	defer C.free(unsafe.Pointer(czone))
	offset := C.get_offset_by_usec(czone, C.longlong(timestamp))

	return int32(offset)
}
Example #2
0
func main() {
	xs := make([]int64, 4096)
	for i := 0; i < len(xs); i++ {
		xs[i] = int64(rand.Int())
	}
	fmt.Println(C.sum((*C.longlong)(unsafe.Pointer(&xs[0])), C.longlong(len(xs))))
}
Example #3
0
func getRawUSec(zone string, timestamp int64) int64 {
	czone := C.CString(zone)
	defer C.free(unsafe.Pointer(czone))
	ret := C.get_rawoffset_usec(czone, C.longlong(timestamp))

	return int64(ret)
}
Example #4
0
func (ptr *QWebSocket) BytesWritten(bytes int64) {
	defer qt.Recovering("QWebSocket::bytesWritten")

	if ptr.Pointer() != nil {
		C.QWebSocket_BytesWritten(ptr.Pointer(), C.longlong(bytes))
	}
}
Example #5
0
func (ptr *QWebSocket) SetReadBufferSize(size int64) {
	defer qt.Recovering("QWebSocket::setReadBufferSize")

	if ptr.Pointer() != nil {
		C.QWebSocket_SetReadBufferSize(ptr.Pointer(), C.longlong(size))
	}
}
Example #6
0
func ReadAt(fd int, off int64, size int) ([]byte, error) {
	idx := <-idle_event
	retch := aio_result_map[idx]
	defer func() { idle_event <- idx }()

	var cb *C.struct_iocb = &cbs[idx]

	var read_buf unsafe.Pointer
	C.posix_memalign(&read_buf, pagesize, C.size_t(size))
	defer C.free(read_buf)

	C.io_prep_pread(cb, C.int(fd), read_buf, C.size_t(size), C.longlong(off))
	cbs[idx].data = unsafe.Pointer(&idx)

	aio_lock.Lock()
	rt := C.io_submit(ctx, 1, &cb)
	if int(rt) < 0 {
		aio_lock.Unlock()
		return nil, errors.New("io submit failed")
	}
	aiocount++
	aio_lock.Unlock()

	select {
	case have_aio_event <- 0:
	default:
	}

	ret := <-retch

	return ret.buf, ret.err
}
Example #7
0
File: lgo.go Project: reusee/lgo
func (lua *Lua) PushGoValue(value reflect.Value) {
	switch t := value.Type(); t.Kind() {
	case reflect.Bool:
		if value.Bool() {
			C.lua_pushboolean(lua.State, C.int(1))
		} else {
			C.lua_pushboolean(lua.State, C.int(0))
		}
	case reflect.String:
		C.lua_pushstring(lua.State, C.CString(value.String()))
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		C.lua_pushnumber(lua.State, C.lua_Number(C.longlong(value.Int())))
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		C.lua_pushnumber(lua.State, C.lua_Number(C.ulonglong(value.Uint())))
	case reflect.Float32, reflect.Float64:
		C.lua_pushnumber(lua.State, C.lua_Number(C.double(value.Float())))
	case reflect.Slice:
		length := value.Len()
		C.lua_createtable(lua.State, C.int(length), 0)
		for i := 0; i < length; i++ {
			C.lua_pushnumber(lua.State, C.lua_Number(i+1))
			lua.PushGoValue(value.Index(i))
			C.lua_settable(lua.State, -3)
		}
	case reflect.Interface:
		lua.PushGoValue(value.Elem())
	case reflect.Ptr, reflect.UnsafePointer:
		C.lua_pushlightuserdata(lua.State, unsafe.Pointer(value.Pointer()))
	default:
		lua.Panic("wrong return value %v %v", value, t.Kind())
	}
}
Example #8
0
// SetNum sets a number in the specified field of the engine configuration.
// Certain fields accept only 32-bit numbers, silently truncating the higher bits
// of the engine config. See dat.go for more information.
func (e *Engine) SetNum(field EngineField, num uint64) error {
	err := C.cl_engine_set_num((*C.struct_cl_engine)(e), C.enum_cl_engine_field(field), C.longlong(num))
	if ErrorCode(err) != Success {
		return fmt.Errorf("%v", StrError(ErrorCode(err)))
	}
	return nil
}
func cTraceRays(computator CComputationManager, startIndex, endIndex int64) [][]float32 {
	indicesSize := endIndex - startIndex + 1

	results := make([][]float32, indicesSize)
	refResults := make([]*float32, indicesSize)

	for i := range results {
		data := make([]float32, 3)
		results[i] = data
		refResults[i] = (*float32)(unsafe.Pointer(&data[0]))
	}

	resultsPtr := (**C.float)(unsafe.Pointer((&refResults[0])))
	C.traceRays(computator.p, C.longlong(startIndex), C.longlong(endIndex), resultsPtr)

	return results
}
Example #10
0
/// Returns the predicted head pose in outHmdTrackingState and offset eye poses in outEyePoses.
///
/// This is a thread-safe function where caller should increment frameIndex with every frame
/// and pass that index where applicable to functions called on the rendering thread.
/// Assuming outEyePoses are used for rendering, it should be passed as a part of ovrLayerEyeFov.
/// The caller does not need to worry about applying HmdToEyeOffset to the returned outEyePoses variables.
///
/// \param[in]  hmd Specifies an ovrSession previously returned by ovr_Create.
/// \param[in]  frameIndex Specifies the targeted frame index, or 0 to refer to one frame after
///             the last time ovr_SubmitFrame was called.
/// \param[in]  HmdToEyeOffset Can be ovrEyeRenderDesc.HmdToEyeOffset returned from
///             ovr_GetRenderDesc. For monoscopic rendering, use a vector that is the average
///             of the two vectors for both eyes.
/// \param[in]  latencyMarker Specifies that this call is the point in time where
///             the "App-to-Mid-Photon" latency timer starts from. If a given ovrLayer
///             provides "SensorSampleTimestamp", that will override the value stored here.
/// \param[out] outEyePoses The predicted eye poses.
/// \param[out] outSensorSampleTime The time when this function was called. May be NULL, in which case it is ignored.
func (s *Session) GetEyePoses(frameIndex uint64, latencyMarker bool, hmdToEyeOffset [2]Vector3f) ([2]Posef, float64) {
	var cHmdToEyeViewOffset [2]C.ovrVector3f
	cHmdToEyeViewOffset[0] = cVector3f(hmdToEyeOffset[0])
	cHmdToEyeViewOffset[1] = cVector3f(hmdToEyeOffset[1])
	var cEyePoses [2]C.ovrPosef
	var cSensorSampleTime C.double
	C.ovr_GetEyePoses(s.cSession, C.longlong(frameIndex), ovrBool(latencyMarker), &cHmdToEyeViewOffset[0], &cEyePoses[0], &cSensorSampleTime)
	return [2]Posef{goPosef(cEyePoses[0]), goPosef(cEyePoses[1])}, float64(cSensorSampleTime)
}
Example #11
0
File: stream.go Project: nzlov/wxgo
//export x_GoReader_Seek
func x_GoReader_Seek(pGoReader C.GoReaderPtr, offset int64, whence int) C.longlong {
	reader := (*(*io.Reader)(pGoReader))
	seeker := reader.(io.Seeker)
	n, err := seeker.Seek(offset, whence)
	if err != nil {
		return -1
	}
	return C.longlong(n)
}
Example #12
0
func (t *TypedParameters) TypedParamsAddInt64(val int64, name string) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	result := C.virTypedParamsAddLLong(&t.cptr, &t.length, &t.capacity, cname, C.longlong(val))
	if result == -1 {
		return GetLastError()
	}
	return nil
}
Example #13
0
func (sch *aioScheduler) Read(fd int, buf []byte, off uint64) (int, error) {
	iocb := &C.iocb_t{}
	sh := *(*reflect.SliceHeader)(unsafe.Pointer(&buf))
	C.io_prep_pread(iocb, C.int(fd), unsafe.Pointer(sh.Data), C.size_t(sh.Len), C.longlong(off))
	ev, err := sch.submit(iocb)
	if err != nil {
		return 0, err
	}

	return int(ev.wait()), nil
}
Example #14
0
func unpack_kv(pack *C.struct___0, v reflect.Value) *McpackError {
	vt := v.Type()

	for i := 0; i < v.NumField(); i++ {
		vtf := vt.Field(i)
		vf := v.Field(i)

		realName := vtf.Tag.Get("mcpack")
		if realName == "" {
			realName = vtf.Name
		}

		switch vf.Kind() {
		case reflect.Struct:
			subpack := C.mc_pack_get_object(pack, C.CString(realName))
			if err := unpack_kv(subpack, vf); err != nil {
				return err
			}
		case reflect.Interface:
			subpack := C.mc_pack_get_object(pack, C.CString(realName))
			evf := vf.Elem().Elem()
			if err := unpack_kv(subpack, evf); err != nil {
				return err
			}
		case reflect.String:
			value_c := C.mc_pack_get_str(pack, C.CString(realName))
			vf.SetString(C.GoString(value_c))
		case reflect.Int, reflect.Int32:
			value_i := C.int(0)
			C.go_mc_pack_get_int32(pack, C.CString(realName), &value_i)
			vf.SetInt(int64(value_i))
		case reflect.Int64:
			value_i := C.longlong(0)
			C.go_mc_pack_get_int64(pack, C.CString(realName), &value_i)
			vf.SetInt(int64(value_i))
		case reflect.Slice, reflect.Array:
			if vf.Type().Elem().Kind() != reflect.Uint8 {
				return &McpackError{"unspport slice type"}
			}
			value_len := C.int(0)
			value_r := C.go_mc_pack_get_raw(pack, C.CString(realName), &value_len)
			vf.SetBytes(C.GoBytes(unsafe.Pointer(value_r), value_len))

		default:
			return &McpackError{"unsupport type: " + v.Kind().String()}
		}
	}

	return nil
}
Example #15
0
// SendProcessSignal sends a signal to the designated process in the guest.
func (dom Domain) SendProcessSignal(pid int64, signal DomainProcessSignal) error {
	dom.log.Printf("sending signal %v to domain's process %v...\n", signal, pid)
	cRet := C.virDomainSendProcessSignal(dom.virDomain, C.longlong(pid), C.uint(signal), 0)
	ret := int32(cRet)

	if ret == -1 {
		err := LastError()
		dom.log.Printf("an error occurred: %v\n", err)
		return err
	}

	dom.log.Println("signal sent")

	return nil
}
Example #16
0
// Initialize GoTypes in NumTypeMap
func initTypeMap() {
	cgoNumMap["C.char"] = GetNumInfo(C.char(0))
	cgoNumMap["C.schar"] = GetNumInfo(C.schar(0))
	cgoNumMap["C.uchar"] = GetNumInfo(C.uchar(0))
	cgoNumMap["C.short"] = GetNumInfo(C.short(0))
	cgoNumMap["C.ushort"] = GetNumInfo(C.ushort(0))
	cgoNumMap["C.wchar_t"] = GetNumInfo(C.wchar_t(0))
	cgoNumMap["C.int"] = GetNumInfo(C.int(0))
	cgoNumMap["C.uint"] = GetNumInfo(C.uint(0))
	cgoNumMap["C.long"] = GetNumInfo(C.long(0))
	cgoNumMap["C.ulong"] = GetNumInfo(C.ulong(0))
	cgoNumMap["C.longlong"] = GetNumInfo(C.longlong(0))
	cgoNumMap["C.ulonglong"] = GetNumInfo(C.ulonglong(0))
	cgoNumMap["C.float"] = GetNumInfo(C.float(0))
	cgoNumMap["C.double"] = GetNumInfo(C.double(0))
	cgoNumMap["complex64"] = GetNumInfo(complex64(0))
	cgoNumMap["complex128"] = GetNumInfo(complex128(0))
}
Example #17
0
func main() {
	loop := C.aeCreateEventLoop(C.int(1024))

	c := make(chan bool)
	n := 1000

	callback := func() {
		fmt.Printf("foo\n")
		c <- true
	}
	for i := 0; i < n; i++ {
		C.create_time_event(loop, C.longlong(i), unsafe.Pointer(&callback))
	}

	go C.aeMain(loop)
	for i := 0; i < n; i++ {
		<-c
	}
}
Example #18
0
func pack_kv(pack *C.struct___0, key string, v reflect.Value) *McpackError {
	switch v.Kind() {
	case reflect.Int32, reflect.Int:
		C.go_mc_pack_put_int32(pack, C.CString(key), C.int(v.Int()))
	case reflect.Int64:
		C.go_mc_pack_put_int64(pack, C.CString(key), C.longlong(v.Int()))
	case reflect.String:
		C.mc_pack_put_str(pack, C.CString(key), C.CString(v.String()))
	case reflect.Struct:
		subpack := C.mc_pack_put_object(pack, C.CString(key))
		if err := marshal(subpack, v); err != nil {
			return err
		}
		C.mc_pack_finish(subpack)
	default:
		return &McpackError{"unknown type: " + v.Kind().String()}
	}
	return nil
}
Example #19
0
func (k *Keydir) Add(key string, Fid, Vsz, Vpos int32, Tstamp int64) error {
	k.Lock()
	defer k.Unlock()

	c_key := C.CString(key)
	defer C.free(unsafe.Pointer(c_key))
	sliceKey := C.slice_new(c_key, C.int((len(key))))

	var item C.Item
	item.fid = C.int(Fid)
	item.vsz = C.int(Vsz)
	item.vpos = C.int(Vpos)
	item.tstamp = C.longlong(Tstamp)

	ok := C.dict_add(k.dict, sliceKey, item)
	if ok != C.DICT_OK {
		return fmt.Errorf("failed to add Key %s", key)
	}
	return nil
}
Example #20
0
func (closure *Closure) NewFunction(name string, nin int, doc string) *Base {

	d := &closure.methodDef
	d.ml_name = C.CString(name)
	defer C.free(unsafe.Pointer(d.ml_name))

	if C.setMethod(d, C.int(nin)) != 0 {
		panic("Invalid arguments: nin")
	}
	if doc != "" {
		d.ml_doc = C.CString(doc)
		defer C.free(unsafe.Pointer(d.ml_doc))
	}

	ctx := uintptr(unsafe.Pointer(closure))
	self := C.PyLong_FromLongLong(C.longlong(ctx))
	defer C.decref(self)

	f := C.PyCFunction_NewEx(d, self, nil)
	return (*Base)(unsafe.Pointer(f))
}
Example #21
0
func WriteAt(fd int, off int64, buf []byte) (int, error) {
	size := len(buf)
	if size == 0 {
		return 0, nil
	}

	idx := <-idle_event
	retch := aio_result_map[idx]
	defer func() { idle_event <- idx }()

	var cb *C.struct_iocb = &cbs[idx]

	var write_buf unsafe.Pointer
	C.posix_memalign(&write_buf, pagesize, C.size_t(size))
	defer C.free(write_buf)
	for i := 0; i < size; i++ {
		*(*byte)(unsafe.Pointer(uintptr(write_buf) + uintptr(i))) = buf[i]
	}

	C.io_prep_pwrite(cb, C.int(fd), write_buf, C.size_t(size), C.longlong(off))
	cbs[idx].data = unsafe.Pointer(&idx)

	aio_lock.Lock()
	rt := C.io_submit(ctx, 1, &cb)

	if int(rt) < 0 {
		aio_lock.Unlock()
		return 0, errors.New("io submit failed")
	}
	aiocount++
	aio_lock.Unlock()

	select {
	case have_aio_event <- 0:
	default:
	}

	ret := <-retch
	return ret.size, ret.err
}
Example #22
0
func Blob_read(con_handle int, blob GCI_BLOB, start_pos int64, length int64) (GCI_BLOB, GCI_ERROR) {
	var handle C.int = C.int(con_handle)
	var res C.int
	var c_start_pos C.longlong = C.longlong(start_pos)
	var c_length C.int = C.int(length)
	var c_blob string
	var cci_error C.T_CCI_ERROR
	var err GCI_ERROR
	var data C.T_CCI_BLOB = C.T_CCI_BLOB(blob)
	var res_blob GCI_BLOB

	c_buf := C.CString(c_blob)
	defer C.free(unsafe.Pointer(c_buf))
	res = C.cci_blob_read(handle, data, c_start_pos, c_length, c_buf, &cci_error)
	if res < C.int(0) {
		err.Code = int(cci_error.err_code)
		err.Msg = C.GoString(&cci_error.err_msg[0])
	}

	res_blob = GCI_BLOB(c_buf)

	return res_blob, err
}
Example #23
0
func INT64toNUM(n int64) C.VALUE {
	return C.rb_ll2inum(C.longlong(n))
}
Example #24
0
func (self *sqlStatement) sqlBindInt64(slot int, value int64) int {
	return int(C.wsq_bind_int64(self.handle, C.int(slot+1), C.longlong(value)))
}
Example #25
0
func NewVariantInt64(n int64) Variant {
	v := &variant{}
	v.bindWxPtr(C.wxVariant_NewInt64(C.longlong(n)), true)
	return v
}
Example #26
0
func (r *Redis) ReplyWithLongLong(l int64) error {
	if rc := C.rm_replyWithLongLong(r.ctx, C.longlong(l)); rc != C.REDISMODULE_OK {
		return ErrModule
	}
	return nil
}
Example #27
0
func (stmt *Statement) BindParam(index int, param interface{}) *ODBCError {
	var ValueType C.SQLSMALLINT
	var ParameterType C.SQLSMALLINT
	var ColumnSize C.SQLULEN
	var DecimalDigits C.SQLSMALLINT
	var ParameterValuePtr C.SQLPOINTER
	var BufferLength C.SQLLEN
	var StrLen_or_IndPt C.SQLLEN
	v := reflect.ValueOf(param)
	if param == nil {
		ft, _, _, _, err := stmt.GetParamType(index)
		if err != nil {
			return err
		}
		ParameterType = C.SQLSMALLINT(ft)
		if ParameterType == C.SQL_UNKNOWN_TYPE {
			ParameterType = C.SQL_VARCHAR
		}
		ValueType = C.SQL_C_DEFAULT
		StrLen_or_IndPt = C.SQL_NULL_DATA
		ColumnSize = 1
	} else {
		switch v.Kind() {
		case reflect.Bool:
			ParameterType = C.SQL_BIT
			ValueType = C.SQL_C_BIT
			var b [1]byte
			if v.Bool() {
				b[0] = 1
			} else {
				b[0] = 0
			}
			ParameterValuePtr = C.SQLPOINTER(unsafe.Pointer(&b[0]))
			BufferLength = 1
			StrLen_or_IndPt = 0
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			switch v.Type().Kind() {
			case reflect.Int:
			case reflect.Int8, reflect.Int16, reflect.Int32:
				ParameterType = C.SQL_INTEGER
				ValueType = C.SQL_C_LONG
				var l C.long = C.long(v.Int())
				ParameterValuePtr = C.SQLPOINTER(unsafe.Pointer(&l))
				BufferLength = 4
				StrLen_or_IndPt = 0
			case reflect.Int64:
				ParameterType = C.SQL_BIGINT
				ValueType = C.SQL_C_SBIGINT
				var ll C.longlong = C.longlong(v.Int())
				ParameterValuePtr = C.SQLPOINTER(unsafe.Pointer(&ll))
				BufferLength = 8
				StrLen_or_IndPt = 0
			}
		case reflect.Float32, reflect.Float64:
			ParameterType = C.SQL_DOUBLE
			ValueType = C.SQL_C_DOUBLE
			var d C.double = C.double(v.Float())
			ParameterValuePtr = C.SQLPOINTER(unsafe.Pointer(&d))
			BufferLength = 8
			StrLen_or_IndPt = 0
		case reflect.Complex64, reflect.Complex128:
		case reflect.String:
			var slen C.SQLUINTEGER = C.SQLUINTEGER(len(v.String()))
			ParameterType = C.SQL_VARCHAR
			ValueType = C.SQL_C_CHAR
			s := []byte(v.String())
			ParameterValuePtr = C.SQLPOINTER(unsafe.Pointer(&s[0]))
			ColumnSize = C.SQLULEN(slen)
			BufferLength = C.SQLLEN(slen + 1)
			StrLen_or_IndPt = C.SQLLEN(slen)
		default:
			fmt.Println("Not support type", v)
		}
	}
	ret := C.SQLBindParameter(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(index), C.SQL_PARAM_INPUT, ValueType, ParameterType, ColumnSize, DecimalDigits, ParameterValuePtr, BufferLength, &StrLen_or_IndPt)
	if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
		return err
	}

	return nil
}
Example #28
0
File: lua.go Project: reusee/lua
func (l *Lua) pushGoValue(v interface{}, name string) error {
	if v == nil {
		C.lua_pushnil(l.State)
		return nil
	}
	switch value := v.(type) {
	case bool:
		if value {
			C.lua_pushboolean(l.State, C.int(1))
		} else {
			C.lua_pushboolean(l.State, C.int(0))
		}
	case string:
		C.lua_pushstring(l.State, C.CString(value))
	case int:
		C.lua_pushnumber(l.State, C.lua_Number(C.longlong(value)))
	case int8:
		C.lua_pushnumber(l.State, C.lua_Number(C.longlong(value)))
	case int16:
		C.lua_pushnumber(l.State, C.lua_Number(C.longlong(value)))
	case int32:
		C.lua_pushnumber(l.State, C.lua_Number(C.longlong(value)))
	case int64:
		C.lua_pushnumber(l.State, C.lua_Number(C.longlong(value)))
	case uint:
		C.lua_pushnumber(l.State, C.lua_Number(C.ulonglong(value)))
	case uint8:
		C.lua_pushnumber(l.State, C.lua_Number(C.ulonglong(value)))
	case uint16:
		C.lua_pushnumber(l.State, C.lua_Number(C.ulonglong(value)))
	case uint32:
		C.lua_pushnumber(l.State, C.lua_Number(C.ulonglong(value)))
	case uint64:
		C.lua_pushnumber(l.State, C.lua_Number(C.ulonglong(value)))
	case float32:
		C.lua_pushnumber(l.State, C.lua_Number(C.double(value)))
	case float64:
		C.lua_pushnumber(l.State, C.lua_Number(C.double(value)))
	case unsafe.Pointer:
		C.lua_pushlightuserdata(l.State, value)
	default:
		// not basic types, use reflect
		switch valueType := reflect.TypeOf(v); valueType.Kind() {
		case reflect.Func:
			// function
			if valueType.IsVariadic() {
				return fmt.Errorf("variadic function is not supported, %s", name)
			}
			function := &_Function{
				name:      name,
				lua:       l,
				fun:       v,
				funcType:  valueType,
				funcValue: reflect.ValueOf(v),
				argc:      valueType.NumIn(),
			}
			funcsLock.Lock()
			funcs = append(funcs, function)
			id := len(funcs) - 1
			funcsLock.Unlock()
			C.push_go_func(l.State, C.int64_t(id))
		case reflect.Slice:
			value := reflect.ValueOf(v)
			length := value.Len()
			C.lua_createtable(l.State, C.int(length), 0)
			for i := 0; i < length; i++ {
				C.lua_pushnumber(l.State, C.lua_Number(i+1))
				err := l.pushGoValue(value.Index(i).Interface(), "")
				if err != nil {
					return err
				}
				C.lua_settable(l.State, -3)
			}
		case reflect.Ptr:
			C.lua_pushlightuserdata(l.State, unsafe.Pointer(reflect.ValueOf(v).Pointer()))
		default:
			// unknown type
			return fmt.Errorf("unsupported type %v", v)
		}
	}
	return nil
}
Example #29
0
func NewLong(i int64) *Long {
	return newLong(C.PyLong_FromLongLong(C.longlong(i)))
}
Example #30
0
func NewVariantInt64(n int64) Variant {
	return globalObjectTable.bindObject(C.wxVariant_NewInt64(C.longlong(n)), true).(Variant)
}