Skip to content

Support #define old_function new_function #2544

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

Open
davidben opened this issue Jun 5, 2023 · 1 comment
Open

Support #define old_function new_function #2544

davidben opened this issue Jun 5, 2023 · 1 comment
Labels

Comments

@davidben
Copy link

davidben commented Jun 5, 2023

Input C/C++ Header

void new_function_name(void);
#define old_function_name new_function_name

Bindgen Invocation

$ bindgen header.h

Actual Results

/* automatically generated by rust-bindgen 0.65.1 */

extern "C" {
    pub fn new_function_name();
}

Expected Results

Ideally old_function_name would also be available as an alias for new_function_name. This pattern is quite common in C libraries.

In OpenSSL, they like to define compatibility aliases like this:
https://github.com/openssl/openssl/blob/master/include/openssl/x509.h.in#L732-L742

In glibc, these may not even be compatibility aliases but the actual intended public API. E.g. my system headers say:

#   define gmtime_r __gmtime64_r
#   define localtime_r __localtime_r

It's also used to fake something like C++ inline namespace, when you want the symbol to have a prefixed name to avoid collisions, but to support callers writing another.

On the C library authoring side, we would like to do this for deprecated functions in BoringSSL, as it's much less tedious than defining a parallel function or an inline wrapper. But, were we do to this, it would break bindgen output due to bindgen insufficiently faithfully supporting C semantics. Of course, fully faithfully supporting C macros is Hard, but this case seems straightforward and common enough to be worth picking up. (When the destination is a single symbol that is a function you already know to bind.)

One caveat when doing this, the feature should not break things like this:

void foo(void);
#define foo foo

We have to do that sometimes in BoringSSL for... very dumb reasons. :-)

@pvdrz pvdrz added the A-macros label Jun 21, 2023
davidben added a commit to google/boringssl that referenced this issue Jun 26, 2023
The standard macro-based pattern does not work in bindgen because of
rust-lang/rust-bindgen#2544

Change-Id: Ic2b92e779ade2ed55a627bba9c76f7df5c0f6136
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61185
Reviewed-by: Bob Beck <[email protected]>
Commit-Queue: Bob Beck <[email protected]>
Auto-Submit: David Benjamin <[email protected]>
@KarelPeeters
Copy link
Contributor

The cuda headers also do this, for example in cuda v12.2 header cuda_runtime_api.h:

#define cudaGetDeviceProperties cudaGetDeviceProperties_v2

samuel40791765 pushed a commit to samuel40791765/aws-lc that referenced this issue Nov 10, 2023
The standard macro-based pattern does not work in bindgen because of
rust-lang/rust-bindgen#2544

Change-Id: Ic2b92e779ade2ed55a627bba9c76f7df5c0f6136
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61185
Reviewed-by: Bob Beck <[email protected]>
Commit-Queue: Bob Beck <[email protected]>
Auto-Submit: David Benjamin <[email protected]>
(cherry picked from commit 4e88a3557f6a022e30d1ff85fbd87e1173848be2)
samuel40791765 pushed a commit to samuel40791765/aws-lc that referenced this issue Nov 14, 2023
The standard macro-based pattern does not work in bindgen because of
rust-lang/rust-bindgen#2544

Change-Id: Ic2b92e779ade2ed55a627bba9c76f7df5c0f6136
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61185
Reviewed-by: Bob Beck <[email protected]>
Commit-Queue: Bob Beck <[email protected]>
Auto-Submit: David Benjamin <[email protected]>
(cherry picked from commit 4e88a3557f6a022e30d1ff85fbd87e1173848be2)
samuel40791765 pushed a commit to samuel40791765/aws-lc that referenced this issue Nov 14, 2023
The standard macro-based pattern does not work in bindgen because of
rust-lang/rust-bindgen#2544

Change-Id: Ic2b92e779ade2ed55a627bba9c76f7df5c0f6136
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61185
Reviewed-by: Bob Beck <[email protected]>
Commit-Queue: Bob Beck <[email protected]>
Auto-Submit: David Benjamin <[email protected]>
(cherry picked from commit 4e88a3557f6a022e30d1ff85fbd87e1173848be2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants