From 0f91631bb6d9fe201d47a362bcf23bfe24d2a1d6 Mon Sep 17 00:00:00 2001 From: febo Date: Tue, 24 Sep 2024 15:31:30 +0100 Subject: [PATCH] Add module level docs --- sdk/src/entrypoint.rs | 14 ++++++-------- sdk/src/instruction.rs | 2 ++ sdk/src/lib.rs | 1 - sdk/src/program.rs | 2 ++ sdk/src/pubkey.rs | 2 ++ sdk/src/syscalls.rs | 2 ++ sdk/src/sysvars/mod.rs | 2 +- sdk/src/sysvars/rent.rs | 2 +- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/sdk/src/entrypoint.rs b/sdk/src/entrypoint.rs index e955979..d2382b9 100644 --- a/sdk/src/entrypoint.rs +++ b/sdk/src/entrypoint.rs @@ -1,3 +1,6 @@ +//! Macros and functions for defining the program entrypoint and setting up +//! global handlers. + use core::{alloc::Layout, mem::size_of, ptr::null_mut, slice::from_raw_parts}; use crate::{ @@ -150,11 +153,7 @@ pub unsafe fn deserialize<'a, const MAX_ACCOUNTS: usize>( let processed = if total_accounts > 0 { // number of accounts to process (limited to MAX_ACCOUNTS) - let processed = if total_accounts > MAX_ACCOUNTS { - MAX_ACCOUNTS - } else { - total_accounts - }; + let processed = core::cmp::min(total_accounts, MAX_ACCOUNTS); for i in 0..processed { let duplicate = *(input.add(offset) as *const u8); @@ -171,7 +170,7 @@ pub unsafe fn deserialize<'a, const MAX_ACCOUNTS: usize>( accounts[i].write(AccountInfo { raw: account_info }); } else { - offset += 8; + offset += core::mem::size_of::(); // duplicate account, clone the original pointer accounts[i].write(accounts[duplicate as usize].assume_init_ref().clone()); } @@ -191,7 +190,7 @@ pub unsafe fn deserialize<'a, const MAX_ACCOUNTS: usize>( offset += (offset as *const u8).align_offset(BPF_ALIGN_OF_U128); offset += core::mem::size_of::(); } else { - offset += 8; + offset += core::mem::size_of::(); } } @@ -202,7 +201,6 @@ pub unsafe fn deserialize<'a, const MAX_ACCOUNTS: usize>( }; // instruction data - #[allow(clippy::cast_ptr_alignment)] let instruction_data_len = *(input.add(offset) as *const u64) as usize; offset += core::mem::size_of::(); diff --git a/sdk/src/instruction.rs b/sdk/src/instruction.rs index c58ad26..371dc88 100644 --- a/sdk/src/instruction.rs +++ b/sdk/src/instruction.rs @@ -1,3 +1,5 @@ +//! Instruction types. + use core::marker::PhantomData; use crate::{account_info::AccountInfo, pubkey::Pubkey}; diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 5d99da3..8bf9b4c 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -7,7 +7,6 @@ //! //! [`solana-sdk`]: https://docs.rs/solana-sdk/latest/solana_sdk/ //! [`solana-program`]: https://docs.rs/solana-program/latest/solana_program/ -//! #![no_std] diff --git a/sdk/src/program.rs b/sdk/src/program.rs index b14e84e..ef11120 100644 --- a/sdk/src/program.rs +++ b/sdk/src/program.rs @@ -1,3 +1,5 @@ +//! Cross-program invocation helpers. + use core::mem::MaybeUninit; use crate::{ diff --git a/sdk/src/pubkey.rs b/sdk/src/pubkey.rs index 18c4de9..e646190 100644 --- a/sdk/src/pubkey.rs +++ b/sdk/src/pubkey.rs @@ -1,3 +1,5 @@ +//! Public key type and functions. + /// maximum length of derived `Pubkey` seed pub const MAX_SEED_LEN: usize = 32; diff --git a/sdk/src/syscalls.rs b/sdk/src/syscalls.rs index b2dedce..ecc74bf 100644 --- a/sdk/src/syscalls.rs +++ b/sdk/src/syscalls.rs @@ -1,3 +1,5 @@ +//! Syscall functions. + use crate::{ instruction::{AccountMeta, ProcessedSiblingInstruction}, pubkey::Pubkey, diff --git a/sdk/src/sysvars/mod.rs b/sdk/src/sysvars/mod.rs index 73a1df6..c571707 100644 --- a/sdk/src/sysvars/mod.rs +++ b/sdk/src/sysvars/mod.rs @@ -1,4 +1,4 @@ -//! Provides access to system accounts. +//! Provides access to cluster system accounts. use crate::program_error::ProgramError; diff --git a/sdk/src/sysvars/rent.rs b/sdk/src/sysvars/rent.rs index c59c632..ae3ad48 100644 --- a/sdk/src/sysvars/rent.rs +++ b/sdk/src/sysvars/rent.rs @@ -1,4 +1,4 @@ -//! This account contains the current cluster rent +//! This account contains the current cluster rent. //! //! This is required for the rent sysvar implementation.