Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to handle zero size array field in struct #122

Open
andypeng2015 opened this issue Jun 17, 2022 · 1 comment
Open

how to handle zero size array field in struct #122

andypeng2015 opened this issue Jun 17, 2022 · 1 comment

Comments

@andypeng2015
Copy link

go version go1.17.11 darwin/amd64
OS macOS Big Sur 11.4

when I run

| => cd bindings/x86/
| => ~/go/bin/c-for-go gen.yml
| => mv -v ./x86/* .
| => go test .
# github.com/andypeng2015/test/bindings/x86
./cgo_helpers.go:272:13: ref3fccfd0e.coalesced_mmio undefined (type *_Ctype_struct_kvm_coalesced_mmio_ring has no field or method coalesced_mmio)
./cgo_helpers.go:272:53: cannot assign [0]_Ctype_struct_kvm_coalesced_mmio to ref3fccfd0e.coalesced_mmio in multiple assignment
./cgo_helpers.go:298:108: x.ref3fccfd0e.coalesced_mmio undefined (type *_Ctype_struct_kvm_coalesced_mmio_ring has no field or method coalesced_mmio)
./cgo_helpers.go:402:13: refde42b52b.entries undefined (type *_Ctype_struct_kvm_cpuid has no field or method entries)
./cgo_helpers.go:402:39: cannot assign [0]_Ctype_struct_kvm_cpuid_entry to refde42b52b.entries in multiple assignment
./cgo_helpers.go:428:96: x.refde42b52b.entries undefined (type *_Ctype_struct_kvm_cpuid has no field or method entries)
FAIL    github.com/andypeng2015/test/bindings/x86 [build failed]
FAIL
// code generated by c-for-go
// from ~/Library/Caches/go-build

type _Ctype_struct_kvm_coalesced_mmio_ring struct {
	first	_Ctype___u32
	last	_Ctype___u32
}

type _Ctype_struct_kvm_cpuid struct {
	nent	_Ctype___u32
	padding	_Ctype___u32
}

type _Ctype_struct_kvm_cpuid_entry struct {
	function	_Ctype___u32
	eax		_Ctype___u32
	ebx		_Ctype___u32
	ecx		_Ctype___u32
	edx		_Ctype___u32
	padding		_Ctype___u32
}
struct kvm_coalesced_mmio_ring {
	__u32 first, last;
	struct kvm_coalesced_mmio coalesced_mmio[0];
};

struct kvm_cpuid {
	__u32 nent;
	__u32 padding;
	struct kvm_cpuid_entry entries[0];
};

source code attached
test.zip

pls advise, thanks

@andypeng2015
Copy link
Author

I believe it's caused by zero size array.

I also tried MemTips below, but still got error, not sure how to handle this properly, please kindly advise @xlab thanks

MemTips:
    - {target: "^kvm_coalesced_mmio", self: raw}
    - {target: "^kvm_cpuid", self: raw}
processing gen.yml ⠋[WARN] cannot gofmt x86/cgo_helpers.go: x86/cgo_helpers.go:239:82: expected operand, found '&&' (and 10 more errors)

Screenshot 2022-06-20 at 11 14 07 AM

@andypeng2015 andypeng2015 changed the title C struct undefined (type *_Ctype_struct_xxx has no field or method xxx) how to handle zero size array field in struct Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant