Skip to content
Snippets Groups Projects
Commit 300024b8 authored by rnd's avatar rnd
Browse files

[API] Provide a card10-alloc based global allocator as default feature.

parent 19f1c5a1
No related branches found
No related tags found
1 merge request!19[WIP] Task/card10 alloc
...@@ -77,10 +77,15 @@ name = "byteorder" ...@@ -77,10 +77,15 @@ name = "byteorder"
version = "1.3.2" version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "card10-alloc"
version = "0.1.0"
[[package]] [[package]]
name = "card10-l0dable" name = "card10-l0dable"
version = "0.1.1" version = "0.1.1"
dependencies = [ dependencies = [
"card10-alloc 0.1.0",
"card10-sys 0.1.0", "card10-sys 0.1.0",
] ]
...@@ -181,8 +186,8 @@ dependencies = [ ...@@ -181,8 +186,8 @@ dependencies = [
name = "l0dable-example" name = "l0dable-example"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"card10-alloc 0.1.0",
"card10-l0dable 0.1.1", "card10-l0dable 0.1.1",
"cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
......
[workspace] [workspace]
members = [ members = [
"card10-alloc",
"card10-sys", "card10-sys",
"card10-l0dable", "card10-l0dable",
"example", "example",
......
...@@ -17,5 +17,18 @@ categories = ["no-std"] ...@@ -17,5 +17,18 @@ categories = ["no-std"]
description = "make l0dables for the Card10 (CCCamp 2019) badge" description = "make l0dables for the Card10 (CCCamp 2019) badge"
[dependencies] [dependencies]
card10-sys = { path = "../card10-sys", version = "^0.1" }
[dependencies.card10-sys]
path = "../card10-sys"
version = "^0.1"
[dependencies.card10-alloc]
path = "../card10-alloc"
version = "^0.1"
optional = true
[features]
default = [ "alloc" ]
# Provides an allocator to the dependent crate.
alloc = [ "card10-alloc" ]
#![no_std] #![no_std]
#![feature(alloc_error_handler)]
mod os; mod os;
pub use os::*; pub use os::*;
mod display; mod display;
...@@ -39,3 +41,30 @@ macro_rules! main { ...@@ -39,3 +41,30 @@ macro_rules! main {
} }
}; };
} }
// -----------------------------------------------------------------------------
// Allocation handling
// -----------------------------------------------------------------------------
/// Global Allocator Handling.
///
/// Contains only the minimal necessary definitions:
///
/// - static global allocator
/// - a proper allocation error handler
#[cfg(feature = "alloc")]
mod alloc {
pub extern crate alloc;
use alloc::alloc::Layout;
use card10_alloc::Card10Allocator;
#[global_allocator]
pub static ALLOCATOR: Card10Allocator = Card10Allocator;
#[alloc_error_handler]
fn error_handler(_layout: Layout) -> ! {
panic!("OOM!");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment