1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#![feature(
    alloc,
    alloc_error_handler,
    core_intrinsics,
    panic_info_message,
    try_trait,
    )]
#![cfg_attr(debug_assertions, feature(set_stdio))]

extern crate serde_cbor;
#[cfg(test)]
extern crate ellipticoin_test_framework as ellipticoin;
pub mod error;
mod memory;
mod response;
mod pointer;
mod external;
mod bytes;

use memory::ptr_from_vec;
pub use serde_cbor::{
    Value,
    ObjectKey,
    to_vec,
    from_slice,
};
pub use std::collections::{
    BTreeMap,
};
pub use external::{set_memory, get_memory};
pub use response::{Responsable, Bytes};
pub use bytes::{ToBytes, FromBytes};
pub use pointer::{
    Pointer,
    Referenceable,
    Dereferenceable,
};

#[cfg(debug_assertions)]
mod hook;
#[cfg(debug_assertions)]
pub use hook::{
    _print_args,
    _eprint_args,
};
#[cfg(debug_assertions)]
pub use hook::{hook};

// Note these must be defined in lib.rs
// https://users.rust-lang.org/t/how-to-export-rust-functions-from-child-module/11057/7
#[no_mangle]
pub unsafe fn dealloc(ptr: *mut u8, old_size: usize) {
    Vec::from_raw_parts(ptr, 0, old_size);
}
#[no_mangle]
pub unsafe fn alloc(size: usize) -> *mut u8 {
    ptr_from_vec(Vec::with_capacity(size))
}

/// Overrides the default `print!` macro.
#[macro_export]
macro_rules! print {
    ($($arg:tt)*) => (#[cfg(debug_assertions)]
        $crate::_print_args(format_args!($($arg)*)));
}

#[macro_export]
macro_rules! println {
    () => (print!("\n"));
    ($($arg:tt)*) => (print!("{}\n", format_args!($($arg)*)))
}

#[macro_export]
macro_rules! eprintln {
    () => (print!("\n"));
    ($($arg:tt)*) => (eprint!("{}\n", format_args!($($arg)*)))
}

/// Overrides the default `eprint!` macro.
#[macro_export]
macro_rules! eprint {
    ($($arg:tt)*) => (#[cfg(debug_assertions)]
    $crate::_eprint_args(format_args!($($arg)*)));
}