c-for-go
c-for-go copied to clipboard
Issue when working with typedef'd struct *
I'm attempting to wrap a commercial 3rd party lib and hitting a lot of issues, mostly around typedefs of struct *. Likely I'm missing something in the config/doco but here is a stripped down version:
ll.h
#ifndef LINKED_LIST_H_
#define LINKED_LIST_H_
struct sLinkedList {
void* data;
struct sLinkedList* next;
};
typedef struct sLinkedList* LinkedList;
#endif /* LINKED_LIST_H_ */
ll.yml
GENERATOR:
PackageName: ll
PackageDescription: "Package ll for testing"
PackageLicense: "NO RIGHTS RESERVED"
Includes: ["ll.h"]
Options:
SafeStrings: true
PARSER:
IncludePaths: ["./ll"]
SourcesPaths: ["ll.h"]
TRANSLATOR:
Rules:
global:
- {action: accept, from: "^LinkedList"}
The subsequent 'go build' errors are:
./cgo_helpers.go:123:13: refd49e7347.data undefined (type *_Ctype_LinkedList has no field or method data)
./cgo_helpers.go:147:56: x.refd49e7347.data undefined (type *_Ctype_LinkedList has no field or method data)
That generated code is not aware that the _Ctype_LinkedList is a pointer to the struct and does not dereference it:
...
refd49e7347 := (*C.LinkedList)(memd49e7347)
allocsd49e7347 := new(cgoAllocMap)
allocsd49e7347.Add(memd49e7347)
var cdata_allocs *cgoAllocMap
123> refd49e7347.data, cdata_allocs = *(*unsafe.Pointer)(unsafe.Pointer(&x.data)), cgoAllocsUnknown
Manually editing the cgo_helpers.go to use (**refd49e7347).data and (**x.refd49e7347).data) respectively allows 'go build' to succeed.
If I comment out the LinkedList typedef in ll.h and change the accept to '^sLinkedList' it works as expected.
I've tried many variations of config file without success. Pointers (pun intended) to what I'm missing gratefully accepted.