Package dl
2015-06-03 18:42
225 查看
import "gopkgs.com/dl.v1"
(referenced as dl)
(u)int32 - (unsigned) int (u)int64 - uint64_t / int64_t float32 - float float64 - double string - char * (read only) []byte - char * (readwrite) slices - pointer to first argument uintptr - void * unsafe.Pointer - void * No struct types are supported at this
time.
Constants
Open(name string, flag int) (*DL, error)
(d *DL) Close() error
(d *DL) Sym(symbol string, out interface{}) error
asm_amd64.S
darwin.go
dl.go
doc.go
gopkgs.go
sysv.go
trampoline.go
trampoline.h
This package supports the following type mapping between Goand C.
No struct types are supported at this time.
It might be retrieved as a value, returning a copy with:
Alternatively, a pointer to the variable might be obtained as:
Note that changing the value via the pointer will change the symbolin the loaded library, while changing the value obtained without thepointer will not, since a copy is made at lookup time.
Argument and return types must be of one of thesupported types. See the examples in this package for the complete code.
Functions retrieved from a symbol can be used as standard Go functions.
DL represents an opened dynamic library. Use
Opento initialize a DL and use
DL.Close when you're finishedwith it. Note that when the DL is closed all its loadedsymbols become invalid.
Open opens the shared library identified by the given namewith the given flags. See man dlopen for the available flagsand its meaning. Note that the only difference with dlopen is thatif nor
RTLD_LAZY nor
RTLD_NOW are specified, Open defaults toRTLD_NOW rather than returning an error. If the name argumentpassed to name does not have extension, the default for theplatform
will be appended to it (e.g. .so, .dylib, etc...).
Close closes the shared library handle. All symbolsloaded from the library will become invalid.
Sym loads the symbol identified by the given name intothe out parameter. Note that out must always be a pointer.See the package documentation to learn how types are mappedbetween Go and C.
(referenced as dl)
Overview
Package dl implements dynamic of shared libraries, like dlopen() and dlsym() in C. This package supports the following type mapping between Go and C. Go - C (u)int - (unsigned) long (u)int8 - uint8_t / int8_t (u)int16 - uint16_t / int16_t(u)int32 - (unsigned) int (u)int64 - uint64_t / int64_t float32 - float float64 - double string - char * (read only) []byte - char * (readwrite) slices - pointer to first argument uintptr - void * unsafe.Pointer - void * No struct types are supported at this
time.
Index
DocumentationConstants
Types
DLOpen(name string, flag int) (*DL, error)
(d *DL) Close() error
(d *DL) Sym(symbol string, out interface{}) error
Functions
Open(name string, flag int) (*DL, error)Files
amd64.casm_amd64.S
darwin.go
dl.go
doc.go
gopkgs.go
sysv.go
trampoline.go
trampoline.h
Documentation
Package dl implements dynamic of shared libraries, likedlopen() and dlsym() in C.This package supports the following type mapping between Goand C.
Go - C (u)int - (unsigned) long (u)int8 - uint8_t / int8_t (u)int16 - uint16_t / int16_t (u)int32 - (unsigned) int (u)int64 - uint64_t / int64_t float32 - float float64 - double string - char * (read only) []byte - char * (readwrite) slices - pointer to first argument uintptr - void * unsafe.Pointer - void *
No struct types are supported at this time.
Retrieving variable symbols
Symbols pointing to variables might be retrievedeither as values or pointers. Given a C librarywhich declares a symbol as:int my_int = 8;
It might be retrieved as a value, returning a copy with:
var myInt int32 if err := lib.Sym("my_int", &myInt); err != nil { handle_error... }
Alternatively, a pointer to the variable might be obtained as:
var myInt *int32 if err := lib.Sym("my_int", &myInt); err != nil { handle_error... }
Note that changing the value via the pointer will change the symbolin the loaded library, while changing the value obtained without thepointer will not, since a copy is made at lookup time.
Retrieving function symbols
This package also supports dynamically loading functions from libraries. Todo so you must declare a function variable which matches the signature of theC function. Note that type mismatches will likely result in crashes, so use thisfeature with extreme care.Argument and return types must be of one of thesupported types. See the examples in this package for the complete code.
var printf func(string, ...interface{}) int32 if err := lib.Sym("printf", &printf); err != nil { handle_error... } printf("this string uses C format: %d\n", 7)
Functions retrieved from a symbol can be used as standard Go functions.
Overhead
Typically, calling functions via this package rather than using cgo directlytakes around 500ns more per call, due to reflection overhead. Future versionsmight adopt a JIT strategy which should make it as fast as cgo.Constants
const ( // dlopen() flags. See man dlopen. RTLD_LAZY = int(C.RTLD_LAZY) RTLD_NOW = int(C.RTLD_NOW) RTLD_GLOBAL = int(C.RTLD_GLOBAL) RTLD_LOCAL = int(C.RTLD_LOCAL) RTLD_NODELETE = int(C.RTLD_NODELETE) RTLD_NOLOAD = int(C.RTLD_NOLOAD) )
const ( LibExt = ".so" )
Types
type DL
type DL struct { // contains filtered or unexported fields }
DL represents an opened dynamic library. Use
Opento initialize a DL and use
DL.Close when you're finishedwith it. Note that when the DL is closed all its loadedsymbols become invalid.
func Open
func Open(name string, flag int) (*DL, error)
Open opens the shared library identified by the given namewith the given flags. See man dlopen for the available flagsand its meaning. Note that the only difference with dlopen is thatif nor
RTLD_LAZY nor
RTLD_NOW are specified, Open defaults toRTLD_NOW rather than returning an error. If the name argumentpassed to name does not have extension, the default for theplatform
will be appended to it (e.g. .so, .dylib, etc...).
func (DL) Close
func (d *DL) Close() error
Close closes the shared library handle. All symbolsloaded from the library will become invalid.
func (DL) Sym
func (d *DL) Sym(symbol string, out interface{}) error
Sym loads the symbol identified by the given name intothe out parameter. Note that out must always be a pointer.See the package documentation to learn how types are mappedbetween Go and C.
相关文章推荐
- VC使用mysql API 连接mysql数据库
- 黑马程序员_java语言_ArrayList和泛型的概述
- android打包准备:混淆第三方jar包(Gson, greenDao,sharesdk,UIL,高德地图, unity,pinyin4j,async http,JPush,EventBus等)
- SlopOne推荐算法
- MySQL字符集问题
- 高仿QQ音乐之旋转专辑图片的实现—仿留声机效果
- sicily 1219(记忆化搜索)
- Android 自定义view 的绘制时机 问题
- linux的IP配置方法
- 基于drbd的mariaDB 的高可用集群
- HBase 单台服务器启动多个 thrift 服务
- 主键,外键,视图,索引
- IMP-00038: Could not convert to environment character set's handle
- REHL6.2 添加yum源
- 单调队列
- 让Apache支持ASP.NET
- http服务(二)——apache基于用户名访问控制
- 比较器 comparable vs comparator
- Android手机客户端与服务器之间的通信、Android手机客户端通过服务器与Android手机客户端之间的通信---------阿冬专栏!!!
- 笔记本连接无线局域网的设置