FAQ
Hi all

I am working on a lvm2 binding for go.

The most stuff works well now, but when I call the function
lvm_vg_get_property the go compiler crashes.

in Go I have something like

func Lvm2_vg_get_property(vg C.vg_t, property string) {
xyz := C.lvm_vg_get_property(vg, C.CString(string))
}

in C the function is defined in /usr/include/lvm2app.h
struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char
*name);
it will return a lvm_property_value struct also defined in lvm2app.h

typedef struct lvm_property_value {
uint32_t is_settable:1;
uint32_t is_string:1;
uint32_t is_integer:1;
uint32_t is_valid:1;
uint32_t padding:28;
union {
const char *string;
uint64_t integer;
} value;
} lvm_property_value_t;


when I call go build it tells me

bash-4.1$ go build src/pfch/lvm.go
# pfch/golvm
panic: runtime error: integer divide by zero
[signal 0x8 code=0x1 addr=0x41d0e0 pc=0x41d0e0]
goroutine 1 [running]:
main.(*Package).structType(0xf840095000, 0xf840048b80, 0xf8400c7a60, 0x1a,
0xf8400c4101, ...)
/var/lib/jenkins/workspace/LINUX_go/label/rhel6-rpm/build/BUILD/go-1.0.2/go/src/cmd/cgo/out.go:219
+0xd75
main.(*Package).writeOutputFunc(0xf840095000, 0xf8400789f0, 0xf840048b80,
0xa732500000013, 0xf840048b80, ...)
/var/lib/jenkins/workspace/LINUX_go/label/rhel6-rpm/build/BUILD/go-1.0.2/go/src/cmd/cgo/out.go:403
+0x218
main.(*Package).writeOutput(0xf840095000, 0xf840097060, 0x7fffb35ff684,
0x6570797400000008, 0x2fffffffff, ...)
/var/lib/jenkins/workspace/LINUX_go/label/rhel6-rpm/build/BUILD/go-1.0.2/go/src/cmd/cgo/out.go:381
+0x866
main.main()
/var/lib/jenkins/workspace/LINUX_go/label/rhel6-rpm/build/BUILD/go-1.0.2/go/src/cmd/cgo/main.go:260
+0xe40
goroutine 2 [syscall]:
created by runtime.main
/var/lib/jenkins/workspace/LINUX_go/label/rhel6-rpm/build/BUILD/go-1.0.2/go/src/pkg/runtime/proc.c:221
goroutine 9 [finalizer wait]:
created by runtime.gc
/var/lib/jenkins/workspace/LINUX_go/label/rhel6-rpm/build/BUILD/go-1.0.2/go/src/pkg/runtime/mgc0.c:882
bash-4.1$

I am using go version 1.02
bash-4.1$ go version
go version go1.0.2

Has anyone an Idea how to realize the function call? I think the problem is
the struct with bitfields and a union in C.
The only idea I have is to write a wrapper for the function in C. But
that's like ..... you now....
Is there another way?

Thanks

Tom






--

Search Discussions

  • Jan Mercl at Sep 20, 2012 at 7:29 am

    On Thu, Sep 20, 2012 at 8:48 AM, wrote:

    in Go I have something like

    func Lvm2_vg_get_property(vg C.vg_t, property string) {
    xyz := C.lvm_vg_get_property(vg, C.CString(string))
    } ...
    Has anyone an Idea how to realize the function call? I think the problem is
    the struct with bitfields and a union in C.
    I see no checks of the 'is_valid' nor 'is_string' fields.

    -j


    The only idea I have is to write a wrapper for the function in C. But that's
    like ..... you now....
    Is there another way?

    Thanks

    Tom






    --
    --
  • Thomas at Sep 20, 2012 at 9:24 am
    I see no checks of the 'is_valid' nor 'is_string' fields.
    Thats true, because I don't get the struct back. Go crashes just after the
    function call.
    xyz should contain the struct but it's just an example here. Go should not
    crash. At least not at compile time!



    Am Donnerstag, 20. September 2012 09:29:50 UTC+2 schrieb Jan Mercl:
    On Thu, Sep 20, 2012 at 8:48 AM, <tho...@xn--bhler-gra.ch <javascript:>>
    wrote:
    in Go I have something like

    func Lvm2_vg_get_property(vg C.vg_t, property string) {
    xyz := C.lvm_vg_get_property(vg, C.CString(string))
    } ...
    Has anyone an Idea how to realize the function call? I think the problem is
    the struct with bitfields and a union in C.
    I see no checks of the 'is_valid' nor 'is_string' fields.

    -j


    The only idea I have is to write a wrapper for the function in C. But that's
    like ..... you now....
    Is there another way?

    Thanks

    Tom






    --
    --
  • Jan Mercl at Sep 20, 2012 at 9:58 am

    On Thu, Sep 20, 2012 at 9:52 AM, wrote:
    I see no checks of the 'is_valid' nor 'is_string' fields.
    Thats true, because I don't get the struct back. Go crashes just after the
    function call.
    xyz should contain the struct but it's just an example here. Go should not
    crash. At least not at compile time!
    My bad, I totally missed it's not a runtime crash.

    Looking again at:

    func Lvm2_vg_get_property(vg C.vg_t, property string) {
    xyz := C.lvm_vg_get_property(vg, C.CString(string))
    }

    What's that 'C.CString(string)'? Did you mean:

    func Lvm2_vg_get_property(vg C.vg_t, property string) {
    xyz := C.lvm_vg_get_property(vg, C.CString(property))
    }

    ?

    If that's the culprit then you've probably run in a cgo bug.

    -j

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 20, '12 at 7:11a
activeSep 20, '12 at 9:58a
posts4
users2
websitegolang.org

2 users in discussion

Thomas: 2 posts Jan Mercl: 2 posts

People

Translate

site design / logo © 2022 Grokbase