Golang C.bool类(方法)实例源码

下面列出了Golang C.bool 类(方法)源码代码实例,从而了解它的用法。

作者:getblan    项目:v8worke   
// 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
}

作者:csdig    项目:cockroac   
// 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
}

作者:Hellblaze    项目:cockroac   
// 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
}

作者:liugangnh    项目:cockroac   
// 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
}

作者:kinglan    项目:openimageig   
//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)
}

作者:kinglan    项目:openimageig   
// 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
}

作者:josephyzho    项目:libto   
// 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
}

作者:zanell    项目:noma   
// 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
}

作者:zanell    项目:noma   
// 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
}

作者:ht10199    项目:libm   
// 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])
}

作者:godee    项目:wellingto   
// 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
	}
}

作者:kotha    项目:brotli-g   
// 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
}

作者:huachen021    项目:libm   
// 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])
}

作者:vonwen    项目:goczm   
// 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
}

作者:trotha0    项目:goncurse   
// 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
}

作者:ht10199    项目:libm   
// Touch command
func (client *Client) Touch(key string, expiration int64) 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))
	cExptime := C.exptime_t(expiration)
	cNoreply := C.bool(client.noreply)

	var rst **C.message_result_t
	var n C.size_t

	errCode := C.client_touch(
		client._imp, &cKey, &cKeyLen, cExptime, 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_TOUCHED {
			return nil
		}
	}
	return errors.New(errorMessage[errCode])
}

作者:justinf    项目:opencolorig   
func (c *Config) SetStrictParsingEnabled(enabled bool) error {
	_, err := C.Config_setStrictParsingEnabled(c.ptr, C.bool(enabled))
	if err != nil {
		return c.lastError()
	}
	return err
}

作者:kinglan    项目:openimageig   
// This routine will return the error string (and clear any error
// flags).  If no error has occurred since the last time GetError()
// was called, it will return an empty string.
func (c *ColorConfig) error() error {
	isError := C.ColorConfig_error(c.ptr)
	if C.bool(isError) {
		return errors.New(C.GoString(C.ColorConfig_geterror(c.ptr)))
	}
	return nil
}

作者:Olreic    项目:ncurse   
/* Enables the reading of all keys on a keyboard (that the operating system will interpret) */
func Keypad(win *Window, translate bool) {
	temp := 0
	if translate {
		temp = 1
	}
	C.keypad((*C.WINDOW)(win), C.bool(temp))
}

作者:louisZ    项目:sslcon   
// Creates new SSL connection for the underlying reader and writer.
func NewConn(reader io.Reader, writer io.Writer,
	config *Config, server bool) (*Conn, error) {
	c := &Conn{}

	if server && (config.Cert == nil || config.PrivateKey == nil) {
		panic("Cert and PrivateKey are required for server SSL connections")
	}

	sslConnConfig := newSSLConnConfig(config)
	defer cleanupSSLConnConfig(sslConnConfig)
	sslConnConfig.is_server = C.bool(server)
	sslConnConfig.ptr = unsafe.Pointer(c)

	var sslConnError C.SSLConnError
	c.sslConn = C.SSLConn_new(sslConnConfig,
		(*C.SSLConnError)(unsafe.Pointer(&sslConnError)))
	if c.sslConn == nil {
		return nil, errors.New(C.GoString(&sslConnError.string[0]))
	}

	c.lock = &sync.Mutex{}
	c.reader = NewNonBlockingReader(reader, defaultBufferSize)
	c.writer = NewNonBlockingWriter(writer, defaultBufferSize)
	return c, nil
}


问题


面经


文章

微信
公众号

扫码关注公众号