Merge branch 'minor-cleanup' into 'master'
assorted cleanups and add some lints See merge request redox-os/relibc!1061
This commit is contained in:
@@ -22,7 +22,13 @@ exclude = ["tests", "dlmalloc-rs"]
|
||||
[workspace.lints.clippy]
|
||||
borrow_as_ptr = "deny"
|
||||
cast_lossless = "warn" # TODO review occurrences
|
||||
cast_possible_truncation = "allow" # TODO review occurrences
|
||||
cast_possible_wrap = "allow" # TODO review occurrences
|
||||
cast_precision_loss = "allow" # TODO review occurrences
|
||||
cast_ptr_alignment = "allow" # TODO review occurrences
|
||||
cast_sign_loss = "allow" # TODO review occurrences
|
||||
missing_errors_doc = "allow" # TODO review occurrences
|
||||
missing_panics_doc = "allow" # TODO review occurrences
|
||||
missing_safety_doc = "allow" # TODO review occurrences
|
||||
mut_from_ref = "warn" # TODO review occurrences
|
||||
precedence = "deny"
|
||||
|
||||
@@ -29,6 +29,7 @@ pub struct CVec<T> {
|
||||
cap: usize,
|
||||
}
|
||||
impl<T> CVec<T> {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
ptr: NonNull::dangling(),
|
||||
|
||||
+5
-6
@@ -58,12 +58,11 @@ pub unsafe extern "C" fn __cxa_finalize(dso: *mut c_void) {
|
||||
let dso_usize = dso as usize;
|
||||
|
||||
for slot in funcs.iter_mut().rev() {
|
||||
if let Some(entry) = slot.as_ref() {
|
||||
if dso.is_null() || entry.dso == dso_usize {
|
||||
if let Some(entry_to_run) = slot.take() {
|
||||
(entry_to_run.func)(entry_to_run.arg as *mut c_void);
|
||||
}
|
||||
}
|
||||
if let Some(entry) = slot.as_ref()
|
||||
&& (dso.is_null() || entry.dso == dso_usize)
|
||||
&& let Some(entry_to_run) = slot.take()
|
||||
{
|
||||
(entry_to_run.func)(entry_to_run.arg as *mut c_void);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ pub struct crypt_data {
|
||||
}
|
||||
|
||||
impl crypt_data {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
crypt_data {
|
||||
initialized: 1,
|
||||
|
||||
+10
-10
@@ -127,17 +127,17 @@ pub unsafe extern "C" fn newlocale(mask: c_int, locale: *const c_char, base: loc
|
||||
if base != LC_GLOBAL_LOCALE {
|
||||
// borrowing here
|
||||
let base = base.cast_const().cast::<LocaleData>();
|
||||
if let Ok(new_locale) = new_locale.as_mut() {
|
||||
if let Some(base) = unsafe { base.as_ref() } {
|
||||
// copy old values if not containing the mask
|
||||
if (mask & LC_NUMERIC_MASK) == 0 {
|
||||
new_locale.copy_category(base, LC_NUMERIC);
|
||||
}
|
||||
if (mask & LC_MONETARY_MASK) == 0 {
|
||||
new_locale.copy_category(base, LC_MONETARY);
|
||||
}
|
||||
// TODO: other categories?
|
||||
if let Ok(new_locale) = new_locale.as_mut()
|
||||
&& let Some(base) = unsafe { base.as_ref() }
|
||||
{
|
||||
// copy old values if not containing the mask
|
||||
if (mask & LC_NUMERIC_MASK) == 0 {
|
||||
new_locale.copy_category(base, LC_NUMERIC);
|
||||
}
|
||||
if (mask & LC_MONETARY_MASK) == 0 {
|
||||
new_locale.copy_category(base, LC_MONETARY);
|
||||
}
|
||||
// TODO: other categories?
|
||||
}
|
||||
}
|
||||
new_locale.or_errno_null_mut().cast()
|
||||
|
||||
@@ -84,28 +84,27 @@ impl<L: LogSink> LogParams<L> {
|
||||
unsafe { printf(&mut buffer, message, ap) };
|
||||
buffer.extend(b"\n\0");
|
||||
|
||||
if self.maybe_open_logger().is_ok() {
|
||||
if self
|
||||
if self.maybe_open_logger().is_ok()
|
||||
&& self
|
||||
.writer
|
||||
.as_mut()
|
||||
.map(|w| w.writer().write_all(&buffer).is_err())
|
||||
.unwrap_or(true)
|
||||
{
|
||||
// Try reopening the log file once and retrying as musl does.
|
||||
if !self
|
||||
.open_logger()
|
||||
.is_ok()
|
||||
.then(|| {
|
||||
self.writer
|
||||
.as_mut()
|
||||
.map(|w| w.writer().write_all(&buffer).is_ok())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
&& self.opt.contains(Config::Console)
|
||||
{
|
||||
// Try reopening the log file once and retrying as musl does.
|
||||
if !self
|
||||
.open_logger()
|
||||
.is_ok()
|
||||
.then(|| {
|
||||
self.writer
|
||||
.as_mut()
|
||||
.map(|w| w.writer().write_all(&buffer).is_ok())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
&& self.opt.contains(Config::Console)
|
||||
{
|
||||
// TODO: Log error to /dev/console & Redox equivalent
|
||||
}
|
||||
// TODO: Log error to /dev/console & Redox equivalent
|
||||
}
|
||||
}
|
||||
if self.opt.contains(Config::PError) {
|
||||
|
||||
+5
-7
@@ -143,13 +143,11 @@ impl<R: Seek> BufReader<R> {
|
||||
self.pos = new_pos as usize;
|
||||
return Ok(());
|
||||
}
|
||||
} else {
|
||||
if let Some(new_pos) = pos.checked_add(offset as u64) {
|
||||
if new_pos <= self.cap as u64 {
|
||||
self.pos = new_pos as usize;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
} else if let Some(new_pos) = pos.checked_add(offset as u64)
|
||||
&& new_pos <= self.cap as u64
|
||||
{
|
||||
self.pos = new_pos as usize;
|
||||
return Ok(());
|
||||
}
|
||||
self.seek(SeekFrom::Current(offset)).map(|_| ())
|
||||
}
|
||||
|
||||
+1
-1
@@ -252,7 +252,7 @@ impl Write for &mut [u8] {
|
||||
#[inline]
|
||||
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
||||
let amt = cmp::min(data.len(), self.len());
|
||||
let (a, b) = mem::replace(self, &mut []).split_at_mut(amt);
|
||||
let (a, b) = mem::take(self).split_at_mut(amt);
|
||||
a.copy_from_slice(&data[..amt]);
|
||||
*self = b;
|
||||
Ok(amt)
|
||||
|
||||
@@ -10,6 +10,7 @@ pub struct LinkerCallbacks {
|
||||
}
|
||||
|
||||
impl LinkerCallbacks {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> LinkerCallbacks {
|
||||
LinkerCallbacks {
|
||||
unload: Box::new(unload),
|
||||
|
||||
+5
-5
@@ -203,10 +203,10 @@ pub unsafe fn init(
|
||||
}
|
||||
|
||||
pub unsafe fn fini() {
|
||||
if let Some(tcb) = unsafe { Tcb::current() } {
|
||||
if !tcb.linker_ptr.is_null() {
|
||||
let linker = unsafe { (*tcb.linker_ptr).lock() };
|
||||
linker.fini();
|
||||
}
|
||||
if let Some(tcb) = unsafe { Tcb::current() }
|
||||
&& !tcb.linker_ptr.is_null()
|
||||
{
|
||||
let linker = unsafe { (*tcb.linker_ptr).lock() };
|
||||
linker.fini();
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -74,10 +74,10 @@ unsafe fn get_env(mut ptr: *const usize) -> (BTreeMap<String, String>, *const us
|
||||
let env = unsafe { *ptr };
|
||||
if let Ok(arg_str) = unsafe { CStr::from_ptr(env as *const c_char).to_str() } {
|
||||
let mut parts = arg_str.splitn(2, '=');
|
||||
if let Some(key) = parts.next() {
|
||||
if let Some(value) = parts.next() {
|
||||
envs.insert(key.to_owned(), value.to_owned());
|
||||
}
|
||||
if let Some(key) = parts.next()
|
||||
&& let Some(value) = parts.next()
|
||||
{
|
||||
envs.insert(key.to_owned(), value.to_owned());
|
||||
}
|
||||
}
|
||||
ptr = unsafe { ptr.add(1) };
|
||||
|
||||
+28
-29
@@ -151,37 +151,36 @@ impl Tcb {
|
||||
/// Copy data from masters
|
||||
pub unsafe fn copy_masters(&mut self) -> Result<(), DlError> {
|
||||
//TODO: Complain if masters or tls exist without the other
|
||||
if let Some(tls) = unsafe { self.tls() } {
|
||||
if let Some(masters) = self.masters() {
|
||||
for master in masters
|
||||
.iter()
|
||||
.skip(self.num_copied_masters)
|
||||
.filter(|master| master.image_size != 0)
|
||||
{
|
||||
let range = if cfg!(any(target_arch = "x86", target_arch = "x86_64")) {
|
||||
// x86{_64} TLS layout is backwards
|
||||
self.tls_len - master.offset
|
||||
..self.tls_len - master.offset + master.image_size
|
||||
} else {
|
||||
master.offset..master.offset + master.image_size
|
||||
};
|
||||
if let Some(tls_data) = tls.get_mut(range) {
|
||||
let data = unsafe { master.data() };
|
||||
#[cfg(feature = "trace_tls")]
|
||||
log::trace!(
|
||||
"tls master: {:p}, {:#x}: {:p}, {:#x}",
|
||||
data.as_ptr(),
|
||||
data.len(),
|
||||
tls_data.as_mut_ptr(),
|
||||
tls_data.len()
|
||||
);
|
||||
tls_data.copy_from_slice(data);
|
||||
} else {
|
||||
return Err(DlError::Malformed);
|
||||
}
|
||||
if let Some(tls) = unsafe { self.tls() }
|
||||
&& let Some(masters) = self.masters()
|
||||
{
|
||||
for master in masters
|
||||
.iter()
|
||||
.skip(self.num_copied_masters)
|
||||
.filter(|master| master.image_size != 0)
|
||||
{
|
||||
let range = if cfg!(any(target_arch = "x86", target_arch = "x86_64")) {
|
||||
// x86{_64} TLS layout is backwards
|
||||
self.tls_len - master.offset..self.tls_len - master.offset + master.image_size
|
||||
} else {
|
||||
master.offset..master.offset + master.image_size
|
||||
};
|
||||
if let Some(tls_data) = tls.get_mut(range) {
|
||||
let data = unsafe { master.data() };
|
||||
#[cfg(feature = "trace_tls")]
|
||||
log::trace!(
|
||||
"tls master: {:p}, {:#x}: {:p}, {:#x}",
|
||||
data.as_ptr(),
|
||||
data.len(),
|
||||
tls_data.as_mut_ptr(),
|
||||
tls_data.len()
|
||||
);
|
||||
tls_data.copy_from_slice(data);
|
||||
} else {
|
||||
return Err(DlError::Malformed);
|
||||
}
|
||||
self.num_copied_masters = masters.len();
|
||||
}
|
||||
self.num_copied_masters = masters.len();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
+3
-3
@@ -47,7 +47,7 @@ pub const ISSUE_URL: &str = "https://gitlab.redox-os.org/redox-os/relibc/-/issue
|
||||
macro_rules! todo_skip {
|
||||
($issue:expr, $($arg:tt)*) => {
|
||||
if $issue != 0 {
|
||||
log::info!("TODO ({}{}): {}", crate::macros::ISSUE_URL, $issue, format_args!($($arg)*))
|
||||
log::info!("TODO ({}{}): {}", $crate::macros::ISSUE_URL, $issue, format_args!($($arg)*))
|
||||
} else {
|
||||
log::info!("TODO: {}", format_args!($($arg)*))
|
||||
}
|
||||
@@ -59,7 +59,7 @@ macro_rules! todo_skip {
|
||||
macro_rules! todo_error {
|
||||
($issue:expr, $err:expr, $($arg:tt)*) => {
|
||||
if $issue != 0 {
|
||||
log::error!("TODO ({}{}): {}: {}", crate::macros::ISSUE_URL, $issue, format_args!($($arg)*), $err)
|
||||
log::error!("TODO ({}{}): {}: {}", $crate::macros::ISSUE_URL, $issue, format_args!($($arg)*), $err)
|
||||
} else {
|
||||
log::error!("TODO: {}: {:?}", format_args!($($arg)*), $err)
|
||||
}
|
||||
@@ -71,7 +71,7 @@ macro_rules! todo_error {
|
||||
macro_rules! todo_panic {
|
||||
($issue:expr, $($arg:tt)*) => {
|
||||
if $issue != 0 {
|
||||
todo!("{} ({}{})", format_args!($($arg)*), crate::macros::ISSUE_URL, $issue)
|
||||
todo!("{} ({}{})", format_args!($($arg)*), $crate::macros::ISSUE_URL, $issue)
|
||||
} else {
|
||||
todo!("{}", format_args!($($arg)*))
|
||||
}
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ impl<'a, T> Out<'a, [T]> {
|
||||
} else {
|
||||
ptr
|
||||
};
|
||||
unsafe { Self::nonnull(core::slice::from_raw_parts_mut(ptr, len)) }
|
||||
unsafe { Self::nonnull(core::ptr::slice_from_raw_parts_mut(ptr, len)) }
|
||||
}
|
||||
pub fn len(&self) -> usize {
|
||||
self.ptr.as_ptr().len()
|
||||
|
||||
@@ -14,6 +14,7 @@ use dlmalloc::DlmallocCApi;
|
||||
|
||||
pub type Dlmalloc = DlmallocCApi<sys::System>;
|
||||
|
||||
#[allow(clippy::declare_interior_mutable_const)]
|
||||
pub const NEWALLOCATOR: Allocator = Allocator::new();
|
||||
|
||||
pub struct Allocator {
|
||||
@@ -22,6 +23,7 @@ pub struct Allocator {
|
||||
}
|
||||
|
||||
impl Allocator {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub const fn new() -> Self {
|
||||
Allocator {
|
||||
inner: SyncUnsafeCell::new(Mutex::new(Dlmalloc::new(sys::System::new()))),
|
||||
|
||||
@@ -13,15 +13,15 @@ pub unsafe fn init() {
|
||||
#[cfg(feature = "no_trace")]
|
||||
let mut trace_warn = false;
|
||||
unsafe {
|
||||
if let Some(env) = CStr::from_nullable_ptr(crate::header::stdlib::getenv(log_env)) {
|
||||
if let Ok(level) = log::LevelFilter::from_str(env.to_str().unwrap_or("")) {
|
||||
#[cfg(feature = "no_trace")]
|
||||
if level == log::LevelFilter::Trace {
|
||||
trace_warn = true;
|
||||
}
|
||||
|
||||
logger = logger.with_output(OutputBuilder::stderr().with_filter(level).build());
|
||||
if let Some(env) = CStr::from_nullable_ptr(crate::header::stdlib::getenv(log_env))
|
||||
&& let Ok(level) = log::LevelFilter::from_str(env.to_str().unwrap_or(""))
|
||||
{
|
||||
#[cfg(feature = "no_trace")]
|
||||
if level == log::LevelFilter::Trace {
|
||||
trace_warn = true;
|
||||
}
|
||||
|
||||
logger = logger.with_output(OutputBuilder::stderr().with_filter(level).build());
|
||||
}
|
||||
if let Some(name) = CStr::from_nullable_ptr(crate::platform::program_invocation_short_name)
|
||||
{
|
||||
|
||||
+4
-4
@@ -96,10 +96,10 @@ fn alloc_init() {
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
if let Some(tcb) = ld_so::tcb::Tcb::current() {
|
||||
if !tcb.mspace.is_null() {
|
||||
ALLOCATOR.set(tcb.mspace);
|
||||
}
|
||||
if let Some(tcb) = ld_so::tcb::Tcb::current()
|
||||
&& !tcb.mspace.is_null()
|
||||
{
|
||||
ALLOCATOR.set(tcb.mspace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ impl<'a, T> Deref for MutexGuard<'a, T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.content
|
||||
self.content
|
||||
}
|
||||
}
|
||||
impl<'a, T> DerefMut for MutexGuard<'a, T> {
|
||||
|
||||
@@ -16,6 +16,7 @@ unsafe impl<T: Send + Sync> Send for Waitval<T> {}
|
||||
unsafe impl<T: Send + Sync> Sync for Waitval<T> {}
|
||||
|
||||
impl<T> Waitval<T> {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
state: AtomicUint::new(0),
|
||||
|
||||
Reference in New Issue
Block a user