Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Ioan-Cristian
Copy link
Contributor

Pull Request Overview

This pull request brings little improvements to the Process trait.

Testing Strategy

This pull request was tested by running libtock-c applications on STM32F429ZI Nucleo-144.

TODO or Help Wanted

No help needed.

Documentation Updated

  • Added required documentation comments.

Formatting

  • Ran make prepush.

/// Header, returns 0.
fn binary_version(&self) -> u32;
/// in a TBF Program Header; if the binary has no version assigned, return [None]
fn binary_version(&self) -> Option<BinaryVersion>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, 0 marked the absence of the binary version. This approach works, but Option is the Rust way of doing this in my opinion.

Using a u32 for the binary version is too powerful: several operations defined on the integer type don't make sense, like addition or division. Or do they?

In the end, NonZeroU32 has been chosen as the underlying type of the new BinaryVersion type. This allows code generation optimizations. In my tests, the new version compiles exactly the same to the old code.

@@ -612,7 +621,7 @@ pub trait Process {
driver_num: usize,
size: usize,
align: usize,
) -> bool;
) -> Result<(), ()>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result is the Rust way of signaling a function may fail. Additionally, Result triggers a warning when the return value is unused. From my little experiments, the new signature is compiled to the same code as the old one.

/// `enter_custom_grant()` to get access to the memory and the pointer to
/// the memory which must be used to initialize the memory.
fn allocate_custom_grant(
&self,
size: usize,
align: usize,
) -> Option<(ProcessCustomGrantIdentifier, NonNull<u8>)>;
) -> Result<(ProcessCustomGrantIdentifier, NonNull<u8>), ()>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the pattern of returning a Result as allocate_grant.

bradjc
bradjc previously approved these changes Oct 20, 2023
Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change.

@alevy alevy enabled auto-merge October 20, 2023 21:33
@alevy alevy added this pull request to the merge queue Oct 20, 2023
Merged via the queue into tock:master with commit 754c885 Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants