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
use crate::{error_hook, VmApiImpl};
use elrond_wasm::api::{ErrorApi, ErrorApiImpl, Handle};

extern "C" {
    #[cfg(not(feature = "unmanaged-ei"))]
    fn managedSignalError(messageHandle: i32) -> !;
}

impl ErrorApi for VmApiImpl {
    type ErrorApiImpl = VmApiImpl;

    #[inline]
    fn error_api_impl() -> Self {
        VmApiImpl {}
    }
}

impl ErrorApiImpl for VmApiImpl {
    #[inline(always)]
    fn signal_error(&self, message: &[u8]) -> ! {
        error_hook::signal_error(message)
    }

    #[cfg(feature = "unmanaged-ei")]
    fn signal_error_from_buffer(&self, message_handle: Handle) -> ! {
        use elrond_wasm::api::ManagedBufferApi;
        let message = self.mb_to_boxed_bytes(message_handle);
        self.signal_error(message.as_slice())
    }

    #[inline(always)]
    #[cfg(not(feature = "unmanaged-ei"))]
    fn signal_error_from_buffer(&self, message_handle: Handle) -> ! {
        unsafe { managedSignalError(message_handle) }
    }
}