Skip to content

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

Open
@horenmar

Description

@horenmar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ProposalToolProposalIssues describing a requested change to a Go tool or command-line program.

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions