Lines Matching +full:self +full:- +full:test
1 // SPDX-License-Identifier: Apache-2.0 OR MIT
7 #[cfg(not(test))]
10 #[cfg(not(test))]
11 use core::ptr::{self, NonNull};
17 #[cfg(test)]
26 …// The rustc fork of LLVM 14 and earlier also special-cases these function names to be able to opt…
30 fn __rust_alloc(size: usize, align: usize) -> *mut u8; in __rust_alloc()
36 fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8; in __rust_realloc()
39 fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8; in __rust_alloc_zeroed()
51 /// accessed through the [free functions in `alloc`](self#functions).
54 #[cfg(not(test))]
57 #[cfg(test)]
94 pub unsafe fn alloc(layout: Layout) -> *mut u8 { in alloc()
137 pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { in realloc()
141 /// Allocate zero-initialized memory with the global allocator.
171 pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 { in alloc_zeroed()
175 #[cfg(not(test))]
178 fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocError> { in alloc_impl() argument
181 // SAFETY: `layout` is non-zero in size, in alloc_impl()
193 &self, in grow_impl() argument
198 ) -> Result<NonNull<[u8]>, AllocError> { in grow_impl()
205 0 => self.alloc_impl(new_layout, zeroed), in grow_impl()
207 // SAFETY: `new_size` is non-zero as `old_size` is greater than or equal to `new_size` in grow_impl()
218 raw_ptr.add(old_size).write_bytes(0, new_size - old_size); in grow_impl()
229 let new_ptr = self.alloc_impl(new_layout, zeroed)?; in grow_impl()
231 self.deallocate(ptr, old_layout); in grow_impl()
239 #[cfg(not(test))]
242 fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { in allocate() argument
243 self.alloc_impl(layout, false) in allocate()
247 fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { in allocate_zeroed() argument
248 self.alloc_impl(layout, true) in allocate_zeroed()
252 unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { in deallocate() argument
254 // SAFETY: `layout` is non-zero in size, in deallocate()
262 &self, in grow() argument
266 ) -> Result<NonNull<[u8]>, AllocError> { in grow()
268 unsafe { self.grow_impl(ptr, old_layout, new_layout, false) } in grow()
273 &self, in grow_zeroed() argument
277 ) -> Result<NonNull<[u8]>, AllocError> { in grow_zeroed()
279 unsafe { self.grow_impl(ptr, old_layout, new_layout, true) } in grow_zeroed()
284 &self, in shrink() argument
288 ) -> Result<NonNull<[u8]>, AllocError> { in shrink()
297 self.deallocate(ptr, old_layout); in shrink()
301 // SAFETY: `new_size` is non-zero. Other conditions must be upheld by the caller in shrink()
317 let new_ptr = self.allocate(new_layout)?; in shrink()
319 self.deallocate(ptr, old_layout); in shrink()
327 #[cfg(all(not(no_global_oom_handling), not(test)))]
330 unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 { in exchange_malloc()
345 fn __rust_alloc_error_handler(size: usize, align: usize) -> !; in __rust_alloc_error_handler()
371 /// [The panic handler]: https://doc.rust-lang.org/reference/runtime.html#the-panic_handler-attribu…
372 /// [no_std]: https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute
375 #[cfg(all(not(no_global_oom_handling), not(test)))]
377 pub const fn handle_alloc_error(layout: Layout) -> ! { in handle_alloc_error()
378 const fn ct_error(_: Layout) -> ! { in handle_alloc_error()
382 fn rt_error(layout: Layout) -> ! { in handle_alloc_error()
391 // For alloc test `std::alloc::handle_alloc_error` can be used directly.
392 #[cfg(all(not(no_global_oom_handling), test))]
395 #[cfg(all(not(no_global_oom_handling), not(test)))]
403 pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! { in __rdl_oom()
406 // Its value depends on the -Zoom={panic,abort} compiler option. in __rdl_oom()
421 /// Specialize clones into pre-allocated, uninitialized memory.
424 unsafe fn write_clone_into_raw(&self, target: *mut Self); in write_clone_into_raw() argument
429 default unsafe fn write_clone_into_raw(&self, target: *mut Self) { in write_clone_into_raw() argument
431 // the cloned value in-place, skipping the local and move. in write_clone_into_raw()
432 unsafe { target.write(self.clone()) }; in write_clone_into_raw()
438 unsafe fn write_clone_into_raw(&self, target: *mut Self) { in write_clone_into_raw() argument
439 // We can always copy in-place, without ever involving a local value. in write_clone_into_raw()
440 unsafe { target.copy_from_nonoverlapping(self, 1) }; in write_clone_into_raw()