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

proposal: cmd/cgo: support bulk annotation of C functions with attributes #71833

Open
horenmar opened this issue Feb 19, 2025 · 0 comments
Open
Labels
Proposal ToolProposal Issues describing a requested change to a Go tool or command-line program.
Milestone

Comments

@horenmar
Copy link

Proposal Details

Currently the noescape and nocallback annotations have to be applied to each function individually.

This leads to people having over 300 lines of annotations in their code as they try to get better codegen for their wrappers of C libraries.

As the best practice for C APIs is to "namespace" them with a prefix refering to the library they are from, I suggest adding simple glob support to the function name part of annotations, so users could write

#cgo nocallback FooLib_*

and mark all functions from FooLib used in this file as nocallback.

The downside to this is the potential to glob functions where the annotation is not correct, but I do not think this is more error prone than having users automate generating the 100+ annotations they need in a file via external tooling.


Alternative direction would be to lean into the automated generation side, and support having these annotations be specified in an external file, that the users can autogenerate, instead of having to add these into each file where they wrap the C API. I prefer the globbing option, as that seems more inline with the current design of cgo directives.

@gopherbot gopherbot added this to the Proposal milestone Feb 19, 2025
@gabyhelp gabyhelp added the ToolProposal Issues describing a requested change to a Go tool or command-line program. label Feb 19, 2025
@seankhliao seankhliao changed the title proposal: cmd/cgo: Support bulk annotation of C functions with attributes proposal: cmd/cgo: support bulk annotation of C functions with attributes Feb 19, 2025
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Proposal ToolProposal Issues describing a requested change to a Go tool or command-line program.
Projects
Status: Incoming
Development

No branches or pull requests

3 participants