Skip to content

p-token: Add unsafe to transmutable trait - #65

Merged
febo merged 1 commit into
mainfrom
febo/unsafe-transmutable
Jul 9, 2025
Merged

p-token: Add unsafe to transmutable trait#65
febo merged 1 commit into
mainfrom
febo/unsafe-transmutable

Conversation

@febo

@febo febo commented Jul 1, 2025

Copy link
Copy Markdown
Contributor

Problem

The Transmutable trait has memory safety implications in its implementation, but it is not marked as unsafe. This is problematic since undefined behaviour can result from an incorrect implementation.

Solution

Add unsafe to Transmutable trait to make it explicit that the trait has to be carefully implemented.

cc: @d0nutptr

@febo
febo requested a review from joncinque July 1, 2025 10:06
@febo
febo marked this pull request as draft July 1, 2025 11:17
@febo

febo commented Jul 1, 2025

Copy link
Copy Markdown
Contributor Author

CI is failing since it is pulling a new version of mollusk and having some dependencies conflicts.

@joncinque joncinque left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense to me! Just another consideration for a future PR if you want

Comment on lines 15 to 17
/// It is up to the type implementing this trait to guarantee that the cast is
/// safe, i.e., the fields of the type are well aligned and there are no padding
/// bytes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To go with this safety concern, what do you think about specifying that bytes must be on a well-aligned address for T for all the load functions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, I will add a note on load in a separate PR.

@d0nutptr

d0nutptr commented Jul 3, 2025

Copy link
Copy Markdown

LGTM!

@febo
febo force-pushed the febo/unsafe-transmutable branch from 5ac906f to 50f80b5 Compare July 9, 2025 09:53
@febo
febo marked this pull request as ready for review July 9, 2025 10:07
@febo
febo merged commit e734eb9 into main Jul 9, 2025
15 checks passed
@febo
febo deleted the febo/unsafe-transmutable branch August 22, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants