Skip to content

Commit 3fc16c5

Browse files
committed
Add support for unsafe extern blocks
1 parent c4440b3 commit 3fc16c5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

bindgen/codegen/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,14 @@ impl CodeGenerator for Var {
796796
quote! { mut }
797797
};
798798

799+
let safety = ctx
800+
.options()
801+
.rust_features
802+
.unsafe_extern_blocks
803+
.then(|| quote!(unsafe));
804+
799805
let tokens = quote!(
800-
extern "C" {
806+
#safety extern "C" {
801807
#(#attrs)*
802808
pub static #maybe_mut #canonical_ident: #ty;
803809
}
@@ -4670,9 +4676,16 @@ impl CodeGenerator for Function {
46704676
let ret = utils::fnsig_return_ty(ctx, signature);
46714677

46724678
let ident = ctx.rust_ident(ident);
4679+
4680+
let safety = ctx
4681+
.options()
4682+
.rust_features
4683+
.unsafe_extern_blocks
4684+
.then(|| quote!(unsafe));
4685+
46734686
let tokens = quote! {
46744687
#wasm_link_attribute
4675-
extern #abi {
4688+
#safety extern #abi {
46764689
#(#attributes)*
46774690
pub fn #ident ( #( #args ),* ) #ret;
46784691
}

bindgen/features.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ define_rust_targets! {
254254
ptr_metadata: #81513,
255255
layout_for_ptr: #69835,
256256
},
257+
Stable_1_82(82) => {
258+
unsafe_extern_blocks: #127921,
259+
},
257260
Stable_1_77(77) => {
258261
offset_of: #106655,
259262
literal_cstr(2021)|(2024): #117472,

0 commit comments

Comments
 (0)