/src/test/run-pass/auxiliary/allocator-dummy.rs

https://gitlab.com/alx741/rust · Rust · 55 lines · 36 code · 9 blank · 10 comment · 0 complexity · a4c552e656cb8d4a45e7386d1fd18449 MD5 · raw file

  1. // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. // no-prefer-dynamic
  11. #![feature(allocator, core_intrinsics, libc)]
  12. #![allocator]
  13. #![crate_type = "rlib"]
  14. #![no_std]
  15. extern crate libc;
  16. pub static mut HITS: usize = 0;
  17. #[no_mangle]
  18. pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
  19. unsafe {
  20. HITS += 1;
  21. libc::malloc(size as libc::size_t) as *mut u8
  22. }
  23. }
  24. #[no_mangle]
  25. pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
  26. unsafe {
  27. HITS += 1;
  28. libc::free(ptr as *mut _)
  29. }
  30. }
  31. #[no_mangle]
  32. pub extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize,
  33. align: usize) -> *mut u8 {
  34. unsafe {
  35. libc::realloc(ptr as *mut _, size as libc::size_t) as *mut u8
  36. }
  37. }
  38. #[no_mangle]
  39. pub extern fn __rust_reallocate_inplace(ptr: *mut u8, old_size: usize,
  40. size: usize, align: usize) -> usize {
  41. unsafe { core::intrinsics::abort() }
  42. }
  43. #[no_mangle]
  44. pub extern fn __rust_usable_size(size: usize, align: usize) -> usize {
  45. unsafe { core::intrinsics::abort() }
  46. }