Skip to content

Commit

Permalink
Use libc::abort instead of intrinsics::abort
Browse files Browse the repository at this point in the history
Despite using the `#![feature()]` attribute rustc still warns about it
being unstable. Changing it to `libc::abort` gets rid of the annoying
message.
  • Loading branch information
Kixunil committed Jul 3, 2024
1 parent 924ba38 commit df0523a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions no_std_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
//!
#![feature(start)]
#![feature(core_intrinsics)]
#![feature(alloc_error_handler)]
#![no_std]
extern crate libc;
Expand All @@ -48,7 +47,6 @@ extern crate wee_alloc;
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

use core::fmt::{self, Write};
use core::intrinsics;
use core::panic::PanicInfo;

use secp256k1::ecdh::{self, SharedSecret};
Expand All @@ -61,6 +59,10 @@ use serde_cbor::de;
use serde_cbor::ser::SliceWrite;
use serde_cbor::Serializer;

fn abort() -> ! {
unsafe { libc::abort() }
}

struct FakeRng;
impl RngCore for FakeRng {
fn next_u32(&mut self) -> u32 {
Expand Down Expand Up @@ -157,7 +159,7 @@ impl Write for Print {
if curr + s.len() > MAX_PRINT {
unsafe {
libc::printf("overflow\n\0".as_ptr() as _);
intrinsics::abort();
abort();
}
}
self.loc += s.len();
Expand All @@ -173,11 +175,11 @@ fn panic(info: &PanicInfo) -> ! {
let mut buf = Print::new();
write!(&mut buf, "{}", msg).unwrap();
buf.print();
intrinsics::abort()
abort()
}

#[alloc_error_handler]
fn alloc_error(_layout: Layout) -> ! {
unsafe { libc::printf("alloc shi1\n\0".as_ptr() as _) };
intrinsics::abort()
abort()
}

0 comments on commit df0523a

Please sign in to comment.