Skip to content

Commit 43ad11c

Browse files
committed
auto merge of #20237 : RustOS-Fork-Holding-Ground/rust/master, r=alexcrichton
libc is only used when the heap allocations are not defined externally, or defined in another crate. I assume these extern* configurations were added for the sake of those of us experimenting with freestanding Rust. Avoiding libc where possible is often very important for us.
2 parents fc2ba13 + fd44247 commit 43ad11c

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/liballoc/heap.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,19 @@ unsafe fn exchange_free(ptr: *mut u8, old_size: uint, align: uint) {
115115
// The minimum alignment guaranteed by the architecture. This value is used to
116116
// add fast paths for low alignment values. In practice, the alignment is a
117117
// constant at the call site and the branch will be optimized out.
118-
#[cfg(any(target_arch = "arm",
119-
target_arch = "mips",
120-
target_arch = "mipsel"))]
118+
#[cfg(all(not(feature = "external_funcs"),
119+
not(feature = "external_crate"),
120+
any(target_arch = "arm",
121+
target_arch = "mips",
122+
target_arch = "mipsel")))]
121123
const MIN_ALIGN: uint = 8;
122-
#[cfg(any(target_arch = "x86",
123-
target_arch = "x86_64"))]
124+
#[cfg(all(not(feature = "external_funcs"),
125+
not(feature = "external_crate"),
126+
any(target_arch = "x86",
127+
target_arch = "x86_64")))]
124128
const MIN_ALIGN: uint = 16;
125129

126-
#[cfg(external_funcs)]
130+
#[cfg(feature = "external_funcs")]
127131
mod imp {
128132
extern {
129133
fn rust_allocate(size: uint, align: uint) -> *mut u8;
@@ -141,14 +145,13 @@ mod imp {
141145
}
142146

143147
#[inline]
144-
pub unsafe fn reallocate_inplace(ptr: *mut u8, old_size: uint, size: uint,
145-
align: uint) -> uint {
146-
rust_reallocate_inplace(ptr, old_size, size, align)
148+
pub unsafe fn deallocate(ptr: *mut u8, old_size: uint, align: uint) {
149+
rust_deallocate(ptr, old_size, align)
147150
}
148151

149152
#[inline]
150-
pub unsafe fn deallocate(ptr: *mut u8, old_size: uint, align: uint) {
151-
rust_deallocate(ptr, old_size, align)
153+
pub unsafe fn reallocate(ptr: *mut u8, old_size: uint, size: uint, align: uint) -> *mut u8 {
154+
rust_reallocate(ptr, old_size, size, align)
152155
}
153156

154157
#[inline]
@@ -168,14 +171,16 @@ mod imp {
168171
}
169172
}
170173

171-
#[cfg(external_crate)]
174+
#[cfg(feature = "external_crate")]
172175
mod imp {
173176
extern crate external;
174177
pub use self::external::{allocate, deallocate, reallocate_inplace, reallocate};
175178
pub use self::external::{usable_size, stats_print};
176179
}
177180

178-
#[cfg(all(not(external_funcs), not(external_crate), jemalloc))]
181+
#[cfg(all(not(feature = "external_funcs"),
182+
not(feature = "external_crate"),
183+
jemalloc))]
179184
mod imp {
180185
use core::option::Option;
181186
use core::option::Option::None;
@@ -252,7 +257,10 @@ mod imp {
252257
}
253258
}
254259

255-
#[cfg(all(not(external_funcs), not(external_crate), not(jemalloc), unix))]
260+
#[cfg(all(not(feature = "external_funcs"),
261+
not(feature = "external_crate"),
262+
not(jemalloc),
263+
unix))]
256264
mod imp {
257265
use core::cmp;
258266
use core::ptr;
@@ -313,7 +321,10 @@ mod imp {
313321
pub fn stats_print() {}
314322
}
315323

316-
#[cfg(all(not(external_funcs), not(external_crate), not(jemalloc), windows))]
324+
#[cfg(all(not(feature = "external_funcs"),
325+
not(feature = "external_crate"),
326+
not(jemalloc),
327+
windows))]
317328
mod imp {
318329
use libc::{c_void, size_t};
319330
use libc;

src/liballoc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070

7171
#[phase(plugin, link)]
7272
extern crate core;
73+
74+
#[cfg(all(not(feature = "external_funcs"), not(feature = "external_crate")))]
7375
extern crate libc;
7476

7577
// Allow testing this library

0 commit comments

Comments
 (0)