Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Feb 13, 2023
1 parent 9e6e9d6 commit 98cbe12
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
1 change: 0 additions & 1 deletion program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
account_infos: &[AccountInfo],
signers_seeds: &[&[&[u8]]],
) -> ProgramResult {
// bprumo TODO: can I do anything to remove this clone?
let instruction = StableInstruction::from(instruction.clone());
let invoke_context = get_invoke_context();
let log_collector = invoke_context.get_log_collector();
Expand Down
1 change: 0 additions & 1 deletion sdk/program/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ pub fn invoke_signed_unchecked(
) -> ProgramResult {
#[cfg(target_os = "solana")]
{
// bprumo TODO: it would be nice to not clone `instruction`... Can this fn take a StableInstruction instead?
let instruction = StableInstruction::from(instruction.clone());
let result = unsafe {
crate::syscalls::sol_invoke_signed_rust(
Expand Down
5 changes: 4 additions & 1 deletion sdk/program/src/stable_layout.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//! bprumo TODO: doc, or hide doc?
#![doc(hidden)]
//! Types with stable memory layouts
//!
//! Internal use only; here be dragons!
pub mod stable_instruction;
pub mod stable_rc;
Expand Down
21 changes: 20 additions & 1 deletion sdk/program/src/stable_layout/stable_instruction.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Instruction, with a stable memory layout
//! `Instruction`, with a stable memory layout
use {
crate::{
Expand All @@ -9,6 +9,25 @@ use {
std::fmt::Debug,
};

/// `Instruction`, with a stable memory layout
///
/// This is used within the runtime to ensure memory mapping and memory accesses are valid. We
/// rely on known addresses and offsets within the runtime, and since `Instruction`'s layout is
/// allowed to change, we must provide a way to lock down the memory layout. `StableInstruction`
/// reimplements the bare minimum of `Instruction`'s API sufficient only for the runtime's needs.
///
/// # Examples
///
/// Creating a `StableInstruction` from an `Instruction`
///
/// ```
/// # use solana_program::{instruction::{AccountMeta, Instruction}, pubkey::Pubkey, stable_layout::stable_instruction::StableInstruction};
/// # let program_id = Pubkey::default();
/// # let accounts = Vec::default();
/// # let data = Vec::default();
/// let instruction = Instruction { program_id, accounts, data };
/// let instruction = StableInstruction::from(instruction);
/// ```
#[derive(Debug, PartialEq)]
#[repr(C)]
pub struct StableInstruction {
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/stable_layout/stable_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::{marker::PhantomData, mem::ManuallyDrop, ptr::NonNull};
/// `Vec`, with a stable memory layout
///
/// This container is used within the runtime to ensure memory mapping and memory accesses are
/// valid. We rely on known addresses and offsets within the runtime, and since `Vec`'s layout is
/// allowed to change, we must provide a way to lock down the memory layout. `StableVec`
/// valid. We rely on known addresses and offsets within the runtime, and since `Vec`'s layout
/// is allowed to change, we must provide a way to lock down the memory layout. `StableVec`
/// reimplements the bare minimum of `Vec`'s API sufficient only for the runtime's needs.
///
/// To ensure memory allocation and deallocation is handled correctly, it is only possible to
Expand Down

0 comments on commit 98cbe12

Please sign in to comment.