From 42bb7655baea5bb81b425087a239fb59c38b5adf Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 23 Mar 2023 17:57:43 -0400 Subject: [PATCH] replaced references to core with references to crate --- src/entry/args.rs | 4 ++-- src/entry/mod.rs | 10 +++++----- src/macros.rs | 21 +++++++++------------ src/process.rs | 2 -- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/entry/args.rs b/src/entry/args.rs index c48b354..e6b54ec 100644 --- a/src/entry/args.rs +++ b/src/entry/args.rs @@ -68,7 +68,7 @@ impl Args { ///On error returns pair: `(string index, Utf8Error)` /// ///The function is safe as long as you pass C style main function arguments. - pub unsafe fn new(argc: isize, argv: *const *const u8) -> Result { + pub unsafe fn new(argc: isize, argv: *const *const u8) -> Result { assert!(argc > 0); assert!(!argv.is_null()); @@ -102,7 +102,7 @@ impl Args { ///Returns slice of raw C strings pub fn as_slice(&self) -> &[*const u8] { unsafe { - core::slice::from_raw_parts(self.argv, self.argc) + crate::slice::from_raw_parts(self.argv, self.argc) } } diff --git a/src/entry/mod.rs b/src/entry/mod.rs index a15fbd9..c979d9b 100644 --- a/src/entry/mod.rs +++ b/src/entry/mod.rs @@ -79,10 +79,10 @@ unsafe fn invalid_cli_args_error() -> libc::c_int { ///Converts C string to Rust's, verifying it is UTF-8 /// ///It is UB to pass non-C string as it requires \0 -pub unsafe fn c_str_to_rust(ptr: *const u8) -> Result<&'static str, core::str::Utf8Error> { +pub unsafe fn c_str_to_rust(ptr: *const u8) -> Result<&'static str, crate::str::Utf8Error> { let len = libc::strlen(ptr as *const i8); - let parts = core::slice::from_raw_parts(ptr, len); - core::str::from_utf8(parts) + let parts = crate::slice::from_raw_parts(ptr, len); + crate::str::from_utf8(parts) } ///Converts C string to Rust's one assuming it is UTF-8 @@ -90,8 +90,8 @@ pub unsafe fn c_str_to_rust(ptr: *const u8) -> Result<&'static str, core::str::U ///It is UB to pass non-C string as it requires \0 pub unsafe fn c_str_to_rust_unchecked(ptr: *const u8) -> &'static str { let len = libc::strlen(ptr as *const i8); - let parts = core::slice::from_raw_parts(ptr, len); - core::str::from_utf8_unchecked(parts) + let parts = crate::slice::from_raw_parts(ptr, len); + crate::str::from_utf8_unchecked(parts) } extern "Rust" { diff --git a/src/macros.rs b/src/macros.rs index 8bfee35..3861985 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -85,13 +85,10 @@ //! # } //! ``` -#![no_std] #![allow(dead_code)] #![allow(unused)] #![warn(unsafe_op_in_unsafe_fn)] -use core::{convert::TryFrom, file, line, stringify}; - /// This forces a "C" library linkage #[cfg(not(windows))] #[link(name = "c")] @@ -111,9 +108,9 @@ pub const __LIBC_STDERR: i32 = 2; #[doc(hidden)] pub struct __LibCWriter(i32); -impl core::fmt::Write for __LibCWriter { +impl crate::fmt::Write for __LibCWriter { #[inline] - fn write_str(&mut self, s: &str) -> core::fmt::Result { + fn write_str(&mut self, s: &str) -> crate::fmt::Result { __libc_println(self.0, s) } } @@ -125,24 +122,24 @@ impl __LibCWriter { } #[inline] - pub fn write_fmt(&mut self, args: core::fmt::Arguments) -> core::fmt::Result { - core::fmt::Write::write_fmt(self, args) + pub fn write_fmt(&mut self, args: crate::fmt::Arguments) -> crate::fmt::Result { + crate::fmt::Write::write_fmt(self, args) } #[inline] - pub fn write_str(&mut self, s: &str) -> core::fmt::Result { + pub fn write_str(&mut self, s: &str) -> crate::fmt::Result { __libc_println(self.0, s) } #[inline] - pub fn write_nl(&mut self) -> core::fmt::Result { + pub fn write_nl(&mut self) -> crate::fmt::Result { __libc_println(self.0, __LIBC_NEWLINE) } } #[doc(hidden)] #[inline] -pub fn __libc_println(handle: i32, msg: &str) -> core::fmt::Result { +pub fn __libc_println(handle: i32, msg: &str) -> crate::fmt::Result { let msg = msg.as_bytes(); let mut written = 0; @@ -162,7 +159,7 @@ unsafe fn libc_write(handle: i32, bytes: &[u8]) -> Option { usize::try_from(unsafe { libc::write( handle, - bytes.as_ptr().cast::(), + bytes.as_ptr().cast::(), bytes.len(), ) }) @@ -174,7 +171,7 @@ unsafe fn libc_write(handle: i32, bytes: &[u8]) -> Option { usize::try_from(unsafe { libc::write( handle, - bytes.as_ptr().cast::(), + bytes.as_ptr().cast::(), libc::c_uint::try_from(bytes.len()).unwrap_or(libc::c_uint::MAX), ) }) diff --git a/src/process.rs b/src/process.rs index c121ac8..90f84cc 100644 --- a/src/process.rs +++ b/src/process.rs @@ -35,8 +35,6 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs")); -extern crate core; - pub fn exit(code: u32) -> ! { unsafe { libc::exit(code as i32 as libc::c_int); } }