Skip to content

Commit

Permalink
Auto merge of #29026 - steveklabnik:rollup, r=steveklabnik
Browse files Browse the repository at this point in the history
- Successful merges: #28988, #28989, #28990, #28997, #29007, #29015
- Failed merges: #28906
  • Loading branch information
bors committed Oct 14, 2015
2 parents ec4362d + 1537545 commit c0dc2cb
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 114 deletions.
2 changes: 1 addition & 1 deletion src/doc/trpl/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@ for pop in search(&data_file, &city) {

In this piece of code, we take `file` (which has the type
`Option<String>`), and convert it to a type that `search` can use, in
this case, `&Option<AsRef<Path>>`. Do do this, we take a reference of
this case, `&Option<AsRef<Path>>`. To do this, we take a reference of
file, and map `Path::new` onto it. In this case, `as_ref()` converts
the `Option<String>` into an `Option<&str>`, and from there, we can
execute `Path::new` to the content of the optional, and return the
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/iterators.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ own iterator involves implementing the `Iterator` trait. While doing that is
outside of the scope of this guide, Rust provides a number of useful iterators
to accomplish various tasks. But first, a few notes about limitations of ranges.

Ranges are very primitive, and we often can use better alternatives. Consider
Ranges are very primitive, and we often can use better alternatives. Consider the
following Rust anti-pattern: using ranges to emulate a C-style `for` loop. Let’s
suppose you needed to iterate over the contents of a vector. You may be tempted
to write this:
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/lifetimes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% Lifetimes

This guide is one of three presenting Rust’s ownership system. This is one of
This guide is three of three presenting Rust’s ownership system. This is one of
Rust’s most unique and compelling features, with which Rust developers should
become quite acquainted. Ownership is how Rust achieves its largest goal,
memory safety. There are a few distinct concepts, each with its own chapter:
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/references-and-borrowing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% References and Borrowing

This guide is one of three presenting Rust’s ownership system. This is one of
This guide is two of three presenting Rust’s ownership system. This is one of
Rust’s most unique and compelling features, with which Rust developers should
become quite acquainted. Ownership is how Rust achieves its largest goal,
memory safety. There are a few distinct concepts, each with its own
Expand Down
33 changes: 22 additions & 11 deletions src/liballoc_jemalloc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ use libc::{c_int, c_void, size_t};
extern {
fn je_mallocx(size: size_t, flags: c_int) -> *mut c_void;
fn je_rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void;
fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t,
flags: c_int) -> size_t;
fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t;
fn je_sdallocx(ptr: *mut c_void, size: size_t, flags: c_int);
fn je_nallocx(size: size_t, flags: c_int) -> size_t;
}
Expand All @@ -63,40 +62,52 @@ const MIN_ALIGN: usize = 8;
const MIN_ALIGN: usize = 16;

// MALLOCX_ALIGN(a) macro
fn mallocx_align(a: usize) -> c_int { a.trailing_zeros() as c_int }
fn mallocx_align(a: usize) -> c_int {
a.trailing_zeros() as c_int
}

fn align_to_flags(align: usize) -> c_int {
if align <= MIN_ALIGN { 0 } else { mallocx_align(align) }
if align <= MIN_ALIGN {
0
} else {
mallocx_align(align)
}
}

#[no_mangle]
pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
pub extern "C" fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
let flags = align_to_flags(align);
unsafe { je_mallocx(size as size_t, flags) as *mut u8 }
}

#[no_mangle]
pub extern fn __rust_reallocate(ptr: *mut u8, _old_size: usize, size: usize,
align: usize) -> *mut u8 {
pub extern "C" fn __rust_reallocate(ptr: *mut u8,
_old_size: usize,
size: usize,
align: usize)
-> *mut u8 {
let flags = align_to_flags(align);
unsafe { je_rallocx(ptr as *mut c_void, size as size_t, flags) as *mut u8 }
}

#[no_mangle]
pub extern fn __rust_reallocate_inplace(ptr: *mut u8, _old_size: usize,
size: usize, align: usize) -> usize {
pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8,
_old_size: usize,
size: usize,
align: usize)
-> usize {
let flags = align_to_flags(align);
unsafe { je_xallocx(ptr as *mut c_void, size as size_t, 0, flags) as usize }
}

#[no_mangle]
pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
pub extern "C" fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
let flags = align_to_flags(align);
unsafe { je_sdallocx(ptr as *mut c_void, old_size as size_t, flags) }
}

#[no_mangle]
pub extern fn __rust_usable_size(size: usize, align: usize) -> usize {
pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize {
let flags = align_to_flags(align);
unsafe { je_nallocx(size as size_t, flags) as usize }
}
77 changes: 48 additions & 29 deletions src/liballoc_system/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,35 @@ const MIN_ALIGN: usize = 8;
const MIN_ALIGN: usize = 16;

#[no_mangle]
pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
pub extern "C" fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
unsafe { imp::allocate(size, align) }
}

#[no_mangle]
pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
pub extern "C" fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
unsafe { imp::deallocate(ptr, old_size, align) }
}

#[no_mangle]
pub extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize,
align: usize) -> *mut u8 {
pub extern "C" fn __rust_reallocate(ptr: *mut u8,
old_size: usize,
size: usize,
align: usize)
-> *mut u8 {
unsafe { imp::reallocate(ptr, old_size, size, align) }
}

#[no_mangle]
pub extern fn __rust_reallocate_inplace(ptr: *mut u8, old_size: usize,
size: usize, align: usize) -> usize {
pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8,
old_size: usize,
size: usize,
align: usize)
-> usize {
unsafe { imp::reallocate_inplace(ptr, old_size, size, align) }
}

#[no_mangle]
pub extern fn __rust_usable_size(size: usize, align: usize) -> usize {
pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize {
imp::usable_size(size, align)
}

Expand All @@ -80,7 +86,8 @@ mod imp {
#[cfg(not(target_os = "android"))]
fn posix_memalign(memptr: *mut *mut libc::c_void,
align: libc::size_t,
size: libc::size_t) -> libc::c_int;
size: libc::size_t)
-> libc::c_int;
}

pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 {
Expand All @@ -94,9 +101,7 @@ mod imp {
#[cfg(not(target_os = "android"))]
unsafe fn more_aligned_malloc(size: usize, align: usize) -> *mut u8 {
let mut out = ptr::null_mut();
let ret = posix_memalign(&mut out,
align as libc::size_t,
size as libc::size_t);
let ret = posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);
if ret != 0 {
ptr::null_mut()
} else {
Expand All @@ -107,8 +112,7 @@ mod imp {
}
}

pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize,
align: usize) -> *mut u8 {
pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 {
if align <= MIN_ALIGN {
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
} else {
Expand All @@ -119,8 +123,11 @@ mod imp {
}
}

pub unsafe fn reallocate_inplace(_ptr: *mut u8, old_size: usize, _size: usize,
_align: usize) -> usize {
pub unsafe fn reallocate_inplace(_ptr: *mut u8,
old_size: usize,
_size: usize,
_align: usize)
-> usize {
old_size
}

Expand All @@ -141,8 +148,7 @@ mod imp {
extern "system" {
fn GetProcessHeap() -> HANDLE;
fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID,
dwBytes: SIZE_T) -> LPVOID;
fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID, dwBytes: SIZE_T) -> LPVOID;
fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
}

Expand All @@ -165,32 +171,45 @@ mod imp {
if align <= MIN_ALIGN {
HeapAlloc(GetProcessHeap(), 0, size as SIZE_T) as *mut u8
} else {
let ptr = HeapAlloc(GetProcessHeap(), 0,
(size + align) as SIZE_T) as *mut u8;
if ptr.is_null() { return ptr }
let ptr = HeapAlloc(GetProcessHeap(), 0, (size + align) as SIZE_T) as *mut u8;
if ptr.is_null() {
return ptr
}
align_ptr(ptr, align)
}
}

pub unsafe fn reallocate(ptr: *mut u8, _old_size: usize, size: usize,
align: usize) -> *mut u8 {
pub unsafe fn reallocate(ptr: *mut u8, _old_size: usize, size: usize, align: usize) -> *mut u8 {
if align <= MIN_ALIGN {
HeapReAlloc(GetProcessHeap(), 0, ptr as LPVOID, size as SIZE_T) as *mut u8
} else {
let header = get_header(ptr);
let new = HeapReAlloc(GetProcessHeap(), 0, header.0 as LPVOID,
let new = HeapReAlloc(GetProcessHeap(),
0,
header.0 as LPVOID,
(size + align) as SIZE_T) as *mut u8;
if new.is_null() { return new }
if new.is_null() {
return new
}
align_ptr(new, align)
}
}

pub unsafe fn reallocate_inplace(ptr: *mut u8, old_size: usize, size: usize,
align: usize) -> usize {
pub unsafe fn reallocate_inplace(ptr: *mut u8,
old_size: usize,
size: usize,
align: usize)
-> usize {
if align <= MIN_ALIGN {
let new = HeapReAlloc(GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY,
ptr as LPVOID, size as SIZE_T) as *mut u8;
if new.is_null() { old_size } else { size }
let new = HeapReAlloc(GetProcessHeap(),
HEAP_REALLOC_IN_PLACE_ONLY,
ptr as LPVOID,
size as SIZE_T) as *mut u8;
if new.is_null() {
old_size
} else {
size
}
} else {
old_size
}
Expand Down
Loading

0 comments on commit c0dc2cb

Please sign in to comment.