Pacify clippy

This commit is contained in:
Michael Vines
2021-02-18 23:42:09 -08:00
parent fd3b71a2c6
commit 5df36aec7d
40 changed files with 446 additions and 451 deletions

View File

@@ -50,17 +50,17 @@ solana_sdk::declare_builtin!(
/// Errors returned by functions the BPF Loader registers with the VM
#[derive(Debug, Error, PartialEq)]
pub enum BPFError {
pub enum BpfError {
#[error("{0}")]
VerifierError(#[from] VerifierError),
#[error("{0}")]
SyscallError(#[from] SyscallError),
}
impl UserDefinedError for BPFError {}
impl UserDefinedError for BpfError {}
fn map_ebpf_error(
invoke_context: &mut dyn InvokeContext,
e: EbpfError<BPFError>,
e: EbpfError<BpfError>,
) -> InstructionError {
ic_msg!(invoke_context, "{}", e);
InstructionError::InvalidAccountData
@@ -71,9 +71,9 @@ pub fn create_and_cache_executor(
data: &[u8],
invoke_context: &mut dyn InvokeContext,
use_jit: bool,
) -> Result<Arc<BPFExecutor>, InstructionError> {
) -> Result<Arc<BpfExecutor>, InstructionError> {
let bpf_compute_budget = invoke_context.get_bpf_compute_budget();
let mut program = Executable::<BPFError, ThisInstructionMeter>::from_elf(
let mut program = Executable::<BpfError, ThisInstructionMeter>::from_elf(
data,
None,
Config {
@@ -100,7 +100,7 @@ pub fn create_and_cache_executor(
return Err(InstructionError::ProgramFailedToCompile);
}
}
let executor = Arc::new(BPFExecutor { program });
let executor = Arc::new(BpfExecutor { program });
invoke_context.add_executor(key, executor.clone());
Ok(executor)
}
@@ -138,11 +138,11 @@ const DEFAULT_HEAP_SIZE: usize = 32 * 1024;
/// Create the BPF virtual machine
pub fn create_vm<'a>(
loader_id: &'a Pubkey,
program: &'a dyn Executable<BPFError, ThisInstructionMeter>,
program: &'a dyn Executable<BpfError, ThisInstructionMeter>,
parameter_bytes: &mut [u8],
parameter_accounts: &'a [KeyedAccount<'a>],
invoke_context: &'a mut dyn InvokeContext,
) -> Result<EbpfVm<'a, BPFError, ThisInstructionMeter>, EbpfError<BPFError>> {
) -> Result<EbpfVm<'a, BpfError, ThisInstructionMeter>, EbpfError<BpfError>> {
let heap = vec![0_u8; DEFAULT_HEAP_SIZE];
let heap_region = MemoryRegion::new_from_slice(&heap, MM_HEAP_START, 0, true);
let mut vm = EbpfVm::new(program, parameter_bytes, &[heap_region])?;
@@ -743,18 +743,18 @@ impl InstructionMeter for ThisInstructionMeter {
}
/// BPF Loader's Executor implementation
pub struct BPFExecutor {
program: Box<dyn Executable<BPFError, ThisInstructionMeter>>,
pub struct BpfExecutor {
program: Box<dyn Executable<BpfError, ThisInstructionMeter>>,
}
// Well, implement Debug for solana_rbpf::vm::Executable in solana-rbpf...
impl Debug for BPFExecutor {
impl Debug for BpfExecutor {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "BPFExecutor({:p})", self)
write!(f, "BpfExecutor({:p})", self)
}
}
impl Executor for BPFExecutor {
impl Executor for BpfExecutor {
fn execute(
&self,
loader_id: &Pubkey,
@@ -814,7 +814,7 @@ impl Executor for BPFExecutor {
}
Err(error) => {
let error = match error {
EbpfError::UserError(BPFError::SyscallError(
EbpfError::UserError(BpfError::SyscallError(
SyscallError::InstructionError(error),
)) => error,
err => {
@@ -884,14 +884,14 @@ mod tests {
];
let input = &mut [0x00];
let program = Executable::<BPFError, TestInstructionMeter>::from_text_bytes(
let program = Executable::<BpfError, TestInstructionMeter>::from_text_bytes(
program,
None,
Config::default(),
)
.unwrap();
let mut vm =
EbpfVm::<BPFError, TestInstructionMeter>::new(program.as_ref(), input, &[]).unwrap();
EbpfVm::<BpfError, TestInstructionMeter>::new(program.as_ref(), input, &[]).unwrap();
let mut instruction_meter = TestInstructionMeter { remaining: 10 };
vm.execute_program_interpreted(&mut instruction_meter)
.unwrap();