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

Implement an analog of C99's __func__ #5547

Closed
artob opened this issue Jun 6, 2020 · 1 comment
Closed

Implement an analog of C99's __func__ #5547

artob opened this issue Jun 6, 2020 · 1 comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@artob
Copy link

artob commented Jun 6, 2020

Right now, the lack of an analog for C99's __func__ (aka __FUNCTION__ in GCC) leads to painful error-handling code at API boundaries (see below) as well as to inadvertent copy-paste errors since function names are hardcoded as string literals all over the place and it's easy to miss cases when the string isn't correct.

A concrete, simplified example from a C API that I'm developing, where we must write out the function name as a string literal once per each invocation of error handler:

pub export fn fooCreateContext(version: u64, flags: u64, context: ?*foo.context) foo.status {
    if (version > 0) return status.invalidArgument("fooCreateContext", "version");
    if (flags != 0) return status.invalidArgument("fooCreateContext", "flags");
    if (context == null) return status.invalidArgument("fooCreateContext", "context");

(Wherein status.invalidArgument in turn invokes a user-supplied error callback hook that needs to be able to report the function name whence the error originated.)

Related issue: #2029

@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Jun 18, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Jun 18, 2020
@andrewrk
Copy link
Member

#2029 has been accepted, and so this proposal is no longer needed. Once it is implemented:

pub export fn fooCreateContext(version: u64, flags: u64, context: ?*foo.context) foo.status {
    if (version > 0) return status.invalidArgument(@src().fn_name, "version");
    if (flags != 0) return status.invalidArgument(@src().fn_name, "flags");
    if (context == null) return status.invalidArgument(@src().fn_name, "context");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

2 participants