Skip to content

Commit c0dc2cb

Browse files
committed
Auto merge of #29026 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #28988, #28989, #28990, #28997, #29007, #29015 - Failed merges: #28906
2 parents ec4362d + 1537545 commit c0dc2cb

File tree

7 files changed

+124
-114
lines changed

7 files changed

+124
-114
lines changed

src/doc/trpl/error-handling.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ for pop in search(&data_file, &city) {
18981898

18991899
In this piece of code, we take `file` (which has the type
19001900
`Option<String>`), and convert it to a type that `search` can use, in
1901-
this case, `&Option<AsRef<Path>>`. Do do this, we take a reference of
1901+
this case, `&Option<AsRef<Path>>`. To do this, we take a reference of
19021902
file, and map `Path::new` onto it. In this case, `as_ref()` converts
19031903
the `Option<String>` into an `Option<&str>`, and from there, we can
19041904
execute `Path::new` to the content of the optional, and return the

src/doc/trpl/iterators.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ own iterator involves implementing the `Iterator` trait. While doing that is
4444
outside of the scope of this guide, Rust provides a number of useful iterators
4545
to accomplish various tasks. But first, a few notes about limitations of ranges.
4646

47-
Ranges are very primitive, and we often can use better alternatives. Consider
47+
Ranges are very primitive, and we often can use better alternatives. Consider the
4848
following Rust anti-pattern: using ranges to emulate a C-style `for` loop. Let’s
4949
suppose you needed to iterate over the contents of a vector. You may be tempted
5050
to write this:

src/doc/trpl/lifetimes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% Lifetimes
22

3-
This guide is one of three presenting Rust’s ownership system. This is one of
3+
This guide is three of three presenting Rust’s ownership system. This is one of
44
Rust’s most unique and compelling features, with which Rust developers should
55
become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own chapter:

src/doc/trpl/references-and-borrowing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% References and Borrowing
22

3-
This guide is one of three presenting Rust’s ownership system. This is one of
3+
This guide is two of three presenting Rust’s ownership system. This is one of
44
Rust’s most unique and compelling features, with which Rust developers should
55
become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own

src/liballoc_jemalloc/lib.rs

+22-11
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ use libc::{c_int, c_void, size_t};
4343
extern {
4444
fn je_mallocx(size: size_t, flags: c_int) -> *mut c_void;
4545
fn je_rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void;
46-
fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t,
47-
flags: c_int) -> size_t;
46+
fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t;
4847
fn je_sdallocx(ptr: *mut c_void, size: size_t, flags: c_int);
4948
fn je_nallocx(size: size_t, flags: c_int) -> size_t;
5049
}
@@ -63,40 +62,52 @@ const MIN_ALIGN: usize = 8;
6362
const MIN_ALIGN: usize = 16;
6463

6564
// MALLOCX_ALIGN(a) macro
66-
fn mallocx_align(a: usize) -> c_int { a.trailing_zeros() as c_int }
65+
fn mallocx_align(a: usize) -> c_int {
66+
a.trailing_zeros() as c_int
67+
}
6768

6869
fn align_to_flags(align: usize) -> c_int {
69-
if align <= MIN_ALIGN { 0 } else { mallocx_align(align) }
70+
if align <= MIN_ALIGN {
71+
0
72+
} else {
73+
mallocx_align(align)
74+
}
7075
}
7176

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

7883
#[no_mangle]
79-
pub extern fn __rust_reallocate(ptr: *mut u8, _old_size: usize, size: usize,
80-
align: usize) -> *mut u8 {
84+
pub extern "C" fn __rust_reallocate(ptr: *mut u8,
85+
_old_size: usize,
86+
size: usize,
87+
align: usize)
88+
-> *mut u8 {
8189
let flags = align_to_flags(align);
8290
unsafe { je_rallocx(ptr as *mut c_void, size as size_t, flags) as *mut u8 }
8391
}
8492

8593
#[no_mangle]
86-
pub extern fn __rust_reallocate_inplace(ptr: *mut u8, _old_size: usize,
87-
size: usize, align: usize) -> usize {
94+
pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8,
95+
_old_size: usize,
96+
size: usize,
97+
align: usize)
98+
-> usize {
8899
let flags = align_to_flags(align);
89100
unsafe { je_xallocx(ptr as *mut c_void, size as size_t, 0, flags) as usize }
90101
}
91102

92103
#[no_mangle]
93-
pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
104+
pub extern "C" fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
94105
let flags = align_to_flags(align);
95106
unsafe { je_sdallocx(ptr as *mut c_void, old_size as size_t, flags) }
96107
}
97108

98109
#[no_mangle]
99-
pub extern fn __rust_usable_size(size: usize, align: usize) -> usize {
110+
pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize {
100111
let flags = align_to_flags(align);
101112
unsafe { je_nallocx(size as size_t, flags) as usize }
102113
}

src/liballoc_system/lib.rs

+48-29
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,35 @@ const MIN_ALIGN: usize = 8;
3939
const MIN_ALIGN: usize = 16;
4040

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

4646
#[no_mangle]
47-
pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
47+
pub extern "C" fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
4848
unsafe { imp::deallocate(ptr, old_size, align) }
4949
}
5050

5151
#[no_mangle]
52-
pub extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize,
53-
align: usize) -> *mut u8 {
52+
pub extern "C" fn __rust_reallocate(ptr: *mut u8,
53+
old_size: usize,
54+
size: usize,
55+
align: usize)
56+
-> *mut u8 {
5457
unsafe { imp::reallocate(ptr, old_size, size, align) }
5558
}
5659

5760
#[no_mangle]
58-
pub extern fn __rust_reallocate_inplace(ptr: *mut u8, old_size: usize,
59-
size: usize, align: usize) -> usize {
61+
pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8,
62+
old_size: usize,
63+
size: usize,
64+
align: usize)
65+
-> usize {
6066
unsafe { imp::reallocate_inplace(ptr, old_size, size, align) }
6167
}
6268

6369
#[no_mangle]
64-
pub extern fn __rust_usable_size(size: usize, align: usize) -> usize {
70+
pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize {
6571
imp::usable_size(size, align)
6672
}
6773

@@ -80,7 +86,8 @@ mod imp {
8086
#[cfg(not(target_os = "android"))]
8187
fn posix_memalign(memptr: *mut *mut libc::c_void,
8288
align: libc::size_t,
83-
size: libc::size_t) -> libc::c_int;
89+
size: libc::size_t)
90+
-> libc::c_int;
8491
}
8592

8693
pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 {
@@ -94,9 +101,7 @@ mod imp {
94101
#[cfg(not(target_os = "android"))]
95102
unsafe fn more_aligned_malloc(size: usize, align: usize) -> *mut u8 {
96103
let mut out = ptr::null_mut();
97-
let ret = posix_memalign(&mut out,
98-
align as libc::size_t,
99-
size as libc::size_t);
104+
let ret = posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);
100105
if ret != 0 {
101106
ptr::null_mut()
102107
} else {
@@ -107,8 +112,7 @@ mod imp {
107112
}
108113
}
109114

110-
pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize,
111-
align: usize) -> *mut u8 {
115+
pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 {
112116
if align <= MIN_ALIGN {
113117
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
114118
} else {
@@ -119,8 +123,11 @@ mod imp {
119123
}
120124
}
121125

122-
pub unsafe fn reallocate_inplace(_ptr: *mut u8, old_size: usize, _size: usize,
123-
_align: usize) -> usize {
126+
pub unsafe fn reallocate_inplace(_ptr: *mut u8,
127+
old_size: usize,
128+
_size: usize,
129+
_align: usize)
130+
-> usize {
124131
old_size
125132
}
126133

@@ -141,8 +148,7 @@ mod imp {
141148
extern "system" {
142149
fn GetProcessHeap() -> HANDLE;
143150
fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
144-
fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID,
145-
dwBytes: SIZE_T) -> LPVOID;
151+
fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID, dwBytes: SIZE_T) -> LPVOID;
146152
fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
147153
}
148154

@@ -165,32 +171,45 @@ mod imp {
165171
if align <= MIN_ALIGN {
166172
HeapAlloc(GetProcessHeap(), 0, size as SIZE_T) as *mut u8
167173
} else {
168-
let ptr = HeapAlloc(GetProcessHeap(), 0,
169-
(size + align) as SIZE_T) as *mut u8;
170-
if ptr.is_null() { return ptr }
174+
let ptr = HeapAlloc(GetProcessHeap(), 0, (size + align) as SIZE_T) as *mut u8;
175+
if ptr.is_null() {
176+
return ptr
177+
}
171178
align_ptr(ptr, align)
172179
}
173180
}
174181

175-
pub unsafe fn reallocate(ptr: *mut u8, _old_size: usize, size: usize,
176-
align: usize) -> *mut u8 {
182+
pub unsafe fn reallocate(ptr: *mut u8, _old_size: usize, size: usize, align: usize) -> *mut u8 {
177183
if align <= MIN_ALIGN {
178184
HeapReAlloc(GetProcessHeap(), 0, ptr as LPVOID, size as SIZE_T) as *mut u8
179185
} else {
180186
let header = get_header(ptr);
181-
let new = HeapReAlloc(GetProcessHeap(), 0, header.0 as LPVOID,
187+
let new = HeapReAlloc(GetProcessHeap(),
188+
0,
189+
header.0 as LPVOID,
182190
(size + align) as SIZE_T) as *mut u8;
183-
if new.is_null() { return new }
191+
if new.is_null() {
192+
return new
193+
}
184194
align_ptr(new, align)
185195
}
186196
}
187197

188-
pub unsafe fn reallocate_inplace(ptr: *mut u8, old_size: usize, size: usize,
189-
align: usize) -> usize {
198+
pub unsafe fn reallocate_inplace(ptr: *mut u8,
199+
old_size: usize,
200+
size: usize,
201+
align: usize)
202+
-> usize {
190203
if align <= MIN_ALIGN {
191-
let new = HeapReAlloc(GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY,
192-
ptr as LPVOID, size as SIZE_T) as *mut u8;
193-
if new.is_null() { old_size } else { size }
204+
let new = HeapReAlloc(GetProcessHeap(),
205+
HEAP_REALLOC_IN_PLACE_ONLY,
206+
ptr as LPVOID,
207+
size as SIZE_T) as *mut u8;
208+
if new.is_null() {
209+
old_size
210+
} else {
211+
size
212+
}
194213
} else {
195214
old_size
196215
}

0 commit comments

Comments
 (0)