rusticl/proc: make generated entry points unsafe

Reviewed-by: @LingMan
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32268>
This commit is contained in:
Karol Herbst 2024-12-03 01:10:32 +01:00 committed by Marge Bot
parent 3a155a4591
commit 3692bb3429
2 changed files with 15 additions and 13 deletions

View file

@ -438,29 +438,31 @@ macro_rules! impl_cl_type_trait {
// We need those functions exported
#[no_mangle]
extern "C" fn clGetPlatformInfo(
unsafe extern "C" fn clGetPlatformInfo(
platform: cl_platform_id,
param_name: cl_platform_info,
param_value_size: usize,
param_value: *mut ::std::ffi::c_void,
param_value_size_ret: *mut usize,
) -> cl_int {
platform::clGetPlatformInfo(
platform,
param_name,
param_value_size,
param_value,
param_value_size_ret,
)
unsafe {
platform::clGetPlatformInfo(
platform,
param_name,
param_value_size,
param_value,
param_value_size_ret,
)
}
}
#[no_mangle]
extern "C" fn clIcdGetPlatformIDsKHR(
unsafe extern "C" fn clIcdGetPlatformIDsKHR(
num_entries: cl_uint,
platforms: *mut cl_platform_id,
num_platforms: *mut cl_uint,
) -> cl_int {
clGetPlatformIDs(num_entries, platforms, num_platforms)
unsafe { clGetPlatformIDs(num_entries, platforms, num_platforms) }
}
macro_rules! cl_ext_func {

View file

@ -102,7 +102,7 @@ pub fn cl_entrypoint(attr: TokenStream, item: TokenStream) -> TokenStream {
let mut res: TokenStream = if ret_type == "()" {
// trivial case: return the `Err(err)` as is
format!(
"pub extern \"C\" fn {attr}(
"pub unsafe extern \"C\" fn {attr}(
{args}
) -> cl_int {{
match {name}({arg_names_str}) {{
@ -116,7 +116,7 @@ pub fn cl_entrypoint(attr: TokenStream, item: TokenStream) -> TokenStream {
// which return an object do have the `errcode_ret: *mut cl_int` argument last, so we can
// just make use of this here.
format!(
"pub extern \"C\" fn {attr}(
"pub unsafe extern \"C\" fn {attr}(
{args}
errcode_ret: *mut cl_int,
) -> {ret_type} {{
@ -190,7 +190,7 @@ pub fn cl_info_entrypoint(attr: TokenStream, item: TokenStream) -> TokenStream {
};
let mut res: TokenStream = format!(
"pub extern \"C\" fn {attr}(
"pub unsafe extern \"C\" fn {attr}(
input: {name},
{args}
param_name: {arg},