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


Golang C.bool函数代码示例

本文整理汇总了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
}
开发者ID:getblank,项目名称:v8worker,代码行数:31,代码来源:worker.go

示例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
}
开发者ID:csdigi,项目名称:cockroach,代码行数:67,代码来源:rocksdb.go

示例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
}
开发者ID:Hellblazer,项目名称:cockroach,代码行数:32,代码来源:rocksdb.go

示例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
}
开发者ID:liugangnhm,项目名称:cockroach,代码行数:35,代码来源:rocksdb.go

示例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)
}
开发者ID:kingland,项目名称:openimageigo,代码行数:10,代码来源:oiio.go

示例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
}
开发者ID:kingland,项目名称:openimageigo,代码行数:56,代码来源:imagebufalgo.go

示例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
}
开发者ID:josephyzhou,项目名称:libtox,代码行数:15,代码来源:tox.go

示例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
}
开发者ID:zanella,项目名称:nomad,代码行数:16,代码来源:container.go

示例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
}
开发者ID:zanella,项目名称:nomad,代码行数:17,代码来源:container.go

示例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])
}
开发者ID:ht101996,项目名称:libmc,代码行数:30,代码来源:golibmc.go

示例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
	}
}
开发者ID:godeep,项目名称:wellington,代码行数:35,代码来源:encoding.go

示例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
}
开发者ID:kothar,项目名称:brotli-go,代码行数:22,代码来源:encode.go

示例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])
}
开发者ID:huachen0216,项目名称:libmc,代码行数:36,代码来源:golibmc.go

示例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
}
开发者ID:vonwenm,项目名称:goczmq,代码行数:8,代码来源:cert.go

示例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
}
开发者ID:trotha01,项目名称:goncurses,代码行数:9,代码来源:window.go


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