From 33c49593a1345d68bb0fe6af34a57eb112246835 Mon Sep 17 00:00:00 2001 From: Tropical <42101043+Tropix126@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:21:04 -0500 Subject: [PATCH 1/2] fix: safe initialization context of robot structs --- packages/pros-async/src/lib.rs | 6 ++++-- packages/pros-sync/src/lib.rs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/pros-async/src/lib.rs b/packages/pros-async/src/lib.rs index 6d1beb30..004a082f 100644 --- a/packages/pros-async/src/lib.rs +++ b/packages/pros-async/src/lib.rs @@ -185,8 +185,9 @@ macro_rules! async_robot { #[no_mangle] extern "C" fn initialize() { + let robot = Default::default(); unsafe { - ROBOT = Some(Default::default()); + ROBOT = Some(robot); } } }; @@ -195,8 +196,9 @@ macro_rules! async_robot { #[no_mangle] extern "C" fn initialize() { + let robot = $init; unsafe { - ROBOT = Some($init); + ROBOT = Some(robot); } } }; diff --git a/packages/pros-sync/src/lib.rs b/packages/pros-sync/src/lib.rs index 6f7df18a..6c252308 100644 --- a/packages/pros-sync/src/lib.rs +++ b/packages/pros-sync/src/lib.rs @@ -123,8 +123,9 @@ macro_rules! sync_robot { #[no_mangle] extern "C" fn initialize() { + let robot = Default::default(); unsafe { - ROBOT = Some(Default::default()); + ROBOT = Some(robot); } } }; @@ -133,8 +134,9 @@ macro_rules! sync_robot { #[no_mangle] extern "C" fn initialize() { + let robot = $init; unsafe { - ROBOT = Some($init); + ROBOT = Some(robot); } } }; From 5f39db3413ef247fbbbd9c281adabcca07da1294 Mon Sep 17 00:00:00 2001 From: Tropical <42101043+Tropix126@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:22:35 -0500 Subject: [PATCH 2/2] docs: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c8eb379..28215727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Before releasing: ### Fixed - `pros_sys` bindings to the Motors C API now takes the correct port type (`i8`) as of PROS 4 (**Breaking Change**) (#66). +- Fixed the unintended `unsafe` context present in the `sync_robot` and `async_robot` family of macros (**Breaking Change**) (#107). ### Changed