2023-04-11 12:57:07 -07:00
|
|
|
// Protocol Buffers - Google's data interchange format
|
2023-07-10 07:35:36 -07:00
|
|
|
// Copyright 2023 Google LLC. All rights reserved.
|
2023-04-11 12:57:07 -07:00
|
|
|
//
|
2023-09-09 08:59:23 -07:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2023-04-11 12:57:07 -07:00
|
|
|
|
|
|
|
|
use std::alloc::{alloc, Layout};
|
|
|
|
|
|
2025-10-07 09:18:58 -07:00
|
|
|
#[unsafe(no_mangle)]
|
|
|
|
|
unsafe extern "C" fn proto2_rust_alloc(size: usize, align: usize) -> *mut u8 {
|
2024-02-14 07:38:34 -08:00
|
|
|
if size == 0 {
|
|
|
|
|
// A 0-sized layout is legal but the global allocator isn't required to support
|
|
|
|
|
// it so return a dangling pointer instead.
|
|
|
|
|
std::ptr::null_mut::<u8>().wrapping_add(align)
|
|
|
|
|
} else {
|
2024-03-06 05:39:03 -08:00
|
|
|
let layout = Layout::from_size_align(size, align).unwrap();
|
2024-02-14 07:38:34 -08:00
|
|
|
unsafe { alloc(layout) }
|
|
|
|
|
}
|
2023-04-11 12:57:07 -07:00
|
|
|
}
|