Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "gear-dlmalloc"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["Alex Crichton <alex@alexcrichton.com>", "Gear Technologies"]
license = "MIT/Apache-2.0"
readme = "README.md"
Expand Down Expand Up @@ -50,3 +51,7 @@ debug = []

# Verbose allocator work actions
verbose = []

# See `tests/smoke.rs` for more information on this feature
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(test_lots)'] }
4 changes: 0 additions & 4 deletions build.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/dlmalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::common::{align_down, align_up};
use crate::dlassert;
use crate::dlverbose;
use crate::dlverbose_no_flush;
use crate::sys;
use dlverbose::{DL_CHECKS, DL_DEBUG, DL_VERBOSE, VERBOSE_DEL};
use sys;

extern crate static_assertions;

Expand Down
8 changes: 4 additions & 4 deletions src/dlverbose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ static mut OUT_BUFFER: StaticStr = StaticStr::new();
#[inline(never)]
pub fn dlprint_fn(args: Arguments<'_>) {
unsafe {
core::fmt::write(&mut OUT_BUFFER, args).unwrap();
ext::debug(&OUT_BUFFER, OUT_BUFFER.len());
OUT_BUFFER.set_len(0);
core::fmt::write(&mut *&raw mut OUT_BUFFER, args).unwrap();
ext::debug(&*&raw const OUT_BUFFER, (&*&raw const OUT_BUFFER).len());
(&mut *&raw mut OUT_BUFFER).set_len(0);
}
}

Expand All @@ -53,7 +53,7 @@ pub fn dlprint_fn(args: Arguments<'_>) {
#[inline(never)]
pub fn dlwrite_fn(args: Arguments<'_>) {
unsafe {
core::fmt::write(&mut OUT_BUFFER, args).unwrap();
core::fmt::write(&mut *&raw mut OUT_BUFFER, args).unwrap();
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/global.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::alloc::{GlobalAlloc, Layout};
use core::ops::{Deref, DerefMut};

use Dlmalloc;
use crate::Dlmalloc;

/// An instance of a "global allocator" backed by `Dlmalloc`
///
Expand Down Expand Up @@ -36,30 +36,30 @@ pub unsafe fn get_alloced_mem_size() -> usize {
<Dlmalloc>::get_alloced_mem_size(&get())
}

static mut DLMALLOC: Dlmalloc = Dlmalloc(::dlmalloc::DLMALLOC_INIT);
static mut DLMALLOC: Dlmalloc = Dlmalloc(crate::dlmalloc::DLMALLOC_INIT);

struct Instance;

unsafe fn get() -> Instance {
::sys::acquire_global_lock();
crate::sys::acquire_global_lock();
Instance
}

impl Deref for Instance {
type Target = Dlmalloc;
fn deref(&self) -> &Dlmalloc {
unsafe { &DLMALLOC }
unsafe { &*&raw const DLMALLOC }
}
}

impl DerefMut for Instance {
fn deref_mut(&mut self) -> &mut Dlmalloc {
unsafe { &mut DLMALLOC }
unsafe { &mut *&raw mut DLMALLOC }
}
}

impl Drop for Instance {
fn drop(&mut self) {
::sys::release_global_lock()
crate::sys::release_global_lock()
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod sys;
#[path = "macos.rs"]
mod sys;

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "android"))]
#[path = "linux.rs"]
mod sys;

Expand Down
4 changes: 2 additions & 2 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ static mut LOCK: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER;

#[cfg(feature = "global")]
pub fn acquire_global_lock() {
unsafe { assert_eq!(libc::pthread_mutex_lock(&mut LOCK), 0) }
unsafe { assert_eq!(libc::pthread_mutex_lock(&mut *&raw mut LOCK), 0) }
}

#[cfg(feature = "global")]
pub fn release_global_lock() {
unsafe { assert_eq!(libc::pthread_mutex_unlock(&mut LOCK), 0) }
unsafe { assert_eq!(libc::pthread_mutex_unlock(&mut *&raw mut LOCK), 0) }
}
2 changes: 1 addition & 1 deletion tests/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn map() {

#[test]
fn strings() {
format!("foo, bar, {}", "baz");
let _ = format!("foo, bar, {}", "baz");
}

#[test]
Expand Down