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

Broken code generated for libraw1394 #178

Open
tjamet opened this issue Jan 29, 2025 · 0 comments
Open

Broken code generated for libraw1394 #178

tjamet opened this issue Jan 29, 2025 · 0 comments

Comments

@tjamet
Copy link

tjamet commented Jan 29, 2025

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);
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