作者:sq
项目:godoc
// HasKey is a wrapper around g_key_file_has_key().
func (kf *KeyFile) HasKey(group string, key string) bool {
cGroup := (*C.gchar)(C.CString(group))
defer C.g_free(C.gpointer(cGroup))
cKey := (*C.gchar)(C.CString(key))
defer C.g_free(C.gpointer(cKey))
return goBool(C.g_key_file_has_key(kf.cKey, cGroup, cKey, nil))
}
作者:dradtk
项目:gog
func GetInfoByName(namespace, symbol string) *GiInfo {
_namespace := GlibString(namespace)
defer C.g_free((C.gpointer)(_namespace))
_symbol := GlibString(symbol)
defer C.g_free((C.gpointer)(_symbol))
ptr := (*C.GIBaseInfo)(C.g_irepository_find_by_name(nil, _namespace, _symbol))
if ptr == nil {
return nil
}
return NewGiInfo(ptr)
}
作者:sq
项目:godoc
// GetKeys is a wrapper around g_key_file_get_keys().
func (kf *KeyFile) GetKeys(group string) (uint64, []string, error) {
cGroup := (*C.gchar)(C.CString(group))
defer C.g_free(C.gpointer(cGroup))
var length C.gsize
var cErr *C.GError
c := C.g_key_file_get_keys(kf.cKey, cGroup, &length, &cErr)
list := make([]string, uint64(length))
for i := range list {
list[i] = C.GoString((*(*[999999]*C.char)(unsafe.Pointer(c)))[i])
C.g_free(C.gpointer((*(*[999999]*C.char)(unsafe.Pointer(c)))[i]))
}
return uint64(length), list, goError(cErr)
}
作者:dradtk
项目:gog
func LoadNamespace(namespace string) bool {
_namespace := GlibString(namespace)
defer C.g_free((C.gpointer)(_namespace))
success := GoBool(C.load_namespace(_namespace))
if success {
cExports = make(map[string]bool)
cNamespace = namespace
prefixes = make(map[string]string)
blacklist = make(map[string]bool)
content, err := ioutil.ReadFile(filepath.Join("blacklist", namespace))
if err != nil {
println("error reading blacklist:", err.Error())
} else {
lines := strings.Split(string(content), "\n")
for _, line := range lines {
line = strings.TrimSpace(line)
if len(line) == 0 || strings.HasPrefix(line, "#") {
continue
}
blacklist[line] = true
}
}
}
return success
}
作者:glenn-brow
项目:regex-dn
// Return input with pattern replaced by sub.
func reSub(pattern []byte, sub []byte, input []byte) []byte {
var err *C.GError = nil
re := C.g_regex_new(
(*C.gchar)(data(append(pattern, 0))),
C.G_REGEX_CASELESS|
C.G_REGEX_RAW|
C.G_REGEX_NO_AUTO_CAPTURE|
C.G_REGEX_OPTIMIZE,
0,
&err)
if err != nil {
panic("g_regex_new")
}
defer C.g_regex_unref(re)
subd := C.g_regex_replace_literal(re, (*C.gchar)(data(input)),
C.gssize(len(input)), 0, (*C.gchar)(data(sub)), 0, &err)
if err != nil {
panic("g_regex_replace_literal")
}
defer C.g_free(C.gpointer(subd))
l := C.strlen((*C.char)(subd))
rv := make([]byte, l)
C.memcpy(data(rv), unsafe.Pointer(subd), l)
return rv
}
作者:sq
项目:godoc
// ToData is a wrapper around g_key_file_to_data().
func (kf *KeyFile) ToData() (uint64, string, error) {
var clength C.gsize
var cerr *C.GError
c := C.g_key_file_to_data(kf.cKey, &clength, &cerr)
defer C.g_free(C.gpointer(c))
return uint64(clength), C.GoString((*C.char)(c)), goError(cerr)
}
作者:sq
项目:godoc
// LoadFromFile is a wrapper around g_key_file_load_from_file().
func (kf *KeyFile) LoadFromFile(file string, flags Flags) (bool, error) {
var cstr = C.CString(file)
defer C.g_free(C.gpointer(cstr))
var cerr *C.GError
c := C.g_key_file_load_from_file(kf.cKey, (*C.gchar)(cstr), C.GKeyFileFlags(flags), &cerr)
return c != 0, goError(cerr)
}
作者:sq
项目:godoc
// Get gets a value from the keyfile. Must be used with a pointer to value.
//
func (kf *KeyFile) Get(group string, key string, val interface{}) error {
switch ptr := val.(type) {
case *[]bool:
cast, e := kf.ListBool(group, key)
*ptr = cast
return e
case *[]int:
cast, e := kf.ListInt(group, key)
*ptr = cast
return e
case *[]float64:
cast, e := kf.ListFloat(group, key)
*ptr = cast
return e
case *[]string:
cast, e := kf.ListString(group, key)
*ptr = cast
return e
}
cGroup := (*C.gchar)(C.CString(group))
defer C.g_free(C.gpointer(cGroup))
cKey := (*C.gchar)(C.CString(key))
defer C.g_free(C.gpointer(cKey))
var cErr *C.GError
switch ptr := val.(type) {
case *bool:
*ptr = goBool(C.g_key_file_get_boolean(kf.cKey, cGroup, cKey, &cErr))
case *int:
*ptr = int(C.g_key_file_get_integer(kf.cKey, cGroup, cKey, &cErr))
case *float64:
*ptr = float64(C.g_key_file_get_double(kf.cKey, cGroup, cKey, &cErr))
case *string:
cstr := C.g_key_file_get_string(kf.cKey, cGroup, cKey, &cErr)
*ptr = C.GoString((*C.char)(cstr))
C.g_free(C.gpointer(cstr))
}
return goError(cErr)
}
作者:revmisch
项目:gs
// MT safe.
func (o *GstObj) GetName() string {
s := C.gst_object_get_name(o.g())
if s == nil {
return ""
}
defer C.g_free(C.gpointer(s))
return C.GoString((*C.char)(s))
}
作者:sq
项目:godoc
// GetOne returns a key value as interface.
//
// valid types are:
// bool, int, float64, string, comment
// listbool, listint, listfloat64, liststring,
//
func (kf *KeyFile) GetOne(group string, key string, typ string) (interface{}, error) {
switch typ {
case "listbool":
return kf.ListBool(group, key)
case "listint":
return kf.ListInt(group, key)
case "listfloat64":
return kf.ListFloat(group, key)
case "liststring":
return kf.ListString(group, key)
}
cGroup := (*C.gchar)(C.CString(group))
defer C.g_free(C.gpointer(cGroup))
cKey := (*C.gchar)(C.CString(key))
defer C.g_free(C.gpointer(cKey))
var cErr *C.GError
var c interface{}
switch typ {
case "bool":
c = goBool(C.g_key_file_get_boolean(kf.cKey, cGroup, cKey, &cErr))
case "int":
c = int(C.g_key_file_get_integer(kf.cKey, cGroup, cKey, &cErr))
case "float64":
c = float64(C.g_key_file_get_double(kf.cKey, cGroup, cKey, &cErr))
case "comment":
cstr := C.g_key_file_get_comment(kf.cKey, cGroup, cKey, &cErr)
c = C.GoString((*C.char)(cstr))
C.g_free(C.gpointer(cstr))
case "string":
cstr := C.g_key_file_get_string(kf.cKey, cGroup, cKey, &cErr)
c = C.GoString((*C.char)(cstr))
C.g_free(C.gpointer(cstr))
}
return c, goError(cErr)
}
作者:sq
项目:godoc
// ListString is a wrapper around g_key_file_get_string_list().
func (kf *KeyFile) ListString(group string, key string) ([]string, error) {
length, c, e := kf.getList(group, key, "string")
defer C.g_free(c)
list := make([]string, length)
for i := range list {
list[i] = C.GoString((*(*[999999]*C.char)(c))[i])
}
return list, e
}
作者:sq
项目:godoc
// ListInt is a wrapper around g_key_file_get_integer_list().
func (kf *KeyFile) ListInt(group string, key string) ([]int, error) {
length, c, e := kf.getList(group, key, "int")
defer C.g_free(c)
list := make([]int, length)
for i := range list {
list[i] = int((*(*[999999]C.int)(c))[i])
}
return list, e
}
作者:sq
项目:godoc
// ListFloat is a wrapper around g_key_file_get_double_list().
func (kf *KeyFile) ListFloat(group string, key string) ([]float64, error) {
// var c C.gpointer
length, c, e := kf.getList(group, key, "float64")
defer C.g_free(c)
list := make([]float64, length)
for i := range list {
list[i] = float64((*(*[999999]C.double)(c))[i])
}
return list, e
}
作者:sq
项目:godoc
// ListBool is a wrapper around g_key_file_get_boolean_list().
func (kf *KeyFile) ListBool(group string, key string) ([]bool, error) {
// var c C.gpointer
length, c, e := kf.getList(group, key, "bool")
defer C.g_free(c)
list := make([]bool, length)
for i := range list {
list[i] = (*(*[999999]C.int)(c))[i] != 0
}
return list, e
}
作者:spreadspac
项目:go-gstreame
// ParseWarning() is a wrapper around gst_message_parse_warning().
func (v *Message) ParseWarning() (err error, debug string) {
var e *C.GError
var d *C.gchar
C.gst_message_parse_warning(v.native(), &e, &d)
eMessage := C.GoString((*C.char)(e.message))
defer C.g_error_free(e)
debug = C.GoString((*C.char)(d))
defer C.g_free((C.gpointer)(d))
return errors.New(eMessage), debug
}
作者:gotk
项目:gi
//Loads the content of the file into memory. The data is always zero-terminated, but this is not included in the resultant length . The returned content should be freed with g_free() when no longer needed.
//If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned.
func (v *File) LoadContents(cancellable *Cancellable) (text string, ok bool) {
contents := new(*C.char)
length := new(C.gsize)
c := C.g_file_load_contents(v.native(), cancellable.native(), contents, length, nil, nil)
ok = gobool(c)
text = C.GoStringN((*C.char)(*contents), (C.int)(*length))
C.g_free((C.gpointer)(contents))
return
}
作者:gotk
项目:gi
//Opens the given files.
//In essence, this results in the “open” signal being emitted in the primary instance.
//n_files must be greater than zero.
//hint is simply passed through to the ::open signal. It is intended to be used by applications that have multiple modes for opening files (eg: "view" vs "edit", etc). Unless you have a need for this functionality, you should use "".
//The application must be registered before calling this function and it must have the G_APPLICATION_HANDLES_OPEN flag set.
func (v *Application) Open(files []*File, hint string) {
gfiles := C.alloc_files(C.int(len(files)))
for n, val := range files {
C.set_file(gfiles, C.int(n), val.native())
}
defer C.g_free(C.gpointer(gfiles))
cstr_hint := C.CString(hint)
defer C.free(unsafe.Pointer(cstr_hint))
C.g_application_open(v.native(), gfiles, C.gint(len(files)), (*C.gchar)(cstr_hint))
}
作者:partkyl
项目:go-gmim
func allocateContentEncoder() *contentEncoding {
ptr := C.alloc_gmime_encoding()
obj := &contentEncoding{
Pointer: ptr,
}
runtime.SetFinalizer(obj, func(o *contentEncoding) {
C.g_free((C.gpointer)(unsafe.Pointer(o.Pointer)))
})
return obj
}
作者:dradtk
项目:gog
func GetInfos(namespace string) []*GiInfo {
_namespace := GlibString(namespace)
defer C.g_free((C.gpointer)(_namespace))
raw_list := GListToGo(C.get_infos(_namespace))
results := make([]*GiInfo, raw_list.Len())
for i, e := 0, raw_list.Front(); e != nil; i, e = i+1, e.Next() {
ptr := (*C.GIBaseInfo)(e.Value.(C.gpointer))
results[i] = NewGiInfo(ptr)
}
return results
}
作者:greu
项目:bim
func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
defer C.g_object_unref(C.gpointer(image))
tmpImage, err := vipsPreSave(image, &o)
if err != nil {
return nil, err
}
// When an image has an unsupported color space, vipsPreSave
// returns the pointer of the image passed to it unmodified.
// When this occurs, we must take care to not dereference the
// original image a second time; we may otherwise erroneously
// free the object twice.
if tmpImage != image {
defer C.g_object_unref(C.gpointer(tmpImage))
}
length := C.size_t(0)
saveErr := C.int(0)
interlace := C.int(boolToInt(o.Interlace))
quality := C.int(o.Quality)
var ptr unsafe.Pointer
switch o.Type {
case WEBP:
saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, 1, quality)
break
case PNG:
saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, 1, C.int(o.Compression), quality, interlace)
break
case GIF:
return nil, errors.New("VIPS cannot save to GIF")
case PDF:
return nil, errors.New("VIPS cannot save to PDF")
case SVG:
return nil, errors.New("VIPS cannot save to SVG")
default:
saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, 1, quality, interlace)
break
}
if int(saveErr) != 0 {
return nil, catchVipsError()
}
buf := C.GoBytes(ptr, C.int(length))
// Clean up
C.g_free(C.gpointer(ptr))
C.vips_error_clear()
return buf, nil
}