program-entrypoint: Add a BumpAllocator constructor - #284
Merged
Conversation
#### Problem The current version of program-entrypoint doesn't work because the allocator can't be instantiated in the macros. The start and len fields are private, and so can't be written to in the macro, which exists in the scope of the program. #### Summary of changes Add a new constructor that can be used by the macro.
febo
reviewed
Aug 13, 2025
Comment on lines
+224
to
+227
| static A: $crate::BumpAllocator = $crate::BumpAllocator::new_with_fixed_address_range( | ||
| $crate::HEAP_START_ADDRESS as usize, | ||
| $crate::HEAP_LENGTH, | ||
| ); |
Contributor
There was a problem hiding this comment.
We might need to wrap this in an unsafe block:
Suggested change
| static A: $crate::BumpAllocator = $crate::BumpAllocator::new_with_fixed_address_range( | |
| $crate::HEAP_START_ADDRESS as usize, | |
| $crate::HEAP_LENGTH, | |
| ); | |
| static A: $crate::BumpAllocator = unsafe { | |
| $crate::BumpAllocator::new_with_fixed_address_range( | |
| $crate::HEAP_START_ADDRESS as usize, | |
| $crate::HEAP_LENGTH, | |
| ) | |
| }; |
Collaborator
Author
There was a problem hiding this comment.
You're totally right! I also had to make the function const
febo
reviewed
Aug 13, 2025
| /// | ||
| /// For Solana on-chain programs, a certain address range is reserved, so | ||
| /// the allocator can be given those addresses. | ||
| pub const unsafe fn new_with_fixed_address_range(start: usize, len: usize) -> Self { |
Contributor
There was a problem hiding this comment.
Maybe we can drop the "new" from the name, like the one in Vec type:
Suggested change
| pub const unsafe fn new_with_fixed_address_range(start: usize, len: usize) -> Self { | |
| pub const unsafe fn with_fixed_address_range(start: usize, len: usize) -> Self { |
febo
previously approved these changes
Aug 13, 2025
febo
left a comment
Contributor
There was a problem hiding this comment.
Looks great! Just left a comment about the name, but that is cosmetic.
febo
pushed a commit
to febo/solana-sdk
that referenced
this pull request
Sep 21, 2025
* program-entrypoint: Add a BumpAllocator constructor #### Problem The current version of program-entrypoint doesn't work because the allocator can't be instantiated in the macros. The start and len fields are private, and so can't be written to in the macro, which exists in the scope of the program. #### Summary of changes Add a new constructor that can be used by the macro. * Make function const, call from unsafe block * Rename
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The current version of program-entrypoint doesn't work because the allocator can't be instantiated in the macros. The start and len fields are private, and so can't be written to in the macro, which exists in the scope of the program.
Summary of changes
Add a new constructor that can be used by the macro.