diff --git a/build.rs b/build.rs index 26231139b..ef51c8e49 100644 --- a/build.rs +++ b/build.rs @@ -1722,7 +1722,7 @@ pub fn generate_generic_closure_cpp(macro_func: &[FunctionSignature]) -> String .typename .typename .replace(&format!(" (*{})", &processed_f.args[1].name), ""); - let callback_typename = f.func_name.clone() + "_callabck_t"; + let callback_typename = f.func_name.clone() + "_callback_t"; out += &format!( "extern \"C\" using {} = {};\n", callback_typename, prototype diff --git a/docs/api.rst b/docs/api.rst index fc4189a0d..943d5b846 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -509,7 +509,6 @@ Types .. doxygenstruct:: z_loaned_closure_zid_t .. doxygenstruct:: z_owned_closure_zid_t - :members: Functions ^^^^^^^^^ @@ -557,7 +556,6 @@ Types .. doxygenstruct:: zc_owned_matching_listener_t .. doxygenstruct:: zc_owned_closure_matching_status_t - :members: Functions --------- @@ -602,7 +600,6 @@ Types .. doxygenstruct:: z_loaned_closure_sample_t .. doxygenstruct:: z_owned_closure_sample_t - :members: .. doxygenstruct:: z_subscriber_options_t :members: @@ -655,7 +652,6 @@ Types .. doxygenstruct:: z_loaned_closure_query_t .. doxygenstruct:: z_owned_closure_query_t - :members: .. doxygenstruct:: z_queryable_options_t :members: @@ -725,7 +721,6 @@ Types .. doxygenstruct:: z_loaned_closure_reply_t .. doxygenstruct:: z_owned_closure_reply_t - :members: .. doxygenstruct:: z_get_options_t :members: @@ -788,7 +783,6 @@ Types :members: .. doxygenstruct:: z_loaned_closure_hello_t .. doxygenstruct:: z_owned_closure_hello_t - :members: Functions --------- diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index c77b90a28..dea7b330b 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -282,29 +282,14 @@ typedef struct z_close_options_t { uint8_t _dummy; } z_close_options_t; /** - * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: - * - * Closures are not guaranteed not to be called concurrently. - * - * It is guaranteed that: + * @brief A hello message-processing closure. * - * - `call` will never be called once `drop` has started. - * - `drop` will only be called **once**, and **after every** `call` has ended. - * - The two previous guarantees imply that `call` and `drop` are never called concurrently. + * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. */ typedef struct z_owned_closure_hello_t { - /** - * An optional pointer to a closure state. - */ - void *context; - /** - * A closure body. - */ - void (*call)(struct z_loaned_hello_t *hello, void *context); - /** - * An optional drop function that will be called when the closure is dropped. - */ - void (*drop)(void *context); + void *_context; + void (*_call)(struct z_loaned_hello_t *hello, void *context); + void (*_drop)(void *context); } z_owned_closure_hello_t; /** * Moved closure. @@ -313,28 +298,14 @@ typedef struct z_moved_closure_hello_t { struct z_owned_closure_hello_t _this; } z_moved_closure_hello_t; /** - * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: - * - * Closures are not guaranteed not to be called concurrently. + * @brief A query-processing closure. * - * It is guaranteed that: - * - `call` will never be called once `drop` has started. - * - `drop` will only be called **once**, and **after every** `call` has ended. - * - The two previous guarantees imply that `call` and `drop` are never called concurrently. + * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. */ typedef struct z_owned_closure_query_t { - /** - * An optional pointer to a context representing a closure state. - */ - void *context; - /** - * A closure body. - */ - void (*call)(struct z_loaned_query_t *reply, void *context); - /** - * An optional drop function that will be called when the closure is dropped. - */ - void (*drop)(void *context); + void *_context; + void (*_call)(struct z_loaned_query_t *reply, void *context); + void (*_drop)(void *context); } z_owned_closure_query_t; /** * Moved closure. @@ -343,28 +314,14 @@ typedef struct z_moved_closure_query_t { struct z_owned_closure_query_t _this; } z_moved_closure_query_t; /** - * A structure that contains all the elements for stateful, memory-leak-free callbacks. - * - * Closures are not guaranteed not to be called concurrently. + * @brief A reply-processing closure. * - * It is guaranteed that: - * - `call` will never be called once `drop` has started. - * - `drop` will only be called **once**, and **after every** `call` has ended. - * - The two previous guarantees imply that `call` and `drop` are never called concurrently. + * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. */ typedef struct z_owned_closure_reply_t { - /** - * An optional pointer to a context representing a closure state. - */ - void *context; - /** - * A closure body. - */ - void (*call)(struct z_loaned_reply_t *reply, void *context); - /** - * An optional drop function that will be called when the closure is dropped. - */ - void (*drop)(void *context); + void *_context; + void (*_call)(struct z_loaned_reply_t *reply, void *context); + void (*_drop)(void *context); } z_owned_closure_reply_t; /** * Moved closure. @@ -373,28 +330,14 @@ typedef struct z_moved_closure_reply_t { struct z_owned_closure_reply_t _this; } z_moved_closure_reply_t; /** - * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. - * - * Closures are not guaranteed not to be called concurrently. + * @brief A sample-processing closure. * - * It is guaranteed that: - * - `call` will never be called once `drop` has started. - * - `drop` will only be called **once**, and **after every** `call` has ended. - * - The two previous guarantees imply that `call` and `drop` are never called concurrently. + * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. */ typedef struct z_owned_closure_sample_t { - /** - * An optional pointer to a context representing a closure state. - */ - void *context; - /** - * A closure body. - */ - void (*call)(struct z_loaned_sample_t *sample, void *context); - /** - * An optional drop function that will be called when the closure is dropped. - */ - void (*drop)(void *context); + void *_context; + void (*_call)(struct z_loaned_sample_t *sample, void *context); + void (*_drop)(void *context); } z_owned_closure_sample_t; /** * Moved closure. @@ -404,29 +347,15 @@ typedef struct z_moved_closure_sample_t { } z_moved_closure_sample_t; /** * @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. - * @brief A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: + * @brief A zenoh id-processing closure. * - * Closures are not guaranteed not to be called concurrently. - * - * It is guaranteed that: - * - `call` will never be called once `drop` has started. - * - `drop` will only be called **once**, and **after every** `call` has ended. - * - The two previous guarantees imply that `call` and `drop` are never called concurrently. + * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: */ #if defined(Z_FEATURE_UNSTABLE_API) typedef struct z_owned_closure_zid_t { - /** - * An optional pointer to a closure state. - */ - void *context; - /** - * A callback function. - */ - void (*call)(const struct z_id_t *z_id, void *context); - /** - * An optional function that will be called upon closure drop. - */ - void (*drop)(void *context); + void *_context; + void (*_call)(const struct z_id_t *z_id, void *context); + void (*_drop)(void *context); } z_owned_closure_zid_t; #endif /** @@ -890,28 +819,14 @@ typedef struct z_time_t { uint64_t t; } z_time_t; /** - * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: + * @brief A log-processing closure. * - * Closures are not guaranteed not to be called concurrently. - * - * It is guaranteed that: - * - `call` will never be called once `drop` has started. - * - `drop` will only be called **once**, and **after every** `call` has ended. - * - The two previous guarantees imply that `call` and `drop` are never called concurrently. + * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. */ typedef struct zc_owned_closure_log_t { - /** - * An optional pointer to a closure state. - */ - void *context; - /** - * A closure body. - */ - void (*call)(enum zc_log_severity_t severity, const struct z_loaned_string_t *msg, void *context); - /** - * An optional drop function that will be called when the closure is dropped. - */ - void (*drop)(void *context); + void *_context; + void (*_call)(enum zc_log_severity_t severity, const struct z_loaned_string_t *msg, void *context); + void (*_drop)(void *context); } zc_owned_closure_log_t; /** * Moved closure. @@ -933,29 +848,15 @@ typedef struct zc_matching_status_t { #endif /** * @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. - * @brief A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: + * @brief A matching status-processing closure. * - * Closures are not guaranteed not to be called concurrently. - * - * It is guaranteed that: - * - `call` will never be called once `drop` has started. - * - `drop` will only be called **once**, and **after every** `call` has ended. - * - The two previous guarantees imply that `call` and `drop` are never called concurrently. + * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. */ #if defined(Z_FEATURE_UNSTABLE_API) typedef struct zc_owned_closure_matching_status_t { - /** - * An optional pointer to a closure state. - */ - void *context; - /** - * A closure body. - */ - void (*call)(const struct zc_matching_status_t *matching_status, void *context); - /** - * An optional drop function that will be called when the closure is dropped. - */ - void (*drop)(void *context); + void *_context; + void (*_call)(const struct zc_matching_status_t *matching_status, void *context); + void (*_drop)(void *context); } zc_owned_closure_matching_status_t; #endif /** @@ -1516,6 +1417,15 @@ z_result_t z_close(struct z_loaned_session_t *session, ZENOHC_API void z_close_options_default(struct z_close_options_t *this_); /** * @brief Constructs closure. + * A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: + * + * Closures are not guaranteed not to be called concurrently. + * + * It is guaranteed that: + * + * - `call` will never be called once `drop` has started. + * - `drop` will only be called **once**, and **after every** `call` has ended. + * - The two previous guarantees imply that `call` and `drop` are never called concurrently. * @param this_: uninitialized memory location where new closure will be constructed. * @param call: a closure body. * @param drop: an optional function to be called once on closure drop. @@ -1543,6 +1453,13 @@ ZENOHC_API const struct z_loaned_closure_hello_t *z_closure_hello_loan(const struct z_owned_closure_hello_t *closure); /** * @brief Constructs closure. + * + * Closures are not guaranteed not to be called concurrently. + * + * It is guaranteed that: + * - `call` will never be called once `drop` has started. + * - `drop` will only be called **once**, and **after every** `call` has ended. + * - The two previous guarantees imply that `call` and `drop` are never called concurrently. * @param this_: uninitialized memory location where new closure will be constructed. * @param call: a closure body. * @param drop: an optional function to be called once on closure drop. @@ -1570,6 +1487,13 @@ ZENOHC_API const struct z_loaned_closure_query_t *z_closure_query_loan(const struct z_owned_closure_query_t *closure); /** * @brief Constructs closure. + * + * Closures are not guaranteed not to be called concurrently. + * + * It is guaranteed that: + * - `call` will never be called once `drop` has started. + * - `drop` will only be called **once**, and **after every** `call` has ended. + * - The two previous guarantees imply that `call` and `drop` are never called concurrently. * @param this_: uninitialized memory location where new closure will be constructed. * @param call: a closure body. * @param drop: an optional function to be called once on closure drop. @@ -1598,6 +1522,13 @@ ZENOHC_API const struct z_loaned_closure_reply_t *z_closure_reply_loan(const struct z_owned_closure_reply_t *closure); /** * @brief Constructs closure. + * + * Closures are not guaranteed not to be called concurrently. + * + * It is guaranteed that: + * - `call` will never be called once `drop` has started. + * - `drop` will only be called **once**, and **after every** `call` has ended. + * - The two previous guarantees imply that `call` and `drop` are never called concurrently. * @param this_: uninitialized memory location where new closure will be constructed. * @param call: a closure body. * @param drop: an optional function to be called once on closure drop. @@ -1625,6 +1556,13 @@ ZENOHC_API const struct z_loaned_closure_sample_t *z_closure_sample_loan(const struct z_owned_closure_sample_t *closure); /** * @brief Constructs closure. + * + * Closures are not guaranteed not to be called concurrently. + * + * It is guaranteed that: + * - `call` will never be called once `drop` has started. + * - `drop` will only be called **once**, and **after every** `call` has ended. + * - The two previous guarantees imply that `call` and `drop` are never called concurrently. * @param this_: uninitialized memory location where new closure will be constructed. * @param call: a closure body. * @param drop: an optional function to be called once on closure drop. @@ -4454,6 +4392,13 @@ void zc_cleanup_orphaned_shm_segments(void); #endif /** * @brief Constructs closure. + * + * Closures are not guaranteed not to be called concurrently. + * + * It is guaranteed that: + * - `call` will never be called once `drop` has started. + * - `drop` will only be called **once**, and **after every** `call` has ended. + * - The two previous guarantees imply that `call` and `drop` are never called concurrently. * @param this_: uninitialized memory location where new closure will be constructed. * @param call: a closure body. * @param drop: an optional function to be called once on closure drop. @@ -4484,6 +4429,13 @@ ZENOHC_API const struct zc_loaned_closure_log_t *zc_closure_log_loan(const struct zc_owned_closure_log_t *closure); /** * @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. + * + * Closures are not guaranteed not to be called concurrently. + * + * It is guaranteed that: + * - `call` will never be called once `drop` has started. + * - `drop` will only be called **once**, and **after every** `call` has ended. + * - The two previous guarantees imply that `call` and `drop` are never called concurrently. * @brief Constructs closure. * @param this_: uninitialized memory location where new closure will be constructed. * @param call: a closure body. diff --git a/include/zenoh_macros.h b/include/zenoh_macros.h index 8aa32d4d1..8c690e8dc 100644 --- a/include/zenoh_macros.h +++ b/include/zenoh_macros.h @@ -1024,39 +1024,39 @@ inline void z_call(const zc_loaned_closure_matching_status_t* closure, const zc_ }; extern "C" using z_closure_drop_callback_t = void(void* context); -extern "C" using z_closure_hello_callabck_t = void(z_loaned_hello_t *hello, void *context); -extern "C" using z_closure_query_callabck_t = void(z_loaned_query_t *query, void *context); -extern "C" using z_closure_reply_callabck_t = void(z_loaned_reply_t *reply, void *context); -extern "C" using z_closure_sample_callabck_t = void(z_loaned_sample_t *sample, void *context); -extern "C" using z_closure_zid_callabck_t = void(const z_id_t *z_id, void *context); -extern "C" using zc_closure_log_callabck_t = void(zc_log_severity_t severity, const z_loaned_string_t *msg, void *context); -extern "C" using zc_closure_matching_status_callabck_t = void(const zc_matching_status_t *matching_status, void *context); +extern "C" using z_closure_hello_callback_t = void(z_loaned_hello_t *hello, void *context); +extern "C" using z_closure_query_callback_t = void(z_loaned_query_t *query, void *context); +extern "C" using z_closure_reply_callback_t = void(z_loaned_reply_t *reply, void *context); +extern "C" using z_closure_sample_callback_t = void(z_loaned_sample_t *sample, void *context); +extern "C" using z_closure_zid_callback_t = void(const z_id_t *z_id, void *context); +extern "C" using zc_closure_log_callback_t = void(zc_log_severity_t severity, const z_loaned_string_t *msg, void *context); +extern "C" using zc_closure_matching_status_callback_t = void(const zc_matching_status_t *matching_status, void *context); -inline void z_closure(z_owned_closure_hello_t* this_, z_closure_hello_callabck_t* call, +inline void z_closure(z_owned_closure_hello_t* this_, z_closure_hello_callback_t* call, z_closure_drop_callback_t* drop, void* context) { z_closure_hello(this_, call, drop, context); }; -inline void z_closure(z_owned_closure_query_t* this_, z_closure_query_callabck_t* call, +inline void z_closure(z_owned_closure_query_t* this_, z_closure_query_callback_t* call, z_closure_drop_callback_t* drop, void* context) { z_closure_query(this_, call, drop, context); }; -inline void z_closure(z_owned_closure_reply_t* this_, z_closure_reply_callabck_t* call, +inline void z_closure(z_owned_closure_reply_t* this_, z_closure_reply_callback_t* call, z_closure_drop_callback_t* drop, void* context) { z_closure_reply(this_, call, drop, context); }; -inline void z_closure(z_owned_closure_sample_t* this_, z_closure_sample_callabck_t* call, +inline void z_closure(z_owned_closure_sample_t* this_, z_closure_sample_callback_t* call, z_closure_drop_callback_t* drop, void* context) { z_closure_sample(this_, call, drop, context); }; -inline void z_closure(z_owned_closure_zid_t* this_, z_closure_zid_callabck_t* call, +inline void z_closure(z_owned_closure_zid_t* this_, z_closure_zid_callback_t* call, z_closure_drop_callback_t* drop, void* context) { z_closure_zid(this_, call, drop, context); }; -inline void z_closure(zc_owned_closure_log_t* this_, zc_closure_log_callabck_t* call, +inline void z_closure(zc_owned_closure_log_t* this_, zc_closure_log_callback_t* call, z_closure_drop_callback_t* drop, void* context) { zc_closure_log(this_, call, drop, context); }; -inline void z_closure(zc_owned_closure_matching_status_t* this_, zc_closure_matching_status_callabck_t* call, +inline void z_closure(zc_owned_closure_matching_status_t* this_, zc_closure_matching_status_callback_t* call, z_closure_drop_callback_t* drop, void* context) { zc_closure_matching_status(this_, call, drop, context); }; diff --git a/src/closures/hello_closure.rs b/src/closures/hello_closure.rs index 016e81275..2d3fe31b3 100644 --- a/src/closures/hello_closure.rs +++ b/src/closures/hello_closure.rs @@ -20,23 +20,14 @@ use crate::{ transmute::{LoanedCTypeRef, OwnedCTypeRef, TakeRustType}, z_loaned_hello_t, }; -/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: -/// -/// Closures are not guaranteed not to be called concurrently. -/// -/// It is guaranteed that: +/// @brief A hello message-processing closure. /// -/// - `call` will never be called once `drop` has started. -/// - `drop` will only be called **once**, and **after every** `call` has ended. -/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. +/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. #[repr(C)] pub struct z_owned_closure_hello_t { - /// An optional pointer to a closure state. - context: *mut c_void, - /// A closure body. - call: Option, - /// An optional drop function that will be called when the closure is dropped. - drop: Option, + _context: *mut c_void, + _call: Option, + _drop: Option, } /// Loaned closure. @@ -60,23 +51,23 @@ decl_c_type!( impl Default for z_owned_closure_hello_t { fn default() -> Self { z_owned_closure_hello_t { - context: std::ptr::null_mut(), - call: None, - drop: None, + _context: std::ptr::null_mut(), + _call: None, + _drop: None, } } } impl z_owned_closure_hello_t { pub fn is_empty(&self) -> bool { - self.call.is_none() && self.drop.is_none() && self.context.is_null() + self._call.is_none() && self._drop.is_none() && self._context.is_null() } } unsafe impl Send for z_owned_closure_hello_t {} unsafe impl Sync for z_owned_closure_hello_t {} impl Drop for z_owned_closure_hello_t { fn drop(&mut self) { - if let Some(drop) = self.drop { - drop(self.context) + if let Some(drop) = self._drop { + drop(self._context) } } } @@ -95,8 +86,8 @@ pub extern "C" fn z_closure_hello_call( hello: &mut z_loaned_hello_t, ) { let closure = closure.as_owned_c_type_ref(); - match closure.call { - Some(call) => call(hello, closure.context), + match closure._call { + Some(call) => call(hello, closure._context), None => { tracing::error!("Attempted to call an uninitialized closure!"); } @@ -122,9 +113,9 @@ impl From for z_owned_closure_hello_t { std::mem::drop(unsafe { Box::from_raw(this as *mut F) }) } z_owned_closure_hello_t { - context: this, - call: Some(call::), - drop: Some(drop::), + _context: this, + _call: Some(call::), + _drop: Some(drop::), } } } @@ -144,6 +135,15 @@ pub extern "C" fn z_closure_hello_loan( } /// @brief Constructs closure. +/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: +/// +/// Closures are not guaranteed not to be called concurrently. +/// +/// It is guaranteed that: +/// +/// - `call` will never be called once `drop` has started. +/// - `drop` will only be called **once**, and **after every** `call` has ended. +/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. /// @param this_: uninitialized memory location where new closure will be constructed. /// @param call: a closure body. /// @param drop: an optional function to be called once on closure drop. @@ -156,8 +156,8 @@ pub extern "C" fn z_closure_hello( context: *mut c_void, ) { this.write(z_owned_closure_hello_t { - context, - call, - drop, + _context: context, + _call: call, + _drop: drop, }); } diff --git a/src/closures/log_closure.rs b/src/closures/log_closure.rs index 1d1b64b98..c8f58a6f7 100644 --- a/src/closures/log_closure.rs +++ b/src/closures/log_closure.rs @@ -70,29 +70,20 @@ impl From for zc_log_severity_t { } } } - -/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: -/// -/// Closures are not guaranteed not to be called concurrently. +/// @brief A log-processing closure. /// -/// It is guaranteed that: -/// - `call` will never be called once `drop` has started. -/// - `drop` will only be called **once**, and **after every** `call` has ended. -/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. +/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. #[repr(C)] pub struct zc_owned_closure_log_t { - /// An optional pointer to a closure state. - context: *mut libc::c_void, - /// A closure body. - call: Option< + _context: *mut libc::c_void, + _call: Option< extern "C" fn( severity: zc_log_severity_t, msg: &z_loaned_string_t, context: *mut libc::c_void, ), >, - /// An optional drop function that will be called when the closure is dropped. - drop: Option, + _drop: Option, } /// Loaned closure. @@ -116,9 +107,9 @@ decl_c_type!( impl Default for zc_owned_closure_log_t { fn default() -> Self { zc_owned_closure_log_t { - context: std::ptr::null_mut(), - call: None, - drop: None, + _context: std::ptr::null_mut(), + _call: None, + _drop: None, } } } @@ -126,22 +117,22 @@ impl Default for zc_owned_closure_log_t { impl zc_owned_closure_log_t { pub fn empty() -> Self { zc_owned_closure_log_t { - context: std::ptr::null_mut(), - call: None, - drop: None, + _context: std::ptr::null_mut(), + _call: None, + _drop: None, } } pub fn is_empty(&self) -> bool { - self.call.is_none() && self.drop.is_none() && self.context.is_null() + self._call.is_none() && self._drop.is_none() && self._context.is_null() } } unsafe impl Send for zc_owned_closure_log_t {} unsafe impl Sync for zc_owned_closure_log_t {} impl Drop for zc_owned_closure_log_t { fn drop(&mut self) { - if let Some(drop) = self.drop { - drop(self.context) + if let Some(drop) = self._drop { + drop(self._context) } } } @@ -161,8 +152,8 @@ pub extern "C" fn zc_closure_log_call( msg: &z_loaned_string_t, ) { let closure = closure.as_owned_c_type_ref(); - match closure.call { - Some(call) => call(severity, msg, closure.context), + match closure._call { + Some(call) => call(severity, msg, closure._context), None => { tracing::error!("Attempted to call an uninitialized closure!"); } @@ -189,6 +180,13 @@ pub extern "C" fn zc_closure_log_loan( } /// @brief Constructs closure. +/// +/// Closures are not guaranteed not to be called concurrently. +/// +/// It is guaranteed that: +/// - `call` will never be called once `drop` has started. +/// - `drop` will only be called **once**, and **after every** `call` has ended. +/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. /// @param this_: uninitialized memory location where new closure will be constructed. /// @param call: a closure body. /// @param drop: an optional function to be called once on closure drop. @@ -207,8 +205,8 @@ pub extern "C" fn zc_closure_log( context: *mut c_void, ) { this.write(zc_owned_closure_log_t { - context, - call, - drop, + _context: context, + _call: call, + _drop: drop, }); } diff --git a/src/closures/matching_status_closure.rs b/src/closures/matching_status_closure.rs index b88404c72..dcb359526 100644 --- a/src/closures/matching_status_closure.rs +++ b/src/closures/matching_status_closure.rs @@ -20,22 +20,14 @@ use crate::{ zc_matching_status_t, }; /// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. -/// @brief A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: +/// @brief A matching status-processing closure. /// -/// Closures are not guaranteed not to be called concurrently. -/// -/// It is guaranteed that: -/// - `call` will never be called once `drop` has started. -/// - `drop` will only be called **once**, and **after every** `call` has ended. -/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. +/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. #[repr(C)] pub struct zc_owned_closure_matching_status_t { - /// An optional pointer to a closure state. - context: *mut c_void, - /// A closure body. - call: Option, - /// An optional drop function that will be called when the closure is dropped. - drop: Option, + _context: *mut c_void, + _call: Option, + _drop: Option, } /// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. @@ -61,24 +53,24 @@ decl_c_type!( impl Default for zc_owned_closure_matching_status_t { fn default() -> Self { zc_owned_closure_matching_status_t { - context: std::ptr::null_mut(), - call: None, - drop: None, + _context: std::ptr::null_mut(), + _call: None, + _drop: None, } } } impl zc_owned_closure_matching_status_t { pub fn is_empty(&self) -> bool { - self.call.is_none() && self.drop.is_none() && self.context.is_null() + self._call.is_none() && self._drop.is_none() && self._context.is_null() } } unsafe impl Send for zc_owned_closure_matching_status_t {} unsafe impl Sync for zc_owned_closure_matching_status_t {} impl Drop for zc_owned_closure_matching_status_t { fn drop(&mut self) { - if let Some(drop) = self.drop { - drop(self.context) + if let Some(drop) = self._drop { + drop(self._context) } } } @@ -109,8 +101,8 @@ pub extern "C" fn zc_closure_matching_status_call( mathing_status: &zc_matching_status_t, ) { let closure = closure.as_owned_c_type_ref(); - match closure.call { - Some(call) => call(mathing_status, closure.context), + match closure._call { + Some(call) => call(mathing_status, closure._context), None => { tracing::error!("Attempted to call an uninitialized closure!"); } @@ -140,9 +132,9 @@ impl From for zc_owned_closure_matching_status_ std::mem::drop(unsafe { Box::from_raw(this as *mut F) }) } zc_owned_closure_matching_status_t { - context: this, - call: Some(call::), - drop: Some(drop::), + _context: this, + _call: Some(call::), + _drop: Some(drop::), } } } @@ -157,6 +149,13 @@ pub extern "C" fn zc_closure_matching_status_loan( } /// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. +/// +/// Closures are not guaranteed not to be called concurrently. +/// +/// It is guaranteed that: +/// - `call` will never be called once `drop` has started. +/// - `drop` will only be called **once**, and **after every** `call` has ended. +/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. /// @brief Constructs closure. /// @param this_: uninitialized memory location where new closure will be constructed. /// @param call: a closure body. @@ -170,8 +169,8 @@ pub extern "C" fn zc_closure_matching_status( context: *mut c_void, ) { this.write(zc_owned_closure_matching_status_t { - context, - call, - drop, + _context: context, + _call: call, + _drop: drop, }); } diff --git a/src/closures/query_channel.rs b/src/closures/query_channel.rs index c5c1263fc..abad54c1a 100644 --- a/src/closures/query_channel.rs +++ b/src/closures/query_channel.rs @@ -85,9 +85,9 @@ pub unsafe extern "C" fn z_fifo_channel_query_new( let cb_ptr = Box::into_raw(Box::new(cb)) as *mut libc::c_void; handler.as_rust_type_mut_uninit().write(Some(h)); callback.write(z_owned_closure_query_t { - call: Some(__z_handler_query_send), - context: cb_ptr, - drop: Some(__z_handler_query_drop), + _call: Some(__z_handler_query_send), + _context: cb_ptr, + _drop: Some(__z_handler_query_drop), }); } @@ -194,9 +194,9 @@ pub unsafe extern "C" fn z_ring_channel_query_new( let cb_ptr = Box::into_raw(Box::new(cb)) as *mut libc::c_void; handler.as_rust_type_mut_uninit().write(Some(h)); callback.write(z_owned_closure_query_t { - call: Some(__z_handler_query_send), - context: cb_ptr, - drop: Some(__z_handler_query_drop), + _call: Some(__z_handler_query_send), + _context: cb_ptr, + _drop: Some(__z_handler_query_drop), }); } diff --git a/src/closures/query_closure.rs b/src/closures/query_closure.rs index 35e355c35..f3d08b2aa 100644 --- a/src/closures/query_closure.rs +++ b/src/closures/query_closure.rs @@ -20,22 +20,14 @@ use crate::{ transmute::{LoanedCTypeRef, OwnedCTypeRef, TakeRustType}, z_loaned_query_t, }; -/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: +/// @brief A query-processing closure. /// -/// Closures are not guaranteed not to be called concurrently. -/// -/// It is guaranteed that: -/// - `call` will never be called once `drop` has started. -/// - `drop` will only be called **once**, and **after every** `call` has ended. -/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. +/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. #[repr(C)] pub struct z_owned_closure_query_t { - /// An optional pointer to a context representing a closure state. - pub context: *mut c_void, - /// A closure body. - pub call: Option, - /// An optional drop function that will be called when the closure is dropped. - pub drop: Option, + pub _context: *mut c_void, + pub _call: Option, + pub _drop: Option, } /// Loaned closure. @@ -59,24 +51,24 @@ decl_c_type!( impl Default for z_owned_closure_query_t { fn default() -> Self { z_owned_closure_query_t { - context: std::ptr::null_mut(), - call: None, - drop: None, + _context: std::ptr::null_mut(), + _call: None, + _drop: None, } } } impl z_owned_closure_query_t { pub fn is_empty(&self) -> bool { - self.call.is_none() && self.drop.is_none() && self.context.is_null() + self._call.is_none() && self._drop.is_none() && self._context.is_null() } } unsafe impl Send for z_owned_closure_query_t {} unsafe impl Sync for z_owned_closure_query_t {} impl Drop for z_owned_closure_query_t { fn drop(&mut self) { - if let Some(drop) = self.drop { - drop(self.context) + if let Some(drop) = self._drop { + drop(self._context) } } } @@ -102,8 +94,8 @@ pub extern "C" fn z_closure_query_call( query: &mut z_loaned_query_t, ) { let closure = closure.as_owned_c_type_ref(); - match closure.call { - Some(call) => call(query, closure.context), + match closure._call { + Some(call) => call(query, closure._context), None => tracing::error!("Attempted to call an uninitialized closure!"), } } @@ -127,9 +119,9 @@ impl From for z_owned_closure_query_t { std::mem::drop(unsafe { Box::from_raw(this as *mut F) }) } z_owned_closure_query_t { - context: this, - call: Some(call::), - drop: Some(drop::), + _context: this, + _call: Some(call::), + _drop: Some(drop::), } } } @@ -143,6 +135,13 @@ pub extern "C" fn z_closure_query_loan( } /// @brief Constructs closure. +/// +/// Closures are not guaranteed not to be called concurrently. +/// +/// It is guaranteed that: +/// - `call` will never be called once `drop` has started. +/// - `drop` will only be called **once**, and **after every** `call` has ended. +/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. /// @param this_: uninitialized memory location where new closure will be constructed. /// @param call: a closure body. /// @param drop: an optional function to be called once on closure drop. @@ -155,8 +154,8 @@ pub extern "C" fn z_closure_query( context: *mut c_void, ) { this.write(z_owned_closure_query_t { - context, - call, - drop, + _context: context, + _call: call, + _drop: drop, }); } diff --git a/src/closures/reply_closure.rs b/src/closures/reply_closure.rs index 1fd5908d6..31b64d79e 100644 --- a/src/closures/reply_closure.rs +++ b/src/closures/reply_closure.rs @@ -20,22 +20,15 @@ use crate::{ transmute::{LoanedCTypeRef, OwnedCTypeRef, TakeRustType}, z_loaned_reply_t, }; -/// A structure that contains all the elements for stateful, memory-leak-free callbacks. -/// -/// Closures are not guaranteed not to be called concurrently. + +/// @brief A reply-processing closure. /// -/// It is guaranteed that: -/// - `call` will never be called once `drop` has started. -/// - `drop` will only be called **once**, and **after every** `call` has ended. -/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. +/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. #[repr(C)] pub struct z_owned_closure_reply_t { - /// An optional pointer to a context representing a closure state. - pub context: *mut c_void, - /// A closure body. - pub(crate) call: Option, - /// An optional drop function that will be called when the closure is dropped. - pub drop: Option, + pub _context: *mut c_void, + pub(crate) _call: Option, + pub _drop: Option, } /// Loaned closure. @@ -60,24 +53,24 @@ decl_c_type!( impl Default for z_owned_closure_reply_t { fn default() -> Self { z_owned_closure_reply_t { - context: std::ptr::null_mut(), - call: None, - drop: None, + _context: std::ptr::null_mut(), + _call: None, + _drop: None, } } } impl z_owned_closure_reply_t { pub(crate) fn is_empty(&self) -> bool { - self.call.is_none() && self.drop.is_none() && self.context.is_null() + self._call.is_none() && self._drop.is_none() && self._context.is_null() } } unsafe impl Send for z_owned_closure_reply_t {} unsafe impl Sync for z_owned_closure_reply_t {} impl Drop for z_owned_closure_reply_t { fn drop(&mut self) { - if let Some(drop) = self.drop { - drop(self.context) + if let Some(drop) = self._drop { + drop(self._context) } } } @@ -103,8 +96,8 @@ pub extern "C" fn z_closure_reply_call( reply: &mut z_loaned_reply_t, ) { let closure = closure.as_owned_c_type_ref(); - match closure.call { - Some(call) => call(reply, closure.context), + match closure._call { + Some(call) => call(reply, closure._context), None => { tracing::error!("Attempted to call an uninitialized closure!"); } @@ -130,9 +123,9 @@ impl From for z_owned_closure_reply_t { std::mem::drop(unsafe { Box::from_raw(this as *mut F) }) } z_owned_closure_reply_t { - context: this, - call: Some(call::), - drop: Some(drop::), + _context: this, + _call: Some(call::), + _drop: Some(drop::), } } } @@ -146,6 +139,13 @@ pub extern "C" fn z_closure_reply_loan( } /// @brief Constructs closure. +/// +/// Closures are not guaranteed not to be called concurrently. +/// +/// It is guaranteed that: +/// - `call` will never be called once `drop` has started. +/// - `drop` will only be called **once**, and **after every** `call` has ended. +/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. /// @param this_: uninitialized memory location where new closure will be constructed. /// @param call: a closure body. /// @param drop: an optional function to be called once on closure drop. @@ -158,8 +158,8 @@ pub extern "C" fn z_closure_reply( context: *mut c_void, ) { this.write(z_owned_closure_reply_t { - context, - call, - drop, + _context: context, + _call: call, + _drop: drop, }); } diff --git a/src/closures/response_channel.rs b/src/closures/response_channel.rs index 9e7f26271..1b6dc98e2 100644 --- a/src/closures/response_channel.rs +++ b/src/closures/response_channel.rs @@ -85,9 +85,9 @@ pub unsafe extern "C" fn z_fifo_channel_reply_new( let cb_ptr = Box::into_raw(Box::new(cb)) as *mut libc::c_void; handler.as_rust_type_mut_uninit().write(Some(h)); callback.write(z_owned_closure_reply_t { - call: Some(__z_handler_reply_send), - context: cb_ptr, - drop: Some(__z_handler_reply_drop), + _call: Some(__z_handler_reply_send), + _context: cb_ptr, + _drop: Some(__z_handler_reply_drop), }); } @@ -190,9 +190,9 @@ pub unsafe extern "C" fn z_ring_channel_reply_new( let cb_ptr = Box::into_raw(Box::new(cb)) as *mut libc::c_void; handler.as_rust_type_mut_uninit().write(Some(h)); callback.write(z_owned_closure_reply_t { - call: Some(__z_handler_reply_send), - context: cb_ptr, - drop: Some(__z_handler_reply_drop), + _call: Some(__z_handler_reply_send), + _context: cb_ptr, + _drop: Some(__z_handler_reply_drop), }); } diff --git a/src/closures/sample_channel.rs b/src/closures/sample_channel.rs index 4b9266261..750ad2129 100644 --- a/src/closures/sample_channel.rs +++ b/src/closures/sample_channel.rs @@ -85,9 +85,9 @@ pub unsafe extern "C" fn z_fifo_channel_sample_new( let cb_ptr = Box::into_raw(Box::new(cb)) as *mut libc::c_void; handler.as_rust_type_mut_uninit().write(Some(h)); callback.write(z_owned_closure_sample_t { - call: Some(__z_handler_sample_send), - context: cb_ptr, - drop: Some(__z_handler_sample_drop), + _call: Some(__z_handler_sample_send), + _context: cb_ptr, + _drop: Some(__z_handler_sample_drop), }); } @@ -194,9 +194,9 @@ pub unsafe extern "C" fn z_ring_channel_sample_new( let cb_ptr = Box::into_raw(Box::new(cb)) as *mut libc::c_void; handler.as_rust_type_mut_uninit().write(Some(h)); callback.write(z_owned_closure_sample_t { - call: Some(__z_handler_sample_send), - context: cb_ptr, - drop: Some(__z_handler_sample_drop), + _call: Some(__z_handler_sample_send), + _context: cb_ptr, + _drop: Some(__z_handler_sample_drop), }); } diff --git a/src/closures/sample_closure.rs b/src/closures/sample_closure.rs index 4fed39c36..d568b3c45 100644 --- a/src/closures/sample_closure.rs +++ b/src/closures/sample_closure.rs @@ -20,22 +20,14 @@ use crate::{ transmute::{LoanedCTypeRef, OwnedCTypeRef, TakeRustType}, z_loaned_sample_t, }; -/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. -/// -/// Closures are not guaranteed not to be called concurrently. +/// @brief A sample-processing closure. /// -/// It is guaranteed that: -/// - `call` will never be called once `drop` has started. -/// - `drop` will only be called **once**, and **after every** `call` has ended. -/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. +/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. #[repr(C)] pub struct z_owned_closure_sample_t { - /// An optional pointer to a context representing a closure state. - pub context: *mut c_void, - /// A closure body. - pub(crate) call: Option, - /// An optional drop function that will be called when the closure is dropped. - pub drop: Option, + pub _context: *mut c_void, + pub(crate) _call: Option, + pub _drop: Option, } /// Loaned closure. @@ -59,24 +51,24 @@ decl_c_type!( impl Default for z_owned_closure_sample_t { fn default() -> Self { z_owned_closure_sample_t { - context: std::ptr::null_mut(), - call: None, - drop: None, + _context: std::ptr::null_mut(), + _call: None, + _drop: None, } } } impl z_owned_closure_sample_t { pub fn is_empty(&self) -> bool { - self.call.is_none() && self.drop.is_none() && self.context.is_null() + self._call.is_none() && self._drop.is_none() && self._context.is_null() } } unsafe impl Send for z_owned_closure_sample_t {} unsafe impl Sync for z_owned_closure_sample_t {} impl Drop for z_owned_closure_sample_t { fn drop(&mut self) { - if let Some(drop) = self.drop { - drop(self.context) + if let Some(drop) = self._drop { + drop(self._context) } } } @@ -103,8 +95,8 @@ pub extern "C" fn z_closure_sample_call( sample: &mut z_loaned_sample_t, ) { let closure = closure.as_owned_c_type_ref(); - match closure.call { - Some(call) => call(sample, closure.context), + match closure._call { + Some(call) => call(sample, closure._context), None => tracing::error!("Attempted to call an uninitialized closure!"), } } @@ -129,9 +121,9 @@ impl From for z_owned_closure_sample_t { std::mem::drop(unsafe { Box::from_raw(this as *mut F) }) } z_owned_closure_sample_t { - context: this, - call: Some(call::), - drop: Some(drop::), + _context: this, + _call: Some(call::), + _drop: Some(drop::), } } } @@ -145,6 +137,13 @@ pub extern "C" fn z_closure_sample_loan( } /// @brief Constructs closure. +/// +/// Closures are not guaranteed not to be called concurrently. +/// +/// It is guaranteed that: +/// - `call` will never be called once `drop` has started. +/// - `drop` will only be called **once**, and **after every** `call` has ended. +/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. /// @param this_: uninitialized memory location where new closure will be constructed. /// @param call: a closure body. /// @param drop: an optional function to be called once on closure drop. @@ -157,8 +156,8 @@ pub extern "C" fn z_closure_sample( context: *mut c_void, ) { this.write(z_owned_closure_sample_t { - context, - call, - drop, + _context: context, + _call: call, + _drop: drop, }); } diff --git a/src/closures/zenohid_closure.rs b/src/closures/zenohid_closure.rs index ee7565873..cb491a803 100644 --- a/src/closures/zenohid_closure.rs +++ b/src/closures/zenohid_closure.rs @@ -21,22 +21,14 @@ use crate::{ z_id_t, }; /// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. -/// @brief A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: +/// @brief A zenoh id-processing closure. /// -/// Closures are not guaranteed not to be called concurrently. -/// -/// It is guaranteed that: -/// - `call` will never be called once `drop` has started. -/// - `drop` will only be called **once**, and **after every** `call` has ended. -/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. +/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: #[repr(C)] pub struct z_owned_closure_zid_t { - /// An optional pointer to a closure state. - context: *mut c_void, - /// A callback function. - call: Option, - /// An optional function that will be called upon closure drop. - drop: Option, + _context: *mut c_void, + _call: Option, + _drop: Option, } /// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. @@ -62,24 +54,24 @@ decl_c_type!( impl Default for z_owned_closure_zid_t { fn default() -> Self { z_owned_closure_zid_t { - context: std::ptr::null_mut(), - call: None, - drop: None, + _context: std::ptr::null_mut(), + _call: None, + _drop: None, } } } impl z_owned_closure_zid_t { pub fn is_empty(&self) -> bool { - self.call.is_none() && self.drop.is_none() && self.context.is_null() + self._call.is_none() && self._drop.is_none() && self._context.is_null() } } unsafe impl Send for z_owned_closure_zid_t {} unsafe impl Sync for z_owned_closure_zid_t {} impl Drop for z_owned_closure_zid_t { fn drop(&mut self) { - if let Some(drop) = self.drop { - drop(self.context) + if let Some(drop) = self._drop { + drop(self._context) } } } @@ -107,8 +99,8 @@ pub unsafe extern "C" fn z_internal_closure_zid_null( #[no_mangle] pub extern "C" fn z_closure_zid_call(closure: &z_loaned_closure_zid_t, z_id: &z_id_t) { let closure = closure.as_owned_c_type_ref(); - match closure.call { - Some(call) => call(z_id, closure.context), + match closure._call { + Some(call) => call(z_id, closure._context), None => { tracing::error!("Attempted to call an uninitialized closure!"); } @@ -133,9 +125,9 @@ impl From for z_owned_closure_zid_t { std::mem::drop(unsafe { Box::from_raw(this as *mut F) }) } z_owned_closure_zid_t { - context: this, - call: Some(call::), - drop: Some(drop::), + _context: this, + _call: Some(call::), + _drop: Some(drop::), } } } @@ -148,6 +140,13 @@ pub extern "C" fn z_closure_zid_loan(closure: &z_owned_closure_zid_t) -> &z_loan } /// @brief Constructs closure. +/// +/// Closures are not guaranteed not to be called concurrently. +/// +/// It is guaranteed that: +/// - `call` will never be called once `drop` has started. +/// - `drop` will only be called **once**, and **after every** `call` has ended. +/// - The two previous guarantees imply that `call` and `drop` are never called concurrently. /// @param this_: uninitialized memory location where new closure will be constructed. /// @param call: a closure body. /// @param drop: an optional function to be called once on closure drop. @@ -160,8 +159,8 @@ pub extern "C" fn z_closure_zid( context: *mut c_void, ) { this.write(z_owned_closure_zid_t { - context, - call, - drop, + _context: context, + _call: call, + _drop: drop, }); }