rust-lang / rust-lang/rust-bindgen
wrap_static_fns adds extra incorrect 'const' to pointer parameters
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Hi,
I have the following static inline C function (from the ARM CMSIS):
__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority)
{
*pPreemptPriority = ...;
*pSubPriority = ...;
}
I'm using .wrap_static_fns(true) to generate a C wrapper for this.
However, the wrapper that's generated is:
void NVIC_DecodePriority__extern(uint32_t Priority, uint32_t PriorityGroup, const uint32_t *const pPreemptPriority, const uint32_t *const pSubPriority)
{
NVIC_DecodePriority(Priority, PriorityGroup, pPreemptPriority, pSubPriority);
}
The pPreemptPriority and pSubPriority parameters have gained an extra const, turning them into pointer-to-const. This causes the C compiler to raise warnings.
The Rust binding however looks fine:
#[link_name = "NVIC_DecodePriority__extern"]
pub fn NVIC_DecodePriority(
Priority: u32,
PriorityGroup: u32,
pPreemptPriority: *mut u32,
pSubPriority: *mut u32,
);
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the ARM CMSIS declaration and .wrap_static_fns(true). Trace the static-function wrapper generation and add a regression test covering uint32_t* const parameters, then verify that the generated C preserves mutable pointers and compiles without the reported warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100