rust-lang / rust-lang/rust-bindgen

Generation of const pointers

Open
#3,347 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Given the following C heder:

const int* foo = ((int*) 3ULL);

bindgen will generate the following Rust code:

/* automatically generated by rust-bindgen 0.71.1 */

unsafe extern "C" {
    pub static mut foo: *const ::std::os::raw::c_int;
}

The output I would expect (and need) to be generated is the following:

const FOO: *const c_int = 3usize as *const c_int;

Questions

  • Is there any way to configure bindgen to provide the output above?
  • Is the generation of current output a feature or a bug?
    • If it is a feature, what is the rationale behind it?

For context, we are hitting this in the Linux kernel when generating bindings for these kind of pointers.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the minimal C header shown and compare bindgen's generated Rust binding with the requested const pointer declaration. Review bindgen's handling of initialized const pointer globals and determine whether configuration can select the requested form; done means the behavior and rationale are documented or the generated output is corrected with coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.