Warn when exporting a non-extern-C function pointer
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
Research direction
Start by reproducing the provided Rust example and C output with cbindgen, then trace the handling of function-pointer fields and ABI declarations. Done means cbindgen emits a warning when a non-extern-C Rust function pointer is exported, while extern "C" pointers remain accepted.
Written by the indexing model from the issue text.
Description
#[repr(C)]
pub struct Payload {
data: [u8; 128],
}
#[repr(C)]
pub struct Example {
callback: /* extern "C" */ fn(a: Payload, b: Payload),
}
#[unsafe(no_mangle)]
pub extern "C" fn test(input: Example) {}
cbindgen-ing this code (for C) produces
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct Payload {
uint8_t data[128];
} Payload;
typedef struct Example {
void (*callback)(struct Payload a, struct Payload b);
} Example;
void test(struct Example input);
with no warnings or errors. However, the ABI for callback isn't necessarily the same in C and Rust without the extern "C". (I recently ran into this, and was confused why my structs-passed-by-value had garbage in them until I tracked down my mistake.)
Related: #24, #55, #132.
- Dominant language
- Rust
- Stars
- 3k
- Forks
- 386
- Avg merge
- 1h 43m
- Merged PRs (30d)
- 1
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.
More from mozilla/cbindgen
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
All issues in mozilla/cbindgen
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100