Skip to content

Commit

Permalink
[pdsl_core] Move panic handlers and global allocator def to pdsl_core
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Jan 8, 2019
1 parent 57ddb7b commit 9b3d342
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
1 change: 0 additions & 1 deletion examples/subpeep/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pdsl_core = { path = "../../pdsl_core" }

parity-codec = { version = "2.0.4", default-features = false }
parity-codec-derive = { version = "2.0.4", default-features = false }
wee_alloc = "0.4"

lazy_static = "1.2"
spin = { version = "0.4", default-features = false }
Expand Down
7 changes: 1 addition & 6 deletions examples/subpeep/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@

#[cfg(all(test, feature = "test-env"))]
mod tests;
mod utils;

#[cfg_attr(test, macro_use)]
extern crate alloc;

use alloc::string::String;
use alloc::vec::Vec;

pub mod utils;

use pdsl_core::storage;
use parity_codec_derive::{Encode, Decode};

// Use `wee_alloc` as the global allocator.
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

/// A peep done by a registered user.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Encode, Decode)]
Expand Down
15 changes: 0 additions & 15 deletions examples/subpeep/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ use spin::Mutex;

use alloc::string::String;

#[panic_handler]
#[no_mangle]
pub fn panic(_info: &::core::panic::PanicInfo) -> ! {
unsafe {
core::intrinsics::abort()
}
}

#[alloc_error_handler]
pub extern fn oom(_: ::core::alloc::Layout) -> ! {
unsafe {
core::intrinsics::abort();
}
}

pub type Address = [u8; 32];

/// Return current contract caller as 32-bytes array.
Expand Down
1 change: 1 addition & 0 deletions pdsl_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ parity-codec-derive = { version = "2.0" }
tiny-keccak = "1.4"
log = "0.4"
hashbrown = "0.1.7"
wee_alloc = "0.4"

[dev-dependencies]
env_logger = { version = "0.6", default-features = false }
Expand Down
14 changes: 13 additions & 1 deletion pdsl_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,28 @@
// along with pDSL. If not, see <http://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#![cfg_attr(not(feature = "std"), feature(
alloc,
core_intrinsics,
lang_items,
alloc_error_handler,
))]

#[cfg(not(feature = "std"))]
// #[macro_use]
extern crate alloc;

// Use `wee_alloc` as the global allocator.
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[cfg(all(test, feature = "std"))]
#[macro_use]
mod test_utils;

#[cfg(not(feature = "std"))]
mod panic_handler;

pub mod memory;
mod byte_utils;
pub mod env;
Expand Down
16 changes: 16 additions & 0 deletions pdsl_core/src/panic_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use core::panic::PanicInfo;
use core::alloc::Layout;

#[panic_handler]
#[no_mangle]
pub fn panic(_info: &PanicInfo) -> ! {
unsafe { core::intrinsics::abort() }
}

#[alloc_error_handler]
pub extern fn oom(_: Layout) -> ! {
unsafe { core::intrinsics::abort(); }
}

#[lang = "eh_personality"]
extern fn eh_personality() {}

0 comments on commit 9b3d342

Please sign in to comment.