Skip to content

Conversation

JalonWong
Copy link

No description provided.

@JalonWong JalonWong requested a review from a team as a code owner August 14, 2025 19:33
@JalonWong JalonWong force-pushed the master branch 4 times, most recently from 6bca433 to 6335bb8 Compare August 15, 2025 19:49
Copy link

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

Sounds good to me, thanks! Just a bit of nitpicks and it should be mergable.

@JalonWong JalonWong force-pushed the master branch 2 times, most recently from 9951db6 to 080581e Compare August 17, 2025 05:23
@JalonWong
Copy link
Author

@zeenix I have made improvements based on the suggestions, and I added a assert!($size > 0); in the macro. Is it appropriate?

zeenix
zeenix previously approved these changes Aug 17, 2025
Copy link

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@zeenix
Copy link

zeenix commented Aug 17, 2025

@JalonWong I'll merge soon but I want to first give others a chance to have a look.

CC @adamgreig @sgued

@adamgreig
Copy link
Member

My only thought is that people are likely to want to configure where the backing store for the heap is located in memory using link_section. If the assert!() wasn't there, you could put #[unsafe(link_section=".sram2")] before the init!() macro call; I'm not sure what's most elegant otherwise though:

  • add an optional macro argument for link section? helps for this case, but maybe people will want other attributes (though I think link section is the main one)
  • move the assert later so people can decorate the static mut with whatever attributes they want? I guess it works but it's kind of ugly and unclear when reading the code what it applies to
  • leave it as-is, and if someone wants to specify the linker section they can just write the macro code out by hand instead

@zeenix
Copy link

zeenix commented Aug 18, 2025

  • add an optional macro argument for link section? helps for this case, but maybe people will want other attributes (though I think link section is the main one)
  • leave it as-is, and if someone wants to specify the linker section they can just write the macro code out by hand instead

How about a combination of these two: we add the optional argument for the linker section and if people need to add other attributes, they just don't use the macro?

@JalonWong
Copy link
Author

@zeenix @adamgreig If someone want to use link_section I think they just don't use the macro. I leave the previous example in the README.

@JalonWong JalonWong force-pushed the master branch 5 times, most recently from f447854 to d47bd8a Compare August 19, 2025 02:51
@JalonWong
Copy link
Author

JalonWong commented Aug 19, 2025

@sgued @zeenix I found out that it's very easy to add once in the init(), because critical_section is already used in it. I just added a bool member variable. This keeps the macro very simple, I also remove the unsafe in the macro, it works fine.

Do you think that this is a better solution?

src/llff.rs Outdated
Comment on lines 48 to 47
/// - This function must be called exactly ONCE.
/// - `size > 0`
Copy link

Choose a reason for hiding this comment

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

With the assertions in place now, these are no longer a safety issue but rather just panic scenarios, so I'd change the heading here from Safety to Panics and update the wording of the section.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure how to express it. Could you provide some content?

Copy link

Choose a reason for hiding this comment

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

Can you give it a try first? I can help if/when needed. Just try to keep the changes to minimum and focus on adapting the wording.

Copy link

Choose a reason for hiding this comment

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

This is still not done.

Copy link
Author

@JalonWong JalonWong Aug 25, 2025

Choose a reason for hiding this comment

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

The cllipy requires a Safety section, so I added the content under it.
Maybe we have to make this function safe to change it to Panics

Copy link

Choose a reason for hiding this comment

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

Ah right. I had assumed that @JalonWong did his homework but I guess not. :) So @JalonWong we need both Safety and Panics sections then.

Copy link
Author

Choose a reason for hiding this comment

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

@zeenix Yes, I noticed that the arguments need unsafe. I wonder if we should continue to modify it? Or what content should be written in the Safety section if we keep both Safety and Panics sections?

Copy link

Choose a reason for hiding this comment

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

Or what content should be written in the Safety section if we keep both Safety and Panics sections?

Well, Safety should list the assumptions that keep this method safe and Panics should list the panic scenarios?

Copy link
Author

Choose a reason for hiding this comment

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

We already have the panic scenarios. Did you mean we should add more safety contents? Like "make sure the memory start_addr pointed to is available"?

Copy link

Choose a reason for hiding this comment

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

I made an inline comment so there is no ambiguity anymore.

@JalonWong JalonWong force-pushed the master branch 5 times, most recently from f5ba156 to b3afee2 Compare August 27, 2025 16:21
sgued
sgued previously approved these changes Aug 28, 2025
///
/// - This function must be called exactly ONCE.
/// - `size > 0`
/// - this function is called more than ONCE.
Copy link

Choose a reason for hiding this comment

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

@JalonWong Here, the heading is still Safety but we're listing panics. As I have previous said, you need to rename the section to Panics. For Safety you need to add another section where you describe the safety invariants.

Copy link
Author

Choose a reason for hiding this comment

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

OK, I have done it. Please verify if the content under Safety is appropriate.

Copy link

Choose a reason for hiding this comment

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

OK, I have done it. Please verify if the content under Safety is appropriate.

Yes, but see my other comment.

Copy link

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

Sorry but still some things to do. Thank you for your patience and hard work on this so far. 👍

CHANGELOG.md Outdated
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Added a `init` macro to make initialization easier.
- Added a flag to prevent duplicate initialization
Copy link

Choose a reason for hiding this comment

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

This is a completely internal change and should not be communicated to the users. Instead, you should document the changed behaviour of the init methods (under Changed heading) here.

Copy link
Author

Choose a reason for hiding this comment

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

Done

///
/// - This function must be called exactly ONCE.
/// - `size > 0`
/// - this function is called more than ONCE.
Copy link

Choose a reason for hiding this comment

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

OK, I have done it. Please verify if the content under Safety is appropriate.

Yes, but see my other comment.

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.

4 participants