c-for-go
c-for-go copied to clipboard
Broken code generated for libraw1394
Hi!
I am trying to use this project to generate the bindings of libraw1394.
When using the following description, I got 2 errors after running c-for-go -ccdefs -ccincl -debug -fancy -out=pkg pkg/raw1394.yaml.
GENERATOR:
PackageName: raw1394
PackageDescription: "Package raw1394 provides the bindings to the raw1394 library."
PackageLicense: "THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS."
PkgConfigOpts: [libraw1394]
SysIncludes: [libraw1394/raw1394.h]
PARSER:
IncludePaths: [/usr/include, /usr/include]
SourcesPaths: [libraw1394/raw1394.h, libraw1394/ieee1394.h, libraw1394/csr.h]
TRANSLATOR:
ConstRules:
defines: expand
enum: cgo
Rules:
global:
- {transform: lower}
- {action: accept, from: "^(raw1394)_"}
- {action: transform, from: "^raw1394_", to: ""}
- {transform: export}
type:
- {action: replace, from: "_t$"}
private:
- {transform: unexport}
post-global:
- {action: replace, from: _$}
- {load: snakecase}
First, the command emits a warning processing pkg/raw1394.yaml ⠙[WARN] cannot gofmt pkg/raw1394/raw1394.go: pkg/raw1394/raw1394.go:422:80: expected '(', found '{' (and 1 more errors)
The generated raw1394.go contains indeed syntax errors:
// Raw1394SetBusResetHandler function as declared in libraw1394/raw1394.h:653
func Raw1394SetBusResetHandler(handle Raw1394Handle, newH BusResetHandler) func{
chandle, chandleAllocMap := *(*C.struct_raw1394_handle)(unsafe.Pointer(&handle)), cgoAllocsUnknown
cnewH, cnewHAllocMap := newH.PassValue()
__ret := C.raw1394_set_bus_reset_handler(chandle, cnewH)
runtime.KeepAlive(cnewHAllocMap)
runtime.KeepAlive(chandleAllocMap)
__v := *NewRef(unsafe.Pointer(&__ret))
return __v
}
After ignoring it with the instruction - {action: ignore, from: ".*handler$"}, the generated go code seems valid but the c helper header cgo_helpers.h gets a syntax error:
./cgo_helpers.h:21:8: error: expected identifier before 'int'
21 | enum {int RAW1394_ISO_OK = C.RAW1394_ISO_OK,
| ^~~
cgo-dwarf-inference:1:17: error: expected '{' before ')' token
here is the generated code:
// raw1394_iso_xmit_handler_t_9440902a is a proxy for callback raw1394_iso_xmit_handler_t.
enum {int RAW1394_ISO_OK = C.RAW1394_ISO_OK,
int RAW1394_ISO_DEFER = C.RAW1394_ISO_DEFER,
int RAW1394_ISO_ERROR = C.RAW1394_ISO_ERROR,
int RAW1394_ISO_STOP = C.RAW1394_ISO_STOP,
int RAW1394_ISO_STOP_NOSYNC = C.RAW1394_ISO_STOP_NOSYNC,
int RAW1394_ISO_AGAIN = C.RAW1394_ISO_AGAIN} raw1394_iso_xmit_handler_t_9440902a(struct raw1394_handle handle, unsigned char* data, unsigned int* len, unsigned char* tag, unsigned char* sy, int cycle, unsigned int dropped);