dep-protobuf/rust/cpp_kernel/rust_alloc_for_cpp_api.rs
Adam Cozzette 3ff832936e Start testing against Rust edition 2024
This change also makes all the necessary fixes to get us compatible with
edition 2024.

I set things up so that we test edition 2024 with Bazel but keep Cargo on
edition 2021. This seems like a nice way to go since it allows us to get full
test coverage of both editions without us having to increment our minimum
supported Rust version.

PiperOrigin-RevId: 816241556
2025-10-07 09:21:51 -07:00

20 lines
748 B
Rust

// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
//
// 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
use std::alloc::{alloc, Layout};
#[unsafe(no_mangle)]
unsafe extern "C" fn proto2_rust_alloc(size: usize, align: usize) -> *mut u8 {
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 {
let layout = Layout::from_size_align(size, align).unwrap();
unsafe { alloc(layout) }
}
}