Add msg! macro for program logging, deprecate info! macro

This commit is contained in:
Michael Vines
2020-11-30 13:28:58 -08:00
parent 254790f8c8
commit 6705b5a98c
22 changed files with 162 additions and 141 deletions

View File

@ -2,7 +2,7 @@
#[macro_use]
extern crate alloc;
use solana_program::{entrypoint::SUCCESS, info};
use solana_program::{entrypoint::SUCCESS, msg};
use std::{alloc::Layout, mem};
#[no_mangle]
@ -13,7 +13,7 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
let layout = Layout::from_size_align(std::usize::MAX, mem::align_of::<u8>()).unwrap();
let ptr = alloc::alloc::alloc(layout);
if !ptr.is_null() {
info!("Error: Alloc of very larger buffer should fail");
msg!("Error: Alloc of very larger buffer should fail");
panic!();
}
}
@ -24,7 +24,7 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
let layout = Layout::from_size_align(100, mem::align_of::<u8>()).unwrap();
let ptr = alloc::alloc::alloc(layout);
if ptr.is_null() {
info!("Error: Alloc of 100 bytes failed");
msg!("Error: Alloc of 100 bytes failed");
alloc::alloc::handle_alloc_error(layout);
}
alloc::alloc::dealloc(ptr, layout);
@ -37,7 +37,7 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
let layout = Layout::from_size_align(ITERS, mem::align_of::<u8>()).unwrap();
let ptr = alloc::alloc::alloc(layout);
if ptr.is_null() {
info!("Error: Alloc failed");
msg!("Error: Alloc failed");
alloc::alloc::handle_alloc_error(layout);
}
for i in 0..ITERS {
@ -46,7 +46,7 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
for i in 0..ITERS {
assert_eq!(*ptr.add(i as usize), i as u8);
}
info!(0x3, 0, 0, 0, u64::from(*ptr.add(42)));
msg!(0x3, 0, 0, 0, u64::from(*ptr.add(42)));
assert_eq!(*ptr.add(42), 42);
alloc::alloc::dealloc(ptr, layout);
}
@ -61,7 +61,7 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
for v in ones.iter() {
sum += ones[*v];
}
info!(0x0, 0, 0, 0, sum as u64);
msg!(0x0, 0, 0, 0, sum as u64);
assert_eq!(sum, ITERS);
}
@ -74,7 +74,7 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
for i in 0..ITERS {
v.push(i);
}
info!(0x4, 0, 0, 0, v.len() as u64);
msg!(0x4, 0, 0, 0, v.len() as u64);
assert_eq!(v.len(), ITERS);
}