Skip to content

Commit 2ca1f0b

Browse files
committed
Switch back to alloc_system
1 parent 7697c72 commit 2ca1f0b

File tree

2 files changed

+6
-49
lines changed

2 files changed

+6
-49
lines changed

src/liballoc_system/lib.rs

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
issue = "27783")]
2020
#![feature(allocator)]
2121
#![feature(staged_api)]
22-
#![cfg_attr(target_os = "redox", feature(libc))]
23-
#![cfg_attr(unix, feature(libc))]
22+
#![cfg_attr(any(unix, target_os = "redox"), feature(libc))]
2423

2524
// The minimum alignment guaranteed by the architecture. This value is used to
2625
// add fast paths for low alignment values. In practice, the alignment is a
@@ -72,49 +71,7 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize {
7271
imp::usable_size(size, align)
7372
}
7473

75-
#[cfg(target_os = "redox")]
76-
mod imp {
77-
extern crate libc;
78-
79-
use core::cmp;
80-
use core::ptr;
81-
use MIN_ALIGN;
82-
83-
pub unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
84-
libc::malloc(size as libc::size_t) as *mut u8
85-
}
86-
87-
pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 {
88-
if align <= MIN_ALIGN {
89-
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
90-
} else {
91-
let new_ptr = allocate(size, align);
92-
if !new_ptr.is_null() {
93-
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
94-
deallocate(ptr, old_size, align);
95-
}
96-
new_ptr
97-
}
98-
}
99-
100-
pub unsafe fn reallocate_inplace(_ptr: *mut u8,
101-
old_size: usize,
102-
_size: usize,
103-
_align: usize)
104-
-> usize {
105-
old_size
106-
}
107-
108-
pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, _align: usize) {
109-
libc::free(ptr as *mut libc::c_void)
110-
}
111-
112-
pub fn usable_size(size: usize, _align: usize) -> usize {
113-
size
114-
}
115-
}
116-
117-
#[cfg(any(unix))]
74+
#[cfg(any(unix, target_os = "redox"))]
11875
mod imp {
11976
extern crate libc;
12077

@@ -130,7 +87,7 @@ mod imp {
13087
}
13188
}
13289

133-
#[cfg(target_os = "android")]
90+
#[cfg(any(target_os = "android", target_os = "redox"))]
13491
unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 {
13592
// On android we currently target API level 9 which unfortunately
13693
// doesn't have the `posix_memalign` API used below. Instead we use
@@ -152,7 +109,7 @@ mod imp {
152109
libc::memalign(align as libc::size_t, size as libc::size_t) as *mut u8
153110
}
154111

155-
#[cfg(not(target_os = "android"))]
112+
#[cfg(not(any(target_os = "android", target_os = "redox")))]
156113
unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 {
157114
let mut out = ptr::null_mut();
158115
let ret = libc::posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);

src/librustc_back/target/redox_base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub fn opts() -> TargetOptions {
4040
target_family: Some("redox".to_string()),
4141
linker_is_gnu: true,
4242
no_default_libraries: true,
43-
lib_allocation_crate: "ralloc".to_string(),
44-
exe_allocation_crate: "ralloc".to_string(),
43+
lib_allocation_crate: "alloc_system".to_string(),
44+
exe_allocation_crate: "alloc_system".to_string(),
4545
has_elf_tls: true,
4646
panic_strategy: PanicStrategy::Abort,
4747
.. Default::default()

0 commit comments

Comments
 (0)