Skip to content

Commit b19e559

Browse files
Switch from #[no_mangle] to #[unsafe(no_mangle)]
This is in preparation for switching to the 2024 edition.
1 parent a8f94ed commit b19e559

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Now, add your function signature:
6969
```rust
7070
use core::ffi::{c_char, c_int};
7171

72-
#[no_mangle]
72+
#[unsafe(no_mangle)]
7373
unsafe extern "C" fn c_library_print(str: *const c_char, args: ...) -> c_int {
7474
todo!()
7575
}
@@ -78,13 +78,13 @@ unsafe extern "C" fn c_library_print(str: *const c_char, args: ...) -> c_int {
7878
Think about what you're doing:
7979

8080
- If you're implenting `printf` *because you don't have one*, you'll want to
81-
call it `printf` and add `#[no_mangle]`.
81+
call it `printf` and add `#[unsafe(no_mangle)]`.
8282
- Likewise, if you're creating a custom log function for a C library and it
83-
expects to call a globally-defined function, keep `#[no_mangle]` and
83+
expects to call a globally-defined function, keep `#[unsafe(no_mangle)]` and
8484
rename the function to what it expects.
8585
- On the other hand, if your C library expects you to call a function to
8686
register a callback ([example 1][sigrok-log], [example 2][libusb-log]),
87-
remove `#[no_mangle]`.
87+
remove `#[unsafe(no_mangle)]`.
8888

8989
Now, add your logic:
9090

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
//! # #![feature(c_variadic)]
6666
//! use core::ffi::{c_char, c_int};
6767
//!
68-
//! #[no_mangle]
68+
//! #[unsafe(no_mangle)]
6969
//! unsafe extern "C" fn c_library_print(str: *const c_char, args: ...) -> c_int {
7070
//! todo!()
7171
//! }
@@ -74,20 +74,20 @@
7474
//! Think about what you're doing:
7575
//!
7676
//! - If you're implenting `printf` *because you don't have one*, you'll want to
77-
//! call it `printf` and add `#[no_mangle]`.
77+
//! call it `printf` and add `#[unsafe(no_mangle)]`.
7878
//! - Likewise, if you're creating a custom log function for a C library and it
79-
//! expects to call a globally-defined function, keep `#[no_mangle]` and
79+
//! expects to call a globally-defined function, keep `#[unsafe(no_mangle)]` and
8080
//! rename the function to what it expects.
8181
//! - On the other hand, if your C library expects you to call a function to
8282
//! register a callback ([example 1][sigrok-log], [example 2][libusb-log]),
83-
//! remove `#[no_mangle]`.
83+
//! remove `#[unsafe(no_mangle)]`.
8484
//!
8585
//! Now, add your logic:
8686
//!
8787
//! ```rust
8888
//! # #![feature(c_variadic)]
8989
//! # use core::ffi::{c_char, c_int};
90-
//! # #[no_mangle]
90+
//! # #[unsafe(no_mangle)]
9191
//! # unsafe extern "C" fn c_library_print(str: *const c_char, args: ...) -> c_int {
9292
//! use printf_compat::{format, output};
9393
//! let mut s = String::new();

src/output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub unsafe fn display<'a>(format: *const c_char, va_list: VaList<'a>) -> VaListD
323323
///
324324
/// use core::ffi::{c_char, c_int};
325325
///
326-
/// #[no_mangle]
326+
/// #[unsafe(no_mangle)]
327327
/// unsafe extern "C" fn c_library_print(str: *const c_char, args: ...) -> c_int {
328328
/// let format = unsafe { printf_compat::output::display(str, args) };
329329
/// println!("{}", format);

0 commit comments

Comments
 (0)