3 ms·
It is still useless for me if you have struct with 'packed' attribute ie: http://lxr.free-electrons.com/source/fs/btrfs/ctree.h#L220 http://lxr.free-electrons.c
by laxk 11y ago
It is still useless for me if you have struct with 'packed' attribute
ie: http://lxr.free-electrons.com/source/fs/btrfs/ctree.h#L220 http://lxr.free-electrons.com/source/fs/btrfs/ctree.h#L220
// +build ignore
package tmp
/*
#include <btrfs/ctree.h>
*/
import "C"
// 220 struct btrfs_disk_key {
// 221 __le64 objectid;
// 222 u8 type;
// 223 __le64 offset;
// 224 } __attribute__ ((__packed__));
type BtrfsDiskKey C.struct_btrfs_disk_key
Output:
$ go tool cgo -godefs test.go
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs test.go
package tmp
type BtrfsDiskKey struct {
Objectid uint64
Type uint8
Pad_cgo_0 [8]byte
}
After all the experiments I created my own helper[1], which helps map C structure(even packed) to Go structure using reflect package.
[1] https://github.com/plar/btrfs/blob/master/ioctl/mappings.go https://github.com/plar/btrfs/blob/master/ioctl/mappings.go
- _pmf_ 11y ago> It is still useless for me if you have struct with 'packed' attribute It's somewhat sad that LuaJIT (effectively a one man project) contains a FFI interface with a hand-crafted lexer and tokenizer that supports the packed attribute correctly.