当前位置: 首页>>代码示例>>Golang>>正文


Golang unsafe.Pointer函数代码示例

本文整理汇总了Golang中unsafe.Pointer函数的典型用法代码示例。如果您正苦于以下问题:Golang Pointer函数的具体用法?Golang Pointer怎么用?Golang Pointer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Pointer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetProperty

// GetProperty() retreives the given attribute or freeform property
// string on the underlying Image
func (im *MagickImage) GetProperty(prop string) (value string) {
	c_prop := C.CString(prop)
	defer C.free(unsafe.Pointer(c_prop))
	c_value := C.GetImageProperty(im.Image, c_prop)
	defer C.free(unsafe.Pointer(c_value))
	return C.GoString(c_value)
}
开发者ID:mat,项目名称:magick,代码行数:9,代码来源:magick.go

示例2: mount

func mount(source string, target string, fstype string, flags uintptr, data *byte) (err error) {
	var _p0 *byte
	_p0, err = BytePtrFromString(source)
	if err != nil {
		return
	}
	var _p1 *byte
	_p1, err = BytePtrFromString(target)
	if err != nil {
		return
	}
	var _p2 *byte
	_p2, err = BytePtrFromString(fstype)
	if err != nil {
		return
	}
	_, _, e1 := Syscall6(SYS_MOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(unsafe.Pointer(_p2)), uintptr(flags), uintptr(unsafe.Pointer(data)), 0)
	use(unsafe.Pointer(_p0))
	use(unsafe.Pointer(_p1))
	use(unsafe.Pointer(_p2))
	if e1 != 0 {
		err = errnoErr(e1)
	}
	return
}
开发者ID:Xetius,项目名称:grafana,代码行数:25,代码来源:zsyscall_linux_amd64.go

示例3: ListModes

// Returns the list of available screen dimensions for the given format.
//
// NOTE: The result of this function uses a different encoding than the underlying C function.
// It returns an empty array if no modes are available,
// and nil if any dimension is okay for the given format.
func ListModes(format *PixelFormat, flags uint32) []Rect {
	modes := C.SDL_ListModes((*C.SDL_PixelFormat)(cast(format)), C.Uint32(flags))

	// No modes available
	if modes == nil {
		return make([]Rect, 0)
	}

	// (modes == -1) --> Any dimension is ok
	if uintptr(unsafe.Pointer(modes))+1 == uintptr(0) {
		return nil
	}

	count := 0
	ptr := *modes //first element in the list
	for ptr != nil {
		count++
		ptr = *(**C.SDL_Rect)(unsafe.Pointer(uintptr(unsafe.Pointer(modes)) + uintptr(count*unsafe.Sizeof(ptr))))
	}

	ret := make([]Rect, count)
	for i := 0; i < count; i++ {
		ptr := (**C.SDL_Rect)(unsafe.Pointer(uintptr(unsafe.Pointer(modes)) + uintptr(i*unsafe.Sizeof(*modes))))
		var r *C.SDL_Rect = *ptr
		ret[i].X = int16(r.x)
		ret[i].Y = int16(r.y)
		ret[i].W = uint16(r.w)
		ret[i].H = uint16(r.h)
	}

	return ret
}
开发者ID:kearsley,项目名称:Go-SDL,代码行数:37,代码来源:sdl.go

示例4: convert

func (ic *Iconv) convert(input []byte, out io.Writer, outBuf []byte) (bytesConverted int, err error) {
	inputLen := len(input)
	if inputLen == 0 {
		return
	}

	outputLen := len(outBuf)
	if outputLen == 0 {
		outputLen = inputLen
		outBuf = make([]byte, outputLen)
	}

	outputPtr := &outBuf[0]
	outputPtrPtr := (**C.char)(unsafe.Pointer(&outputPtr))
	outputBytesLeft := C.size_t(outputLen)

	inputPtr := &input[0]
	inputPtrPtr := (**C.char)(unsafe.Pointer(&inputPtr))
	inputBytesLeft := C.size_t(inputLen)

	_, err = C.iconv(ic.pIconv, inputPtrPtr, &inputBytesLeft, outputPtrPtr, &outputBytesLeft)
	bytesConverted = inputLen - int(inputBytesLeft)
	if int(outputBytesLeft) < outputLen {
		out.Write(outBuf[:outputLen-int(outputBytesLeft)])
	}
	return
}
开发者ID:pombredanne,项目名称:goconv,代码行数:27,代码来源:iconv.go

示例5: getBuffer

func getBuffer(s *reflect.SliceHeader, p *C.PaStreamParameters) (unsafe.Pointer, int, error) {
	if p.sampleFormat&C.paNonInterleaved == 0 {
		n := int(p.channelCount)
		if s.Len%n != 0 {
			return nil, 0, fmt.Errorf("length of interleaved buffer not divisible by number of channels")
		}
		return unsafe.Pointer(s.Data), s.Len / n, nil
	} else {
		if s.Len != int(p.channelCount) {
			return nil, 0, fmt.Errorf("buffer has wrong number of channels")
		}
		buf := make([]uintptr, s.Len)
		frames := -1
		sp := s.Data
		for i := range buf {
			ch := (*reflect.SliceHeader)(unsafe.Pointer(sp))
			if frames == -1 {
				frames = ch.Len
			} else if ch.Len != frames {
				return nil, 0, fmt.Errorf("channels have different lengths")
			}
			buf[i] = ch.Data
			sp += unsafe.Sizeof(reflect.SliceHeader{})
		}
		return unsafe.Pointer(&buf[0]), frames, nil
	}
}
开发者ID:gordonklaus,项目名称:portaudio,代码行数:27,代码来源:portaudio.go

示例6: bind

func (bnd *bndTimePtr) bind(value *time.Time, position int, stmt *Stmt) error {
	bnd.stmt = stmt
	bnd.value = value
	r := C.OCIDescriptorAlloc(
		unsafe.Pointer(bnd.stmt.ses.srv.env.ocienv),         //CONST dvoid   *parenth,
		(*unsafe.Pointer)(unsafe.Pointer(&bnd.ociDateTime)), //dvoid         **descpp,
		C.OCI_DTYPE_TIMESTAMP_TZ,                            //ub4           type,
		0,   //size_t        xtramem_sz,
		nil) //dvoid         **usrmempp);
	if r == C.OCI_ERROR {
		return bnd.stmt.ses.srv.env.ociError()
	} else if r == C.OCI_INVALID_HANDLE {
		return errNew("unable to allocate oci timestamp handle during bind")
	}
	r = C.OCIBINDBYPOS(
		bnd.stmt.ocistmt,                              //OCIStmt      *stmtp,
		(**C.OCIBind)(&bnd.ocibnd),                    //OCIBind      **bindpp,
		bnd.stmt.ses.srv.env.ocierr,                   //OCIError     *errhp,
		C.ub4(position),                               //ub4          position,
		unsafe.Pointer(&bnd.ociDateTime),              //void         *valuep,
		C.LENGTH_TYPE(unsafe.Sizeof(bnd.ociDateTime)), //sb8          value_sz,
		C.SQLT_TIMESTAMP_TZ,                           //ub2          dty,
		unsafe.Pointer(&bnd.isNull),                   //void         *indp,
		nil,           //ub2          *alenp,
		nil,           //ub2          *rcodep,
		0,             //ub4          maxarr_len,
		nil,           //ub4          *curelep,
		C.OCI_DEFAULT) //ub4          mode );
	if r == C.OCI_ERROR {
		return bnd.stmt.ses.srv.env.ociError()
	}
	return nil
}
开发者ID:optimuse,项目名称:ora,代码行数:33,代码来源:bndTimePtr.go

示例7: Prepare

func (c *driverConn) Prepare(query string) (driver.Stmt, error) {
	// Generate unique statement name.
	stmtname := strconv.Itoa(c.stmtNum)
	cstmtname := C.CString(stmtname)
	c.stmtNum++
	defer C.free(unsafe.Pointer(cstmtname))
	stmtstr := C.CString(query)
	defer C.free(unsafe.Pointer(stmtstr))
	res := C.PQprepare(c.db, cstmtname, stmtstr, 0, nil)
	err := resultError(res)
	if err != nil {
		C.PQclear(res)
		return nil, err
	}
	stmtinfo := C.PQdescribePrepared(c.db, cstmtname)
	err = resultError(stmtinfo)
	if err != nil {
		C.PQclear(stmtinfo)
		return nil, err
	}
	defer C.PQclear(stmtinfo)
	nparams := int(C.PQnparams(stmtinfo))
	statement := &driverStmt{stmtname, c.db, res, nparams}
	runtime.SetFinalizer(statement, (*driverStmt).Close)
	return statement, nil
}
开发者ID:NDrive,项目名称:gopgsqldriver,代码行数:26,代码来源:pgdriver.go

示例8: init

func init() {
	// CUDA driver kernel call wants pointers to arguments, set them up once.
	zeromask_args.argptr[0] = unsafe.Pointer(&zeromask_args.arg_dst)
	zeromask_args.argptr[1] = unsafe.Pointer(&zeromask_args.arg_maskLUT)
	zeromask_args.argptr[2] = unsafe.Pointer(&zeromask_args.arg_regions)
	zeromask_args.argptr[3] = unsafe.Pointer(&zeromask_args.arg_N)
}
开发者ID:jsampaio,项目名称:3,代码行数:7,代码来源:zeromask_wrapper.go

示例9: Sethook

// Sets the debugging hook function.
//
// Argument fn is the hook function. mask specifies on which events the hook
// will be called: it is formed by a bitwise OR of the constants Maskcall,
// Maskret, Maskline, and Maskcount. The count argument is only meaningful
// when the mask includes Maskcount. The hook is called for each event type
// present in mask.
//
// A hook is disabled by setting mask to 0.
func (s *State) Sethook(fn Hook, mask, count int) error {
	s.Getglobal(namehooks)
	if mask&Maskcall == Maskcall {
		s.Pushstring(namecall)
		s.Pushlightuserdata(unsafe.Pointer(&fn))
		s.Settable(-3)
	}
	if mask&Maskret == Maskret {
		s.Pushstring(nameret)
		s.Pushlightuserdata(unsafe.Pointer(&fn))
		s.Settable(-3)
	}
	if mask&Maskline == Maskline {
		s.Pushstring(nameline)
		s.Pushlightuserdata(unsafe.Pointer(&fn))
		s.Settable(-3)
	}
	if mask&Maskcount == Maskcount {
		s.Pushstring(namecount)
		s.Pushlightuserdata(unsafe.Pointer(&fn))
		s.Settable(-3)
	}
	s.Pop(1) // pop hook table
	C.sethook(s.l, C.int(mask), C.int(count))
	return nil
}
开发者ID:halturin,项目名称:luajit,代码行数:35,代码来源:debug.go

示例10: accept4

func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
	fd, e := socketcall(_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
	if e != 0 {
		err = e
	}
	return
}
开发者ID:CM44,项目名称:shipyard,代码行数:7,代码来源:syscall_linux_386.go

示例11: CmdGetMapped

// CmdGetMapped returns the interface settings in a map
func (e *Ethtool) CmdGetMapped(intf string) (map[string]uint64, error) {
	ecmd := EthtoolCmd{
		Cmd: ETHTOOL_GSET,
	}

	var name [IFNAMSIZ]byte
	copy(name[:], []byte(intf))

	ifr := ifreq{
		ifr_name: name,
		ifr_data: uintptr(unsafe.Pointer(&ecmd)),
	}

	_, _, ep := syscall.Syscall(syscall.SYS_IOCTL, uintptr(e.fd),
		SIOCETHTOOL, uintptr(unsafe.Pointer(&ifr)))
	if ep != 0 {
		return nil, syscall.Errno(ep)
	}

	var result = make(map[string]uint64)

	// ref https://gist.github.com/drewolson/4771479
	// Golang Reflection Example
	ecmd.reflect(&result)

	var speedval uint32 = (uint32(ecmd.Speed_hi) << 16) |
		(uint32(ecmd.Speed) & 0xffff)
	result["speed"] = uint64(speedval)

	return result, nil
}
开发者ID:safchain,项目名称:ethtool,代码行数:32,代码来源:ethtool_cmd.go

示例12: callback_friend_request

//export callback_friend_request
func callback_friend_request(
	c_tox *C.Tox,
	c_public_key *C.uint8_t,
	c_message *C.uint8_t,
	c_length C.size_t,
	c_user_data unsafe.Pointer,
) {
	// Initialize variables.
	tox := (*Tox)(c_user_data)
	var publicKey ToxPublicKey
	message := make([]byte, c_length)
	// Copy the public key.
	C.memcpy(
		unsafe.Pointer(&publicKey[0]),
		unsafe.Pointer(c_public_key),
		ToxPublicKeySize,
	)
	// Copy the friend request message.
	if c_length > 0 {
		C.memcpy(
			unsafe.Pointer(&message[0]),
			unsafe.Pointer(c_message),
			c_length,
		)
	}
	// Register the callback.
	tox.onFriendRequest(tox, publicKey, message)
}
开发者ID:josephyzhou,项目名称:libtox,代码行数:29,代码来源:callbacks.go

示例13: callback_friend_message

//export callback_friend_message
func callback_friend_message(
	c_tox *C.Tox,
	c_friend_number C.uint32_t,
	c_message_type C.TOX_MESSAGE_TYPE,
	c_message *C.uint8_t,
	c_length C.size_t,
	c_user_data unsafe.Pointer,
) {
	// Initialize variables.
	tox := (*Tox)(c_user_data)
	friendNumber := uint32(c_friend_number)
	var messageType ToxMessageType
	switch c_message_type {
	case C.TOX_MESSAGE_TYPE_NORMAL:
		messageType = ToxMessageTypeNormal
	case C.TOX_MESSAGE_TYPE_ACTION:
		messageType = ToxMessageTypeAction
	}
	message := make([]byte, c_length)
	// Copy the chat message.
	if c_length > 0 {
		C.memcpy(
			unsafe.Pointer(&message[0]),
			unsafe.Pointer(c_message),
			c_length,
		)
	}
	// Register the callback.
	tox.onFriendMessage(tox, friendNumber, messageType, message)
}
开发者ID:josephyzhou,项目名称:libtox,代码行数:31,代码来源:callbacks.go

示例14: connect

func connect(conninfo string) (*PgConn, error) {
	cs := C.CString(conninfo)
	defer C.free(unsafe.Pointer(cs))
	conn := C.PQconnectdb(cs)
	if C.PQstatus(conn) != C.CONNECTION_OK {
		cerr := C.PQerrorMessage(conn)
		err := fmt.Errorf("connection failed: %s", C.GoString(cerr))
		C.PQfinish(conn)
		return nil, err
	}

	// TODO: support other encodings?
	pname := C.CString("client_encoding")
	defer C.free(unsafe.Pointer(pname))
	cenc := C.PQparameterStatus(conn, pname)
	if cenc == nil {
		err := errors.New("connection failed: no client encoding")
		C.PQfinish(conn)
		return nil, err
	}
	if enc := C.GoString(cenc); enc != "UTF8" {
		err := fmt.Errorf(
			"connection failed: client encoding not supported: %s", enc)
		C.PQfinish(conn)
		return nil, err
	}

	// one-line error message
	C.PQsetErrorVerbosity(conn, C.PQERRORS_TERSE)

	return &PgConn{conn: conn, conninfo: conninfo}, nil
}
开发者ID:dvarrazzo,项目名称:pger,代码行数:32,代码来源:pq.go

示例15: ECDH

//raise a pubkey to the power of a seckey
func ECDH(pub []byte, sec []byte) []byte {
	if len(sec) != 32 {
		log.Panic()
	}

	if len(pub) != 33 {
		log.Panic()
	}

	if VerifyPubkey(pub) != 1 {
		log.Printf("Invalid Pubkey")
		return nil
	}

	if VerifySeckey(sec) != 1 {
		log.Printf("Invalid Seckey")
	}

	var pub2 []byte = make([]byte, 33)
	copy(pub2[0:33], pub[0:33])

	var pub_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&pub2[0]))
	var sec_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&sec[0]))

	ret := C.secp256k1_ecdsa_pubkey_tweak_mul(
		pub_ptr, C.int(len(pub2)),
		sec_ptr,
	)

	if ret != 1 {
		return nil
	}

	return pub2
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:36,代码来源:secp256.go


注:本文中的unsafe.Pointer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。