-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff5fdfa
commit b050c73
Showing
11 changed files
with
123 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package girepository | ||
|
||
// #include <girepository.h> | ||
import "C" | ||
|
||
import ( | ||
"log" | ||
"reflect" | ||
"strings" | ||
"unsafe" | ||
) | ||
|
||
func trimNull(str string) string { | ||
return strings.TrimSuffix(str, "\x00") | ||
} | ||
|
||
func unsafeCStr(gostr *string) *C.gchar { | ||
if len(*gostr) == 0 { | ||
return nil | ||
} | ||
|
||
if (*gostr)[len(*gostr)-1] != 0 { | ||
log.Panicf("Go string %q should be null-terminated with \\x00", *gostr) | ||
} | ||
|
||
header := (*reflect.StringHeader)(unsafe.Pointer(gostr)) | ||
return (*C.gchar)(unsafe.Pointer(header.Data)) | ||
} | ||
|
||
func cpyCStr(cptr *C.gchar, gostr string) (next *C.gchar) { | ||
cbytes := unsafe.Slice((*byte)(unsafe.Pointer(cptr)), len(gostr)+1) | ||
copy(cbytes, []byte(gostr)) | ||
cbytes[len(gostr)] = 0 | ||
|
||
return (*C.gchar)(unsafe.Add(unsafe.Pointer(cptr), len(cbytes))) | ||
} | ||
|
||
func cstr2bytes[T IntegerType](cstr *C.gchar, len int) []byte { | ||
return unsafe.Slice((*byte)(unsafe.Pointer(cptr)), len) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.