• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2023 Google LLC.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 use std::alloc::{alloc, Layout};
9 
10 #[no_mangle]
proto2_rust_alloc(size: usize, align: usize) -> *mut u811 extern "C" fn proto2_rust_alloc(size: usize, align: usize) -> *mut u8 {
12     if size == 0 {
13         // A 0-sized layout is legal but the global allocator isn't required to support
14         // it so return a dangling pointer instead.
15         std::ptr::null_mut::<u8>().wrapping_add(align)
16     } else {
17         let layout = Layout::from_size_align(size, align).unwrap();
18         unsafe { alloc(layout) }
19     }
20 }
21