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

Wrapping an extern "C" function #50

Closed
ewpratten opened this issue Apr 13, 2023 · 3 comments
Closed

Wrapping an extern "C" function #50

ewpratten opened this issue Apr 13, 2023 · 3 comments

Comments

@ewpratten
Copy link

I would like to be able to profile some extern "C" functions.

Currently, if I try to apply the #[profiling::function] macro to one of these functions, I get an error:

extern "C" {
    #[profiling::function]
    pub fn MyFunction(x: Data);
}
error: expected curly braces

Is there any way to do this without wrapping every external function in a Rust function first?

@aclysma
Copy link
Owner

aclysma commented Apr 13, 2023

The way the procmacro works is it appends a one-liner to the code in the body of the function. An extern function doesn't have a body, so we can't really inject new behavior into it. I suspect any solution for this would ultimately behind the scenes just wrap the call in a rust function.

I try to keep procmacros extremely straightforward and use them sparingly, and I think the cost/benefit ratio for this would be outside my comfort zone. (I'd keep an open mind if you wanted to give it a try though.)

@ewpratten
Copy link
Author

Ah, I figured.

I'm going to try auto-wrapping the functions then.

@aclysma
Copy link
Owner

aclysma commented Dec 9, 2023

Since this has been idle for a while and I'm not optimistic a solution would be simple, going to close.

@aclysma aclysma closed this as completed Dec 9, 2023
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

2 participants