本文整理匯總了Golang中C.bool函數的典型用法代碼示例。如果您正苦於以下問題:Golang bool函數的具體用法?Golang bool怎麽用?Golang bool使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了bool函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LoadWithOptions
// LoadWithOptions loads and executes a javascript file with the ScriptOrigin specified by
// origin and the contents of the file specified by the param code.
func (w *Worker) LoadWithOptions(origin *ScriptOrigin, code string) error {
cCode := C.CString(code)
if origin == nil {
origin = new(ScriptOrigin)
}
if origin.ScriptName == "" {
origin.ScriptName = nextScriptName()
}
cScriptName := C.CString(origin.ScriptName)
cLineOffset := C.int(origin.LineOffset)
cColumnOffset := C.int(origin.ColumnOffset)
cIsSharedCrossOrigin := C.bool(origin.IsSharedCrossOrigin)
cScriptId := C.int(origin.ScriptId)
cIsEmbedderDebugScript := C.bool(origin.IsEmbedderDebugScript)
cSourceMapURL := C.CString(origin.SourceMapURL)
cIsOpaque := C.bool(origin.IsOpaque)
defer C.free(unsafe.Pointer(cScriptName))
defer C.free(unsafe.Pointer(cCode))
defer C.free(unsafe.Pointer(cSourceMapURL))
r := C.worker_load(w.cWorker, cCode, cScriptName, cLineOffset, cColumnOffset, cIsSharedCrossOrigin, cScriptId, cIsEmbedderDebugScript, cSourceMapURL, cIsOpaque)
if r != 0 {
errStr := C.worker_last_exception(w.cWorker)
return errors.New(C.GoString(errStr))
}
return nil
}
示例2: Open
// Open creates options and opens the database. If the database
// doesn't yet exist at the specified directory, one is initialized
// from scratch. The RocksDB Open and Close methods are reference
// counted such that subsequent Open calls to an already opened
// RocksDB instance only bump the reference count. The RocksDB is only
// closed when a sufficient number of Close calls are performed to
// bring the reference count down to 0.
func (r *RocksDB) Open() error {
if r.rdb != nil {
return nil
}
if r.memtableBudget < minMemtableBudget {
return util.Errorf("memtable budget must be at least %s: %s",
humanize.IBytes(minMemtableBudget), humanizeutil.IBytes(r.memtableBudget))
}
var ver storageVersion
if len(r.dir) != 0 {
log.Infof("opening rocksdb instance at %q", r.dir)
// Check the version number.
var err error
if ver, err = getVersion(r.dir); err != nil {
return err
}
if ver < versionMinimum || ver > versionCurrent {
// Instead of an error, we should call a migration if possible when
// one is needed immediately following the DBOpen call.
return fmt.Errorf("incompatible rocksdb data version, current:%d, on disk:%d, minimum:%d",
versionCurrent, ver, versionMinimum)
}
} else {
log.Infof("opening in memory rocksdb instance")
// In memory dbs are always current.
ver = versionCurrent
}
status := C.DBOpen(&r.rdb, goToCSlice([]byte(r.dir)),
C.DBOptions{
cache_size: C.uint64_t(r.cacheSize),
memtable_budget: C.uint64_t(r.memtableBudget),
block_size: C.uint64_t(envutil.EnvOrDefaultBytes("rocksdb_block_size", defaultBlockSize)),
wal_ttl_seconds: C.uint64_t(envutil.EnvOrDefaultDuration("rocksdb_wal_ttl", 0).Seconds()),
allow_os_buffer: C.bool(true),
logging_enabled: C.bool(log.V(3)),
})
if err := statusToError(status); err != nil {
return util.Errorf("could not open rocksdb instance: %s", err)
}
// Update or add the version file if needed.
if ver < versionCurrent {
if err := writeVersionFile(r.dir); err != nil {
return err
}
}
// Start a goroutine that will finish when the underlying handle
// is deallocated. This is used to check a leak in tests.
go func() {
<-r.deallocated
}()
r.stopper.AddCloser(r)
return nil
}
示例3: Open
// Open creates options and opens the database. If the database
// doesn't yet exist at the specified directory, one is initialized
// from scratch. The RocksDB Open and Close methods are reference
// counted such that subsequent Open calls to an already opened
// RocksDB instance only bump the reference count. The RocksDB is only
// closed when a sufficient number of Close calls are performed to
// bring the reference count down to 0.
func (r *RocksDB) Open() error {
if r.rdb != nil {
atomic.AddInt32(&r.refcount, 1)
return nil
}
if len(r.dir) == 0 {
log.Infof("opening in-memory rocksdb instance")
} else {
log.Infof("opening rocksdb instance at %q", r.dir)
}
status := C.DBOpen(&r.rdb, goToCSlice([]byte(r.dir)),
C.DBOptions{
cache_size: C.int64_t(r.cacheSize),
allow_os_buffer: C.bool(true),
logging_enabled: C.bool(log.V(3)),
})
err := statusToError(status)
if err != nil {
return util.Errorf("could not open rocksdb instance: %s", err)
}
atomic.AddInt32(&r.refcount, 1)
return nil
}
示例4: Open
// Open creates options and opens the database. If the database
// doesn't yet exist at the specified directory, one is initialized
// from scratch. The RocksDB Open and Close methods are reference
// counted such that subsequent Open calls to an already opened
// RocksDB instance only bump the reference count. The RocksDB is only
// closed when a sufficient number of Close calls are performed to
// bring the reference count down to 0.
func (r *RocksDB) Open() error {
if r.rdb != nil {
return nil
}
if len(r.dir) != 0 {
log.Infof("opening rocksdb instance at %q", r.dir)
}
status := C.DBOpen(&r.rdb, goToCSlice([]byte(r.dir)),
C.DBOptions{
cache_size: C.uint64_t(r.cacheSize),
memtable_budget: C.uint64_t(r.memtableBudget),
allow_os_buffer: C.bool(true),
logging_enabled: C.bool(log.V(3)),
})
err := statusToError(status)
if err != nil {
return util.Errorf("could not open rocksdb instance: %s", err)
}
// Start a goroutine that will finish when the underlying handle
// is deallocated. This is used to check a leak in tests.
go func() {
<-r.deallocated
}()
r.stopper.AddCloser(r)
return nil
}
示例5: image_progress_callback
//export image_progress_callback
func image_progress_callback(goCallback unsafe.Pointer, done C.float) C.bool {
if goCallback == nil {
return C.bool(false)
}
fn := *(*ProgressCallback)(goCallback)
cancel := fn(float32(done))
return C.bool(cancel)
}
示例6: Channels
// 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
}
示例7: cOptions
// Create a C struct to hold the Tox client startup options. This struct
// contains C heap items that must be freed to prevent memory leaks.
func (options *ToxOptions) cOptions() (c_options *C.struct_Tox_Options) {
// Initialize the return object.
c_options = &C.struct_Tox_Options{}
// Copy the fields.
c_options.ipv6_enabled = C.bool(options.IPv6Enabled)
c_options.udp_enabled = C.bool(options.UDPEnabled)
c_options.proxy_type = C.TOX_PROXY_TYPE(options.ProxyType)
c_options.proxy_host = C.CString(options.ProxyHost)
c_options.proxy_port = C.uint16_t(options.ProxyPort)
c_options.start_port = C.uint16_t(options.StartPort)
c_options.end_port = C.uint16_t(options.EndPort)
return
}
示例8: Restore
// Restore restores the container from a checkpoint.
func (c *Container) Restore(opts RestoreOptions) error {
if err := c.makeSure(isGreaterEqualThanLXC11); err != nil {
return err
}
cdirectory := C.CString(opts.Directory)
defer C.free(unsafe.Pointer(cdirectory))
cverbose := C.bool(opts.Verbose)
if !C.bool(C.go_lxc_restore(c.container, cdirectory, cverbose)) {
return ErrRestoreFailed
}
return nil
}
示例9: Checkpoint
// Checkpoint checkpoints the container.
func (c *Container) Checkpoint(opts CheckpointOptions) error {
if err := c.makeSure(isRunning | isGreaterEqualThanLXC11); err != nil {
return err
}
cdirectory := C.CString(opts.Directory)
defer C.free(unsafe.Pointer(cdirectory))
cstop := C.bool(opts.Stop)
cverbose := C.bool(opts.Verbose)
if !C.go_lxc_checkpoint(c.container, cdirectory, cstop, cverbose) {
return ErrCheckpointFailed
}
return nil
}
示例10: Delete
// Delete a key
func (client *Client) Delete(key string) error {
client.lock()
defer client.unlock()
rawKey := client.addPrefix(key)
cKey := C.CString(rawKey)
defer C.free(unsafe.Pointer(cKey))
cKeyLen := C.size_t(len(rawKey))
cNoreply := C.bool(client.noreply)
var rst **C.message_result_t
var n C.size_t
errCode := C.client_delete(
client._imp, &cKey, &cKeyLen, cNoreply, 1, &rst, &n,
)
defer C.client_destroy_message_result(client._imp)
if errCode == 0 {
if client.noreply {
return nil
} else if int(n) == 1 && ((*rst).type_ == C.MSG_DELETED || (*rst).type_ == C.MSG_NOT_FOUND) {
return nil
}
}
return errors.New(errorMessage[errCode])
}
示例11: makevalue
// make is needed to create types for use by test
func makevalue(v interface{}) (UnionSassValue, error) {
f := reflect.ValueOf(v)
err := error(nil)
switch f.Kind() {
default:
return C.sass_make_null(), err
case reflect.Bool:
return C.sass_make_boolean(C.bool(v.(bool))), err
case reflect.String:
return C.sass_make_string(C.CString(v.(string))), err
case reflect.Struct: //only SassNumber and color.RGBA are supported
if reflect.TypeOf(v).String() == "context.SassNumber" {
var sn = v.(SassNumber)
return C.sass_make_number(C.double(sn.Value), C.CString(sn.Unit)), err
} else if reflect.TypeOf(v).String() == "color.RGBA" {
var sc = v.(color.RGBA)
return C.sass_make_color(C.double(sc.R), C.double(sc.G), C.double(sc.B), C.double(sc.A)), err
} else {
err = errors.New(fmt.Sprintf("The struct type %s is unsupported for marshalling", reflect.TypeOf(v).String()))
return C.sass_make_null(), err
}
case reflect.Slice:
// Initialize the list
l := C.sass_make_list(C.size_t(f.Len()), C.SASS_COMMA)
for i := 0; i < f.Len(); i++ {
t, er := makevalue(f.Index(i).Interface())
if err == nil && er != nil {
err = er
}
C.sass_list_set_value(l, C.size_t(i), t)
}
return l, err
}
}
示例12: writeBrotliData
// Processes the accumulated input data and returns the new output meta-block,
// or zero if no new output meta-block was created (in this case the processed
// input data is buffered internally).
// Returns ErrInputLargerThanBlockSize if more data was copied to the ring buffer
// than the block sized.
// If isLast or forceFlush is true, an output meta-block is always created
func (bp *brotliCompressor) writeBrotliData(isLast bool, forceFlush bool) ([]byte, error) {
var outSize C.size_t
var output *C.uint8_t
success := C.CBrotliCompressorWriteBrotliData(bp.c, C.bool(isLast), C.bool(forceFlush), &outSize, &output)
if success == false {
return nil, errInputLargerThanBlockSize
}
// resize buffer if output is larger than we've anticipated
if int(outSize) > cap(bp.outputBuffer) {
bp.outputBuffer = make([]byte, int(outSize))
}
C.memcpy(unsafe.Pointer(&bp.outputBuffer[0]), unsafe.Pointer(output), outSize)
return bp.outputBuffer[:outSize], nil
}
示例13: Delete
// Delete a key
func (client *Client) Delete(key string) error {
client.lock()
defer client.unlock()
rawKey := client.addPrefix(key)
cKey := C.CString(rawKey)
defer C.free(unsafe.Pointer(cKey))
cKeyLen := C.size_t(len(rawKey))
cNoreply := C.bool(client.noreply)
var rst **C.message_result_t
var n C.size_t
errCode := C.client_delete(
client._imp, &cKey, &cKeyLen, cNoreply, 1, &rst, &n,
)
defer C.client_destroy_message_result(client._imp)
if errCode == 0 {
if client.noreply {
return nil
} else if int(n) == 1 {
if (*rst).type_ == C.MSG_DELETED {
return nil
} else if (*rst).type_ == C.MSG_NOT_FOUND {
return ErrCacheMiss
}
}
} else if errCode == C.RET_INVALID_KEY_ERR {
return ErrMalformedKey
}
return networkError(errorMessage[errCode])
}
示例14: Equal
// Equal checks two Certs for equality
func (c *Cert) Equal(compare *Cert) bool {
check := C.zcert_eq(c.zcertT, compare.zcertT)
if check == C.bool(true) {
return true
}
return false
}
示例15: Keypad
// Keypad turns on/off the keypad characters, including those like the F1-F12
// keys and the arrow keys
func (w *Window) Keypad(keypad bool) error {
var err C.int
if err = C.keypad(w.win, C.bool(keypad)); err == C.ERR {
return errors.New("Unable to set keypad mode")
}
return nil
}