rust-lang / rust-lang/rust-bindgen

Incorrect bitstream length

Open
#3,238 2 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

See the attached rust crate, which generates a binding for a simple structure in a c99 h file.

When the cargo build command is run, build.rs generates a binding file, which is included in lib.rs

the binding file creates struct resource which has two bitfields. the second is

    pub _bitfield_2: __BindgenBitfieldUnit<[u8; 7usize]>,

i believe that bitfield should be 6 bytes wide (containing struct members r, s, t, u, v, w, x, y, and z, and totaling 48 bits). that bitfield is 7 bytes wide which causes the build to fail. is this a bug in bindgen or have i missed something?

Thank you for your attention.

bindgenbug.zip

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 with the attached crate, especially build.rs and lib.rs, and run cargo build to reproduce the generated binding and failure. Inspect how bindgen represents the resource bitfields, then compare the generated __BindgenBitfieldUnit width with the C99 structure's 48-bit second field; done means the binding is generated with the correct size and the crate builds.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.