Skip to content

Commit

Permalink
Add unsafe to extern build scripts in Cargo Book
Browse files Browse the repository at this point in the history
  • Loading branch information
namanlp committed Mar 10, 2025
1 parent 340d123 commit a255e30
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/doc/src/reference/build-script-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void hello() {
// Note the lack of the `#[link]` attribute. We’re delegating the responsibility
// of selecting what to link over to the build script rather than hard-coding
// it in the source file.
extern { fn hello(); }
unsafe extern { fn hello(); }
fn main() {
unsafe { hello(); }
Expand Down Expand Up @@ -327,7 +327,7 @@ Let's round out the example with a basic FFI binding:
use std::os::raw::{c_uint, c_ulong};
extern "C" {
unsafe extern "C" {
pub fn crc32(crc: c_ulong, buf: *const u8, len: c_uint) -> c_ulong;
}
Expand Down
6 changes: 3 additions & 3 deletions src/doc/src/reference/semver.md
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ pub struct SpecificLayout {
// Example usage that will break.
use updated_crate::SpecificLayout;
extern "C" {
unsafe extern "C" {
// This C function is assuming a specific layout defined in a C header.
fn c_fn_get_b(x: &SpecificLayout) -> u32;
}
Expand Down Expand Up @@ -820,7 +820,7 @@ pub struct SpecificLayout {
// Example usage that will break.
use updated_crate::SpecificLayout;
extern "C" {
unsafe extern "C" {
// This C function is assuming a specific layout defined in a C header.
fn c_fn_get_b(x: &SpecificLayout) -> u32; // Error: is not FFI-safe
}
Expand Down Expand Up @@ -941,7 +941,7 @@ pub struct Transparent<T>(T);
#![deny(improper_ctypes)]
use updated_crate::Transparent;
extern "C" {
unsafe extern "C" {
fn c_fn() -> Transparent<f64>; // Error: is not FFI-safe
}
Expand Down

0 comments on commit a255e30

Please sign in to comment.