From 53547b0d2e27c308e618c767ce7ac4a6da12e2f5 Mon Sep 17 00:00:00 2001 From: hyperslv Date: Wed, 17 Jun 2020 12:17:07 +0300 Subject: [PATCH 1/5] Provide an explanation on transformation of static variables by the exception procedural macro --- src/start/exceptions.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/start/exceptions.md b/src/start/exceptions.md index 3d46f4ee..c4a487c5 100644 --- a/src/start/exceptions.md +++ b/src/start/exceptions.md @@ -31,7 +31,7 @@ This behavior is pretty much intended and it's required to provide a feature: fn SysTick() { static mut COUNT: u32 = 0; - // `COUNT` has type `&mut u32` and it's safe to use + // `COUNT` has transformed to type `&mut u32` and it's safe to use *COUNT += 1; } ``` @@ -47,6 +47,12 @@ use `static mut` variables. How is this possible? This is possible because `exception` handlers can *not* be called by software thus reentrancy is not possible. +> Note that the `exception` attribute makes transformation of static variables +> inside the function by wrapping the static variable definitions into `unsafe` +> blocks and providing us with new appropriate variables of type `&mut` which +> names match user defined. Thus we can use operator `*` to access the values +> of the variables without need to wrap them into the `unsafe` blocks. + ## A complete example Here's an example that uses the system timer to raise a `SysTick` exception From 2495fdcfbe449ba247e671f8ed568c8a347657f8 Mon Sep 17 00:00:00 2001 From: hyperslv Date: Sun, 5 Jul 2020 16:22:01 +0300 Subject: [PATCH 2/5] wording --- src/start/exceptions.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/start/exceptions.md b/src/start/exceptions.md index c4a487c5..a3239c1f 100644 --- a/src/start/exceptions.md +++ b/src/start/exceptions.md @@ -47,11 +47,11 @@ use `static mut` variables. How is this possible? This is possible because `exception` handlers can *not* be called by software thus reentrancy is not possible. -> Note that the `exception` attribute makes transformation of static variables -> inside the function by wrapping the static variable definitions into `unsafe` -> blocks and providing us with new appropriate variables of type `&mut` which -> names match user defined. Thus we can use operator `*` to access the values -> of the variables without need to wrap them into the `unsafe` blocks. +> Note that the `exception` attribute transforms definitions of static variables +> inside the function by wrapping them into `unsafe` blocks and providing us +> with new appropriate variables of type `&mut` which names match user defined. +> Thus we can use operator `*` to access the values of the variables without +> need to wrap them into the `unsafe` blocks. ## A complete example From bdb5f1e53468edcbcf335c660bdd5497f29613dd Mon Sep 17 00:00:00 2001 From: hyperslv <57301860+hyperslv@users.noreply.github.com> Date: Sun, 5 Jul 2020 16:53:14 +0300 Subject: [PATCH 3/5] Update src/start/exceptions.md Co-authored-by: Daniel Egger --- src/start/exceptions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/start/exceptions.md b/src/start/exceptions.md index a3239c1f..bcf2644a 100644 --- a/src/start/exceptions.md +++ b/src/start/exceptions.md @@ -49,7 +49,7 @@ possible. > Note that the `exception` attribute transforms definitions of static variables > inside the function by wrapping them into `unsafe` blocks and providing us -> with new appropriate variables of type `&mut` which names match user defined. +> with new appropriate variables of type `&mut` of the same name. > Thus we can use operator `*` to access the values of the variables without > need to wrap them into the `unsafe` blocks. From 2f44d22ceb68123950055faacfafe4922a03758d Mon Sep 17 00:00:00 2001 From: hyperslv <57301860+hyperslv@users.noreply.github.com> Date: Sun, 5 Jul 2020 16:53:36 +0300 Subject: [PATCH 4/5] Update src/start/exceptions.md Co-authored-by: Daniel Egger --- src/start/exceptions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/start/exceptions.md b/src/start/exceptions.md index bcf2644a..1f70d958 100644 --- a/src/start/exceptions.md +++ b/src/start/exceptions.md @@ -51,7 +51,7 @@ possible. > inside the function by wrapping them into `unsafe` blocks and providing us > with new appropriate variables of type `&mut` of the same name. > Thus we can use operator `*` to access the values of the variables without -> need to wrap them into the `unsafe` blocks. +> needing to wrap them in an `unsafe` block. ## A complete example From 5ba9989b1cbd0b4eaa6d820d3ebac3b9775512be Mon Sep 17 00:00:00 2001 From: hyperslv <57301860+hyperslv@users.noreply.github.com> Date: Sun, 5 Jul 2020 16:54:32 +0300 Subject: [PATCH 5/5] Update src/start/exceptions.md Co-authored-by: Daniel Egger --- src/start/exceptions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/start/exceptions.md b/src/start/exceptions.md index 1f70d958..0aa162ad 100644 --- a/src/start/exceptions.md +++ b/src/start/exceptions.md @@ -50,7 +50,7 @@ possible. > Note that the `exception` attribute transforms definitions of static variables > inside the function by wrapping them into `unsafe` blocks and providing us > with new appropriate variables of type `&mut` of the same name. -> Thus we can use operator `*` to access the values of the variables without +> Thus we can derefence the reference via `*` to access the values of the variables without > needing to wrap them in an `unsafe` block. ## A complete example