Skip to content

Commit 9bbc1aa

Browse files
committed
Add #[unsafe()] attribute markers and use &raw instead of addr_of
Both stabilized in Rust 1.82.0, released today This only affects the WASM demo
1 parent e72ddcb commit 9bbc1aa

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

crates/aoc_wasm/src/custom_sections.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ macro_rules! matcher {
4949
mod $day {
5050
use aoc::utils::PuzzleExamples;
5151

52-
#[link_section = "aoc_puzzles"]
52+
#[unsafe(link_section = "aoc_puzzles")]
5353
#[used]
5454
static PUZZLE_LIST: [u8; 6] = [
5555
b'0' + ($y / 1000u16) as u8,
@@ -60,7 +60,7 @@ macro_rules! matcher {
6060
b'0' + $d % 10,
6161
];
6262

63-
#[link_section = concat!("aoc_examples_", stringify!($y), "_", stringify!($d))]
63+
#[unsafe(link_section = concat!("aoc_examples_", stringify!($y), "_", stringify!($d)))]
6464
#[used]
6565
static PUZZLE_EXAMPLES: [u8; super::super::examples_len(aoc::$year::$day::EXAMPLES)]
6666
= super::super::examples_section(aoc::$year::$day::EXAMPLES);

crates/aoc_wasm/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! Simple WebAssembly interface without external libraries.
2-
32
mod custom_sections;
43
#[cfg(feature = "multithreading")]
54
mod multithreading;
@@ -8,18 +7,17 @@ use aoc::all_puzzles;
87
use aoc::utils::input::InputType;
98
use std::error::Error;
109
use std::ffi::CStr;
11-
use std::ptr::addr_of_mut;
1210

1311
const BUFFER_LENGTH: usize = 1024 * 1024;
1412

15-
#[no_mangle]
13+
#[unsafe(no_mangle)]
1614
static INPUT: [u8; BUFFER_LENGTH] = [0u8; BUFFER_LENGTH];
17-
#[no_mangle]
15+
#[unsafe(no_mangle)]
1816
static mut PART1: [u8; BUFFER_LENGTH] = [0u8; BUFFER_LENGTH];
19-
#[no_mangle]
17+
#[unsafe(no_mangle)]
2018
static mut PART2: [u8; BUFFER_LENGTH] = [0u8; BUFFER_LENGTH];
2119

22-
#[no_mangle]
20+
#[unsafe(no_mangle)]
2321
extern "C" fn run_puzzle(
2422
year: u16,
2523
day: u8,
@@ -35,8 +33,8 @@ extern "C" fn run_puzzle(
3533
// SAFETY: No other Rust code accesses these variables or creates references - they're only read
3634
// from JS.
3735
unsafe {
38-
write_string(addr_of_mut!(PART1).cast(), &part1);
39-
write_string(addr_of_mut!(PART2).cast(), &part2);
36+
write_string((&raw mut PART1).cast(), &part1);
37+
write_string((&raw mut PART2).cast(), &part2);
4038
}
4139

4240
success

crates/aoc_wasm/src/multithreading.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use std::alloc::{alloc_zeroed, Layout};
44
/// Allocate stack for worker threads.
55
///
66
/// **WARNING**: Stack overflows on worker threads will corrupt other parts of the linear memory.
7-
#[no_mangle]
7+
#[unsafe(no_mangle)]
88
extern "C" fn allocate_stack(size: usize, align: usize) -> *mut u8 {
99
let layout = Layout::from_size_align(size, align).unwrap();
1010
unsafe { alloc_zeroed(layout) }
1111
}
1212

1313
/// Run worker thread.
14-
#[no_mangle]
14+
#[unsafe(no_mangle)]
1515
extern "C" fn worker_thread() {
1616
worker();
1717
}

0 commit comments

Comments
 (0)