rusticl: Rename XyzCB aliases to FuncXyzCB
authorLingMan <18294-LingMan@users.noreply.gitlab.freedesktop.org>
Wed, 11 Oct 2023 15:25:04 +0000 (17:25 +0200)
committerMarge Bot <emma+marge@anholt.net>
Sun, 15 Oct 2023 00:17:10 +0000 (00:17 +0000)
This happens so the XyzCB names can be used for structs containing both the function pointer and
the provided user data. Since these aliases represent raw unsafe function pointers the `Func`
prefix was chosen over `Fn`, which is generally used for safe functions.

Unfortunately it is not possible to concatinate identifiers to create new ones without a proc macro.
Thus, specify the new alias manually instead of generating them from the existing XyzCB names.

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25669>

src/gallium/frontends/rusticl/api/context.rs
src/gallium/frontends/rusticl/api/event.rs
src/gallium/frontends/rusticl/api/icd.rs
src/gallium/frontends/rusticl/api/memory.rs
src/gallium/frontends/rusticl/api/program.rs
src/gallium/frontends/rusticl/api/types.rs
src/gallium/frontends/rusticl/core/event.rs

index 1aff561..776cf0f 100644 (file)
@@ -41,7 +41,7 @@ fn create_context(
     properties: *const cl_context_properties,
     num_devices: cl_uint,
     devices: *const cl_device_id,
-    pfn_notify: Option<CreateContextCB>,
+    pfn_notify: Option<FuncCreateContextCB>,
     user_data: *mut ::std::os::raw::c_void,
 ) -> CLResult<cl_context> {
     check_cb(&pfn_notify, user_data)?;
@@ -84,7 +84,7 @@ fn create_context(
 fn create_context_from_type(
     properties: *const cl_context_properties,
     device_type: cl_device_type,
-    pfn_notify: Option<CreateContextCB>,
+    pfn_notify: Option<FuncCreateContextCB>,
     user_data: *mut ::std::os::raw::c_void,
 ) -> CLResult<cl_context> {
     // CL_INVALID_DEVICE_TYPE if device_type is not a valid value.
@@ -124,7 +124,7 @@ fn release_context(context: cl_context) -> CLResult<()> {
 #[cl_entrypoint]
 fn set_context_destructor_callback(
     context: cl_context,
-    pfn_notify: ::std::option::Option<DeleteContextCB>,
+    pfn_notify: ::std::option::Option<FuncDeleteContextCB>,
     user_data: *mut ::std::os::raw::c_void,
 ) -> CLResult<()> {
     let c = context.get_ref()?;
index 629c9ce..0b1b2cd 100644 (file)
@@ -115,7 +115,7 @@ fn wait_for_events(num_events: cl_uint, event_list: *const cl_event) -> CLResult
 fn set_event_callback(
     event: cl_event,
     command_exec_callback_type: cl_int,
-    pfn_event_notify: Option<EventCB>,
+    pfn_event_notify: Option<FuncEventCB>,
     user_data: *mut ::std::os::raw::c_void,
 ) -> CLResult<()> {
     let e = event.get_ref()?;
index a0ede4c..ea7e3f7 100644 (file)
@@ -434,7 +434,7 @@ extern "C" fn cl_link_program(
     options: *const ::std::os::raw::c_char,
     num_input_programs: cl_uint,
     input_programs: *const cl_program,
-    pfn_notify: Option<ProgramCB>,
+    pfn_notify: Option<FuncProgramCB>,
     user_data: *mut ::std::os::raw::c_void,
     errcode_ret: *mut cl_int,
 ) -> cl_program {
index fe16ede..fa53d30 100644 (file)
@@ -350,7 +350,7 @@ fn create_sub_buffer(
 #[cl_entrypoint]
 fn set_mem_object_destructor_callback(
     memobj: cl_mem,
-    pfn_notify: Option<MemCB>,
+    pfn_notify: Option<FuncMemCB>,
     user_data: *mut ::std::os::raw::c_void,
 ) -> CLResult<()> {
     let m = memobj.get_ref()?;
@@ -2348,7 +2348,7 @@ fn enqueue_svm_free_impl(
     command_queue: cl_command_queue,
     num_svm_pointers: cl_uint,
     svm_pointers: *mut *mut c_void,
-    pfn_free_func: Option<SVMFreeCb>,
+    pfn_free_func: Option<FuncSVMFreeCb>,
     user_data: *mut c_void,
     num_events_in_wait_list: cl_uint,
     event_wait_list: *const cl_event,
@@ -2407,7 +2407,7 @@ fn enqueue_svm_free(
     command_queue: cl_command_queue,
     num_svm_pointers: cl_uint,
     svm_pointers: *mut *mut c_void,
-    pfn_free_func: Option<SVMFreeCb>,
+    pfn_free_func: Option<FuncSVMFreeCb>,
     user_data: *mut c_void,
     num_events_in_wait_list: cl_uint,
     event_wait_list: *const cl_event,
@@ -2431,7 +2431,7 @@ fn enqueue_svm_free_arm(
     command_queue: cl_command_queue,
     num_svm_pointers: cl_uint,
     svm_pointers: *mut *mut c_void,
-    pfn_free_func: Option<SVMFreeCb>,
+    pfn_free_func: Option<FuncSVMFreeCb>,
     user_data: *mut c_void,
     num_events_in_wait_list: cl_uint,
     event_wait_list: *const cl_event,
index 78ba1ed..9c4a8a5 100644 (file)
@@ -93,7 +93,7 @@ fn validate_devices<'a>(
 }
 
 fn call_cb(
-    pfn_notify: Option<ProgramCB>,
+    pfn_notify: Option<FuncProgramCB>,
     program: cl_program,
     user_data: *mut ::std::os::raw::c_void,
 ) {
@@ -276,7 +276,7 @@ fn build_program(
     num_devices: cl_uint,
     device_list: *const cl_device_id,
     options: *const c_char,
-    pfn_notify: Option<ProgramCB>,
+    pfn_notify: Option<FuncProgramCB>,
     user_data: *mut ::std::os::raw::c_void,
 ) -> CLResult<()> {
     let mut res = true;
@@ -324,7 +324,7 @@ fn compile_program(
     num_input_headers: cl_uint,
     input_headers: *const cl_program,
     header_include_names: *mut *const c_char,
-    pfn_notify: Option<ProgramCB>,
+    pfn_notify: Option<FuncProgramCB>,
     user_data: *mut ::std::os::raw::c_void,
 ) -> CLResult<()> {
     let mut res = true;
@@ -402,7 +402,7 @@ pub fn link_program(
     options: *const ::std::os::raw::c_char,
     num_input_programs: cl_uint,
     input_programs: *const cl_program,
-    pfn_notify: Option<ProgramCB>,
+    pfn_notify: Option<FuncProgramCB>,
     user_data: *mut ::std::os::raw::c_void,
 ) -> CLResult<(cl_program, cl_int)> {
     let c = context.get_arc()?;
@@ -494,7 +494,7 @@ fn set_program_specialization_constant(
 #[cl_entrypoint]
 fn set_program_release_callback(
     _program: cl_program,
-    _pfn_notify: ::std::option::Option<ProgramCB>,
+    _pfn_notify: ::std::option::Option<FuncProgramCB>,
     _user_data: *mut ::std::os::raw::c_void,
 ) -> CLResult<()> {
     Err(CL_INVALID_OPERATION)
index eac1bfb..b4a4c1a 100644 (file)
@@ -15,18 +15,18 @@ macro_rules! cl_closure {
 }
 
 macro_rules! cl_callback {
-    ($cb:ident {
+    ($cb:ident($fn_alias:ident) {
         $($p:ident : $ty:ty,)*
     }) => {
         #[allow(dead_code)]
-        pub type $cb = unsafe extern "C" fn(
+        pub type $fn_alias = unsafe extern "C" fn(
             $($p: $ty,)*
         );
     }
 }
 
 cl_callback!(
-    CreateContextCB {
+    CreateContextCB(FuncCreateContextCB) {
         errinfo: *const ::std::os::raw::c_char,
         private_info: *const ::std::ffi::c_void,
         cb: usize,
@@ -35,14 +35,14 @@ cl_callback!(
 );
 
 cl_callback!(
-    DeleteContextCB {
+    DeleteContextCB(FuncDeleteContextCB) {
         context: cl_context,
         user_data: *mut ::std::os::raw::c_void,
     }
 );
 
 cl_callback!(
-    EventCB {
+    EventCB(FuncEventCB) {
         event: cl_event,
         event_command_status: cl_int,
         user_data: *mut ::std::os::raw::c_void,
@@ -50,21 +50,21 @@ cl_callback!(
 );
 
 cl_callback!(
-    MemCB {
+    MemCB(FuncMemCB) {
         memobj: cl_mem,
         user_data: *mut ::std::os::raw::c_void,
     }
 );
 
 cl_callback!(
-    ProgramCB {
+    ProgramCB(FuncProgramCB) {
         program: cl_program,
         user_data: *mut ::std::os::raw::c_void,
     }
 );
 
 cl_callback!(
-    SVMFreeCb {
+    SVMFreeCb(FuncSVMFreeCb) {
         queue: cl_command_queue,
         num_svm_pointers: cl_uint,
         svm_pointers: *mut *mut ::std::os::raw::c_void,
index a229693..e514647 100644 (file)
@@ -37,7 +37,7 @@ pub enum EventTimes {
 #[derive(Default)]
 struct EventMutState {
     status: cl_int,
-    cbs: [Vec<(EventCB, *mut c_void)>; 3],
+    cbs: [Vec<(FuncEventCB, *mut c_void)>; 3],
     work: Option<EventSig>,
     time_queued: cl_ulong,
     time_submit: cl_ulong,
@@ -161,7 +161,7 @@ impl Event {
         }
     }
 
-    pub fn add_cb(&self, state: cl_int, cb: EventCB, data: *mut c_void) {
+    pub fn add_cb(&self, state: cl_int, cb: FuncEventCB, data: *mut c_void) {
         let mut lock = self.state();
         let status = lock.status;