diff --git a/examples/z_ping.c b/examples/z_ping.c index 72d983236..4879f41fc 100644 --- a/examples/z_ping.c +++ b/examples/z_ping.c @@ -21,7 +21,7 @@ z_owned_condvar_t cond; z_owned_mutex_t mutex; -void callback(const z_loaned_sample_t* sample, void* context) { z_condvar_signal(z_loan(cond)); } +void callback(z_loaned_sample_t* sample, void* context) { z_condvar_signal(z_loan(cond)); } void drop(void* context) { z_drop(z_move(cond)); } struct args_t { diff --git a/examples/z_ping_shm.c b/examples/z_ping_shm.c index 10482a6c2..b9d01c414 100644 --- a/examples/z_ping_shm.c +++ b/examples/z_ping_shm.c @@ -20,7 +20,7 @@ z_owned_condvar_t cond; z_owned_mutex_t mutex; -void callback(const z_loaned_sample_t* sample, void* context) { z_condvar_signal(z_loan(cond)); } +void callback(z_loaned_sample_t* sample, void* context) { z_condvar_signal(z_loan(cond)); } void drop(void* context) { z_drop(z_move(cond)); } struct args_t { diff --git a/examples/z_pong.c b/examples/z_pong.c index d7eda1bb9..98056dd8b 100644 --- a/examples/z_pong.c +++ b/examples/z_pong.c @@ -6,7 +6,7 @@ void parse_args(int argc, char** argv, z_owned_config_t* config); -void callback(const z_loaned_sample_t* sample, void* context) { +void callback(z_loaned_sample_t* sample, void* context) { const z_loaned_publisher_t* pub = z_loan(*(z_owned_publisher_t*)context); z_owned_bytes_t payload; z_bytes_clone(&payload, z_sample_payload(sample)); diff --git a/examples/z_query_sub.c b/examples/z_query_sub.c index 96ac2049f..eddde1b16 100644 --- a/examples/z_query_sub.c +++ b/examples/z_query_sub.c @@ -25,7 +25,7 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config); const char* kind_to_str(z_sample_kind_t kind); -void data_handler(const z_loaned_sample_t* sample, void* arg) { +void data_handler(z_loaned_sample_t* sample, void* arg) { z_view_string_t key_string; z_keyexpr_as_view_string(z_sample_keyexpr(sample), &key_string); z_owned_string_t payload_string; diff --git a/examples/z_queryable.c b/examples/z_queryable.c index 45e073069..91168a5f9 100644 --- a/examples/z_queryable.c +++ b/examples/z_queryable.c @@ -30,7 +30,7 @@ char *value; struct args_t parse_args(int argc, char **argv, z_owned_config_t *config); -void query_handler(const z_loaned_query_t *query, void *context) { +void query_handler(z_loaned_query_t *query, void *context) { z_view_string_t key_string; z_keyexpr_as_view_string(z_query_keyexpr(query), &key_string); diff --git a/examples/z_queryable_shm.c b/examples/z_queryable_shm.c index b70b9a843..0ec351b8c 100644 --- a/examples/z_queryable_shm.c +++ b/examples/z_queryable_shm.c @@ -20,7 +20,7 @@ const char *keyexpr = "demo/example/zenoh-c-queryable"; const char *value = "Queryable from C SHM!"; z_view_keyexpr_t ke; -void query_handler(const z_loaned_query_t *query, void *context) { +void query_handler(z_loaned_query_t *query, void *context) { z_loaned_shm_provider_t *provider = (z_loaned_shm_provider_t *)context; z_view_string_t key_string; diff --git a/examples/z_scout.c b/examples/z_scout.c index c0f3c02d1..dae7bbc47 100644 --- a/examples/z_scout.c +++ b/examples/z_scout.c @@ -72,7 +72,7 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, " }"); } -void callback(const z_loaned_hello_t *hello, void *context) { +void callback(z_loaned_hello_t *hello, void *context) { fprinthello(stdout, hello); fprintf(stdout, "\n"); (*(int *)context)++; diff --git a/examples/z_sub.c b/examples/z_sub.c index ebb4e6a6b..5faa675a6 100644 --- a/examples/z_sub.c +++ b/examples/z_sub.c @@ -25,7 +25,7 @@ struct args_t parse_args(int argc, char **argv, z_owned_config_t *config); const char *kind_to_str(z_sample_kind_t kind); -void data_handler(const z_loaned_sample_t *sample, void *arg) { +void data_handler(z_loaned_sample_t *sample, void *arg) { z_view_string_t key_string; z_keyexpr_as_view_string(z_sample_keyexpr(sample), &key_string); diff --git a/examples/z_sub_attachment.c b/examples/z_sub_attachment.c index 43a67b303..312870e1e 100644 --- a/examples/z_sub_attachment.c +++ b/examples/z_sub_attachment.c @@ -25,7 +25,7 @@ struct args_t { struct args_t parse_args(int argc, char** argv, z_owned_config_t* config); const char* kind_to_str(z_sample_kind_t kind); -void data_handler(const z_loaned_sample_t* sample, void* arg) { +void data_handler(z_loaned_sample_t* sample, void* arg) { z_view_string_t key_string; z_keyexpr_as_view_string(z_sample_keyexpr(sample), &key_string); diff --git a/examples/z_sub_liveliness.c b/examples/z_sub_liveliness.c index b67a2d8b9..73b01582d 100644 --- a/examples/z_sub_liveliness.c +++ b/examples/z_sub_liveliness.c @@ -23,7 +23,7 @@ struct args_t { }; struct args_t parse_args(int argc, char** argv, z_owned_config_t* config); -void data_handler(const z_loaned_sample_t* sample, void* arg) { +void data_handler(z_loaned_sample_t* sample, void* arg) { z_view_string_t key_string; z_keyexpr_as_view_string(z_sample_keyexpr(sample), &key_string); switch (z_sample_kind(sample)) { diff --git a/examples/z_sub_shm.c b/examples/z_sub_shm.c index f6a6fad7e..ce5f5b29a 100644 --- a/examples/z_sub_shm.c +++ b/examples/z_sub_shm.c @@ -17,7 +17,7 @@ const char *kind_to_str(z_sample_kind_t kind); -void data_handler(const z_loaned_sample_t *sample, void *arg) { +void data_handler(z_loaned_sample_t *sample, void *arg) { z_view_string_t key_string; z_keyexpr_as_view_string(z_sample_keyexpr(sample), &key_string); diff --git a/examples/z_sub_thr.c b/examples/z_sub_thr.c index 1a8d8e3f5..bb608dc1a 100644 --- a/examples/z_sub_thr.c +++ b/examples/z_sub_thr.c @@ -36,7 +36,7 @@ z_stats_t *z_stats_make() { return stats; } -void on_sample(const z_loaned_sample_t *sample, void *context) { +void on_sample(z_loaned_sample_t *sample, void *context) { z_stats_t *stats = (z_stats_t *)context; if (stats->count == 0) { stats->start = z_clock_now(); diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index c561672ce..22716f38a 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -461,7 +461,7 @@ typedef struct z_owned_closure_hello_t { /** * A closure body. */ - void (*call)(const struct z_loaned_hello_t *hello, void *context); + void (*call)(struct z_loaned_hello_t *hello, void *context); /** * An optional drop function that will be called when the closure is dropped. */ @@ -491,7 +491,7 @@ typedef struct z_owned_closure_query_t { /** * A closure body. */ - void (*call)(const struct z_loaned_query_t *reply, void *context); + void (*call)(struct z_loaned_query_t *reply, void *context); /** * An optional drop function that will be called when the closure is dropped. */ @@ -521,7 +521,7 @@ typedef struct z_owned_closure_reply_t { /** * A closure body. */ - void (*call)(const struct z_loaned_reply_t *reply, void *context); + void (*call)(struct z_loaned_reply_t *reply, void *context); /** * An optional drop function that will be called when the closure is dropped. */ @@ -551,7 +551,7 @@ typedef struct z_owned_closure_sample_t { /** * A closure body. */ - void (*call)(const struct z_loaned_sample_t *sample, void *context); + void (*call)(struct z_loaned_sample_t *sample, void *context); /** * An optional drop function that will be called when the closure is dropped. */ @@ -1864,7 +1864,7 @@ ZENOHC_API void z_close_options_default(struct z_close_options_t *this_); */ ZENOHC_API void z_closure_hello_call(const struct z_loaned_closure_hello_t *closure, - const struct z_loaned_hello_t *hello); + struct z_loaned_hello_t *hello); /** * Drops the closure. Droping an uninitialized closure is a no-op. */ @@ -1879,7 +1879,7 @@ const struct z_loaned_closure_hello_t *z_closure_hello_loan(const struct z_owned */ ZENOHC_API void z_closure_query_call(const struct z_loaned_closure_query_t *closure, - const struct z_loaned_query_t *query); + struct z_loaned_query_t *query); /** * Drops the closure, resetting it to its gravestone state. */ @@ -1894,7 +1894,7 @@ const struct z_loaned_closure_query_t *z_closure_query_loan(const struct z_owned */ ZENOHC_API void z_closure_reply_call(const struct z_loaned_closure_reply_t *closure, - const struct z_loaned_reply_t *reply); + struct z_loaned_reply_t *reply); /** * Drops the closure, resetting it to its gravestone state. Droping an uninitialized closure is a no-op. */ @@ -1910,7 +1910,7 @@ const struct z_loaned_closure_reply_t *z_closure_reply_loan(const struct z_owned */ ZENOHC_API void z_closure_sample_call(const struct z_loaned_closure_sample_t *closure, - const struct z_loaned_sample_t *sample); + struct z_loaned_sample_t *sample); /** * Drops the closure. Droping an uninitialized closure is a no-op. */ diff --git a/include/zenoh_macros.h b/include/zenoh_macros.h index 04b7a66ac..72fe253a2 100644 --- a/include/zenoh_macros.h +++ b/include/zenoh_macros.h @@ -660,22 +660,22 @@ inline bool z_internal_check(const z_owned_task_t& this_) { return z_internal_ta inline bool z_internal_check(const zc_owned_closure_log_t& this_) { return zc_internal_closure_log_check(&this_); }; -inline void z_call(const z_loaned_closure_hello_t* closure, const z_loaned_hello_t* hello) { +inline void z_call(const z_loaned_closure_hello_t* closure, z_loaned_hello_t* hello) { z_closure_hello_call(closure, hello); }; -inline void z_call(const z_loaned_closure_query_t* closure, const z_loaned_query_t* query) { +inline void z_call(const z_loaned_closure_query_t* closure, z_loaned_query_t* query) { z_closure_query_call(closure, query); }; -inline void z_call(const z_loaned_closure_reply_t* closure, const z_loaned_reply_t* reply) { +inline void z_call(const z_loaned_closure_reply_t* closure, z_loaned_reply_t* reply) { z_closure_reply_call(closure, reply); }; -inline void z_call(const z_loaned_closure_sample_t* closure, const z_loaned_sample_t* sample) { +inline void z_call(const z_loaned_closure_sample_t* closure, z_loaned_sample_t* sample) { z_closure_sample_call(closure, sample); }; extern "C" using z_closure_drop_callback_t = void(void*); -extern "C" using z_closure_hello_callback_t = void(const z_loaned_hello_t*, void*); +extern "C" using z_closure_hello_callback_t = void(z_loaned_hello_t*, void*); inline void z_closure( z_owned_closure_hello_t* closure, z_closure_hello_callback_t* call, @@ -685,7 +685,7 @@ inline void z_closure( closure->drop = drop; closure->call = call; }; -extern "C" using z_closure_query_callback_t = void(const z_loaned_query_t*, void*); +extern "C" using z_closure_query_callback_t = void(z_loaned_query_t*, void*); inline void z_closure( z_owned_closure_query_t* closure, z_closure_query_callback_t* call, @@ -695,7 +695,7 @@ inline void z_closure( closure->drop = drop; closure->call = call; }; -extern "C" using z_closure_reply_callback_t = void(const z_loaned_reply_t*, void*); +extern "C" using z_closure_reply_callback_t = void(z_loaned_reply_t*, void*); inline void z_closure( z_owned_closure_reply_t* closure, z_closure_reply_callback_t* call, @@ -705,7 +705,7 @@ inline void z_closure( closure->drop = drop; closure->call = call; }; -extern "C" using z_closure_sample_callback_t = void(const z_loaned_sample_t*, void*); +extern "C" using z_closure_sample_callback_t = void(z_loaned_sample_t*, void*); inline void z_closure( z_owned_closure_sample_t* closure, z_closure_sample_callback_t* call, diff --git a/src/closures/hello_closure.rs b/src/closures/hello_closure.rs index dcd4c19c8..6439e96d5 100644 --- a/src/closures/hello_closure.rs +++ b/src/closures/hello_closure.rs @@ -34,7 +34,7 @@ pub struct z_owned_closure_hello_t { /// An optional pointer to a closure state. context: *mut c_void, /// A closure body. - call: Option, + call: Option, /// An optional drop function that will be called when the closure is dropped. drop: Option, } @@ -92,7 +92,7 @@ pub unsafe extern "C" fn z_internal_closure_hello_null( #[no_mangle] pub extern "C" fn z_closure_hello_call( closure: &z_loaned_closure_hello_t, - hello: &z_loaned_hello_t, + hello: &mut z_loaned_hello_t, ) { let closure = closure.as_owned_c_type_ref(); match closure.call { @@ -108,15 +108,15 @@ pub extern "C" fn z_closure_hello_drop(this_: &mut z_moved_closure_hello_t) { let _ = this_.take_rust_type(); } -impl From for z_owned_closure_hello_t { +impl From for z_owned_closure_hello_t { fn from(f: F) -> Self { let this = Box::into_raw(Box::new(f)) as _; - extern "C" fn call( - response: *const z_loaned_hello_t, + extern "C" fn call( + response: &mut z_loaned_hello_t, this: *mut c_void, ) { let this = unsafe { &*(this as *const F) }; - unsafe { this(response.as_ref().unwrap()) } + this(response) } extern "C" fn drop(this: *mut c_void) { std::mem::drop(unsafe { Box::from_raw(this as *mut F) }) diff --git a/src/closures/query_channel.rs b/src/closures/query_channel.rs index cc1ff2547..678cf129f 100644 --- a/src/closures/query_channel.rs +++ b/src/closures/query_channel.rs @@ -55,7 +55,7 @@ pub extern "C" fn z_internal_fifo_handler_query_check( this_.as_rust_type_ref().is_some() } -extern "C" fn __z_handler_query_send(query: &z_loaned_query_t, context: *mut c_void) { +extern "C" fn __z_handler_query_send(query: &mut z_loaned_query_t, context: *mut c_void) { unsafe { let f = (context as *mut std::sync::Arc) .as_mut() diff --git a/src/closures/query_closure.rs b/src/closures/query_closure.rs index 8197774f3..73288cefb 100644 --- a/src/closures/query_closure.rs +++ b/src/closures/query_closure.rs @@ -33,7 +33,7 @@ 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, + pub call: Option, /// An optional drop function that will be called when the closure is dropped. pub drop: Option, } @@ -99,7 +99,7 @@ pub extern "C" fn z_internal_closure_query_check(this_: &z_owned_closure_query_t #[no_mangle] pub extern "C" fn z_closure_query_call( closure: &z_loaned_closure_query_t, - query: &z_loaned_query_t, + query: &mut z_loaned_query_t, ) { let closure = closure.as_owned_c_type_ref(); match closure.call { @@ -113,10 +113,13 @@ pub extern "C" fn z_closure_query_drop(closure_: &mut z_moved_closure_query_t) { let _ = closure_.take_rust_type(); } -impl From for z_owned_closure_query_t { +impl From for z_owned_closure_query_t { fn from(f: F) -> Self { let this = Box::into_raw(Box::new(f)) as _; - extern "C" fn call(query: &z_loaned_query_t, this: *mut c_void) { + extern "C" fn call( + query: &mut z_loaned_query_t, + this: *mut c_void, + ) { let this = unsafe { &*(this as *const F) }; this(query) } diff --git a/src/closures/reply_closure.rs b/src/closures/reply_closure.rs index a33692dd0..b40234322 100644 --- a/src/closures/reply_closure.rs +++ b/src/closures/reply_closure.rs @@ -33,7 +33,7 @@ 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, + pub(crate) call: Option, /// An optional drop function that will be called when the closure is dropped. pub drop: Option, } @@ -100,7 +100,7 @@ pub extern "C" fn z_internal_closure_reply_check(this_: &z_owned_closure_reply_t #[no_mangle] pub extern "C" fn z_closure_reply_call( closure: &z_loaned_closure_reply_t, - reply: &z_loaned_reply_t, + reply: &mut z_loaned_reply_t, ) { let closure = closure.as_owned_c_type_ref(); match closure.call { @@ -116,11 +116,11 @@ pub extern "C" fn z_closure_reply_drop(closure_: &mut z_moved_closure_reply_t) { let _ = closure_.take_rust_type(); } -impl From for z_owned_closure_reply_t { +impl From for z_owned_closure_reply_t { fn from(f: F) -> Self { let this = Box::into_raw(Box::new(f)) as _; - extern "C" fn call( - response: &z_loaned_reply_t, + extern "C" fn call( + response: &mut z_loaned_reply_t, this: *mut c_void, ) { let this = unsafe { &*(this as *const F) }; diff --git a/src/closures/response_channel.rs b/src/closures/response_channel.rs index fc7092b17..4e61acb94 100644 --- a/src/closures/response_channel.rs +++ b/src/closures/response_channel.rs @@ -55,7 +55,7 @@ pub extern "C" fn z_internal_fifo_handler_reply_check( this_.as_rust_type_ref().is_some() } -extern "C" fn __z_handler_reply_send(reply: &z_loaned_reply_t, context: *mut c_void) { +extern "C" fn __z_handler_reply_send(reply: &mut z_loaned_reply_t, context: *mut c_void) { unsafe { let f = (context as *mut std::sync::Arc) .as_mut() diff --git a/src/closures/sample_channel.rs b/src/closures/sample_channel.rs index 7daf956d6..8d57c47bb 100644 --- a/src/closures/sample_channel.rs +++ b/src/closures/sample_channel.rs @@ -55,7 +55,7 @@ pub extern "C" fn z_internal_fifo_handler_sample_check( this_.as_rust_type_ref().is_some() } -extern "C" fn __z_handler_sample_send(sample: &z_loaned_sample_t, context: *mut c_void) { +extern "C" fn __z_handler_sample_send(sample: &mut z_loaned_sample_t, context: *mut c_void) { unsafe { let f = (context as *mut std::sync::Arc) .as_mut() diff --git a/src/closures/sample_closure.rs b/src/closures/sample_closure.rs index d2574b764..3186af220 100644 --- a/src/closures/sample_closure.rs +++ b/src/closures/sample_closure.rs @@ -33,7 +33,7 @@ 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, + pub(crate) call: Option, /// An optional drop function that will be called when the closure is dropped. pub drop: Option, } @@ -100,7 +100,7 @@ pub extern "C" fn z_internal_closure_sample_check(this_: &z_owned_closure_sample #[no_mangle] pub extern "C" fn z_closure_sample_call( closure: &z_loaned_closure_sample_t, - sample: &z_loaned_sample_t, + sample: &mut z_loaned_sample_t, ) { let closure = closure.as_owned_c_type_ref(); match closure.call { @@ -115,11 +115,11 @@ pub extern "C" fn z_closure_sample_drop(closure_: &mut z_moved_closure_sample_t) let _ = closure_.take_rust_type(); } -impl From for z_owned_closure_sample_t { +impl From for z_owned_closure_sample_t { fn from(f: F) -> Self { let this = Box::into_raw(Box::new(f)) as _; - extern "C" fn call( - sample: &z_loaned_sample_t, + extern "C" fn call( + sample: &mut z_loaned_sample_t, this: *mut c_void, ) { let this = unsafe { &*(this as *const F) }; diff --git a/src/get.rs b/src/get.rs index da5fc9dc4..9687f942f 100644 --- a/src/get.rs +++ b/src/get.rs @@ -266,10 +266,10 @@ pub unsafe extern "C" fn z_get( } } match get - .callback(move |response| { + .callback(move |mut response| { z_closure_reply_call( z_closure_reply_loan(&callback), - response.as_loaned_c_type_ref(), + response.as_loaned_c_type_mut(), ) }) .wait() diff --git a/src/info.rs b/src/info.rs index 9c49f2081..a2437c324 100644 --- a/src/info.rs +++ b/src/info.rs @@ -66,8 +66,8 @@ pub unsafe extern "C" fn z_info_peers_zid( ) -> result::z_result_t { let session = session.as_rust_type_ref(); let callback = callback.take_rust_type(); - for id in session.info().peers_zid().wait() { - z_closure_zid_call(z_closure_zid_loan(&callback), id.as_ctype_ref()); + for mut id in session.info().peers_zid().wait() { + z_closure_zid_call(z_closure_zid_loan(&callback), id.as_ctype_mut()); } result::Z_OK } @@ -87,8 +87,8 @@ pub unsafe extern "C" fn z_info_routers_zid( ) -> result::z_result_t { let session = session.as_rust_type_ref(); let callback = callback.take_rust_type(); - for id in session.info().routers_zid().wait() { - z_closure_zid_call(z_closure_zid_loan(&callback), id.as_ctype_ref()); + for mut id in session.info().routers_zid().wait() { + z_closure_zid_call(z_closure_zid_loan(&callback), id.as_ctype_mut()); } result::Z_OK } diff --git a/src/liveliness.rs b/src/liveliness.rs index b5e843154..3e5f963f3 100644 --- a/src/liveliness.rs +++ b/src/liveliness.rs @@ -171,8 +171,8 @@ pub extern "C" fn zc_liveliness_declare_subscriber( .liveliness() .declare_subscriber(key_expr) .history(options.is_some_and(|o| o.history)) - .callback(move |sample| { - let sample = sample.as_loaned_c_type_ref(); + .callback(move |mut sample| { + let sample = sample.as_loaned_c_type_mut(); z_closure_sample_call(z_closure_sample_loan(&callback), sample) }) .wait() @@ -223,10 +223,10 @@ pub extern "C" fn zc_liveliness_get( let key_expr = key_expr.as_rust_type_ref(); let callback = callback.take_rust_type(); let liveliness = session.liveliness(); - let mut builder = liveliness.get(key_expr).callback(move |response| { + let mut builder = liveliness.get(key_expr).callback(move |mut response| { z_closure_reply_call( z_closure_reply_loan(&callback), - response.as_loaned_c_type_ref(), + response.as_loaned_c_type_mut(), ) }); if let Some(options) = options { diff --git a/src/queryable.rs b/src/queryable.rs index 0e97e5ede..f6c07030c 100644 --- a/src/queryable.rs +++ b/src/queryable.rs @@ -233,10 +233,10 @@ pub extern "C" fn z_declare_queryable( builder = builder.complete(options.complete); } let queryable = builder - .callback(move |query| { + .callback(move |mut query| { z_closure_query_call( z_closure_query_loan(&callback), - query.as_loaned_c_type_ref(), + query.as_loaned_c_type_mut(), ) }) .wait(); diff --git a/src/querying_subscriber.rs b/src/querying_subscriber.rs index 1db318924..d5ce04625 100644 --- a/src/querying_subscriber.rs +++ b/src/querying_subscriber.rs @@ -131,8 +131,8 @@ pub unsafe extern "C" fn ze_declare_querying_subscriber( sub = sub.query_timeout(std::time::Duration::from_millis(options.query_timeout_ms)); } } - let sub = sub.callback(move |sample| { - let sample = sample.as_loaned_c_type_ref(); + let sub = sub.callback(move |mut sample| { + let sample = sample.as_loaned_c_type_mut(); z_closure_sample_call(z_closure_sample_loan(&callback), sample); }); match sub.wait() { diff --git a/src/scouting.rs b/src/scouting.rs index e106a5ccc..a3389a053 100644 --- a/src/scouting.rs +++ b/src/scouting.rs @@ -184,8 +184,8 @@ pub extern "C" fn z_scout( task::block_on(async move { let scout = zenoh::scout(what, config) - .callback(move |h| { - z_closure_hello_call(z_closure_hello_loan(&callback), h.as_loaned_c_type_ref()) + .callback(move |mut h| { + z_closure_hello_call(z_closure_hello_loan(&callback), h.as_loaned_c_type_mut()) }) .await .unwrap(); diff --git a/src/subscriber.rs b/src/subscriber.rs index 9512e7731..df6e13a4e 100644 --- a/src/subscriber.rs +++ b/src/subscriber.rs @@ -83,8 +83,8 @@ pub extern "C" fn z_declare_subscriber( let callback = callback.take_rust_type(); let subscriber = session .declare_subscriber(key_expr) - .callback(move |sample| { - let sample = sample.as_loaned_c_type_ref(); + .callback(move |mut sample| { + let sample = sample.as_loaned_c_type_mut(); z_closure_sample_call(z_closure_sample_loan(&callback), sample) }); match subscriber.wait() { diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index a8ce64e89..58f243b9a 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -36,14 +36,14 @@ void zid_handler(const z_id_t *id, void *arg) { #endif volatile unsigned int hellos = 0; -void hello_handler(const z_loaned_hello_t *hello, void *arg) { +void hello_handler(z_loaned_hello_t *hello, void *arg) { (void)(arg); (void)(hello); hellos++; } volatile unsigned int queries = 0; -void query_handler(const z_loaned_query_t *query, void *arg) { +void query_handler(z_loaned_query_t *query, void *arg) { queries++; const z_loaned_keyexpr_t *query_ke = z_query_keyexpr(query); @@ -71,7 +71,7 @@ void query_handler(const z_loaned_query_t *query, void *arg) { } volatile unsigned int replies = 0; -void reply_handler(const z_loaned_reply_t *reply, void *arg) { +void reply_handler(z_loaned_reply_t *reply, void *arg) { replies++; if (z_reply_is_ok(reply)) { @@ -91,7 +91,7 @@ void reply_handler(const z_loaned_reply_t *reply, void *arg) { } volatile unsigned int datas = 0; -void data_handler(const z_loaned_sample_t *sample, void *arg) { +void data_handler(z_loaned_sample_t *sample, void *arg) { datas++; z_view_string_t k_str; diff --git a/tests/z_api_double_drop_test.c b/tests/z_api_double_drop_test.c index 2323ceca2..cf1da7f60 100644 --- a/tests/z_api_double_drop_test.c +++ b/tests/z_api_double_drop_test.c @@ -75,7 +75,7 @@ void test_config() { assert(!z_internal_check(config)); } -void data_handler(const z_loaned_sample_t *sample, void *arg) {} +void data_handler(z_loaned_sample_t *sample, void *arg) {} void test_subscriber() { z_owned_config_t config; @@ -97,7 +97,7 @@ void test_subscriber() { z_close(z_move(s), NULL); } -void query_handler(const z_loaned_query_t *query, void *context) {} +void query_handler(z_loaned_query_t *query, void *context) {} void test_queryable() { z_owned_config_t config; diff --git a/tests/z_api_drop_options.c b/tests/z_api_drop_options.c index c886f4cc9..369f683bd 100644 --- a/tests/z_api_drop_options.c +++ b/tests/z_api_drop_options.c @@ -18,7 +18,7 @@ #undef NDEBUG #include -void cb(const struct z_loaned_reply_t *reply, void *context) {} +void cb(struct z_loaned_reply_t *reply, void *context) {} void drop(void *context) {} void put() { diff --git a/tests/z_api_keyexpr_drop_test.c b/tests/z_api_keyexpr_drop_test.c index 0dbc05618..f10544c98 100644 --- a/tests/z_api_keyexpr_drop_test.c +++ b/tests/z_api_keyexpr_drop_test.c @@ -43,7 +43,7 @@ void test_publisher() { z_close(z_move(s), NULL); } -void data_handler(const z_loaned_sample_t *sample, void *arg) {} +void data_handler(z_loaned_sample_t *sample, void *arg) {} void test_subscriber() { z_owned_config_t config; diff --git a/tests/z_api_liveliness.c b/tests/z_api_liveliness.c index 7fe13dc6c..c7465132a 100644 --- a/tests/z_api_liveliness.c +++ b/tests/z_api_liveliness.c @@ -30,7 +30,7 @@ typedef struct context_t { const char* token1_expr = "zenoh/liveliness/test/1"; const char* token2_expr = "zenoh/liveliness/test/2"; -void on_receive(const z_loaned_sample_t* s, void* context) { +void on_receive(z_loaned_sample_t* s, void* context) { context_t* c = (context_t*)context; const z_loaned_keyexpr_t* k = z_sample_keyexpr(s); z_view_string_t ks; diff --git a/tests/z_int_pub_cache_query_sub_test.c b/tests/z_int_pub_cache_query_sub_test.c index ea2babd1f..695b939cd 100644 --- a/tests/z_int_pub_cache_query_sub_test.c +++ b/tests/z_int_pub_cache_query_sub_test.c @@ -91,7 +91,7 @@ int run_publisher() { return 0; } -void data_handler(const z_loaned_sample_t *sample, void *arg) { +void data_handler(z_loaned_sample_t *sample, void *arg) { static int val_num = 0; z_view_string_t keystr; z_keyexpr_as_view_string(z_sample_keyexpr(sample), &keystr); diff --git a/tests/z_int_pub_sub_attachment_test.c b/tests/z_int_pub_sub_attachment_test.c index 21d9fe9f3..fbaa5b1c1 100644 --- a/tests/z_int_pub_sub_attachment_test.c +++ b/tests/z_int_pub_sub_attachment_test.c @@ -131,7 +131,7 @@ int run_publisher() { return 0; } -void data_handler(const z_loaned_sample_t *sample, void *arg) { +void data_handler(z_loaned_sample_t *sample, void *arg) { static int val_num = 0; z_view_string_t keystr; z_keyexpr_as_view_string(z_sample_keyexpr(sample), &keystr); diff --git a/tests/z_int_pub_sub_test.c b/tests/z_int_pub_sub_test.c index d5bc39500..27f697c17 100644 --- a/tests/z_int_pub_sub_test.c +++ b/tests/z_int_pub_sub_test.c @@ -80,7 +80,7 @@ int run_publisher() { return 0; } -void data_handler(const z_loaned_sample_t *sample, void *arg) { +void data_handler(z_loaned_sample_t *sample, void *arg) { static int val_num = 0; z_view_string_t keystr; z_keyexpr_as_view_string(z_sample_keyexpr(sample), &keystr); diff --git a/tests/z_int_queryable_attachment_test.c b/tests/z_int_queryable_attachment_test.c index 375391d1b..8f04db4be 100644 --- a/tests/z_int_queryable_attachment_test.c +++ b/tests/z_int_queryable_attachment_test.c @@ -86,7 +86,7 @@ z_result_t check_attachment(const z_loaned_bytes_t *attachment, kv_it *it) { return 0; }; -void query_handler(const z_loaned_query_t *query, void *context) { +void query_handler(z_loaned_query_t *query, void *context) { static int value_num = 0; z_view_string_t params; diff --git a/tests/z_int_queryable_test.c b/tests/z_int_queryable_test.c index 27d9308cf..567f8824c 100644 --- a/tests/z_int_queryable_test.c +++ b/tests/z_int_queryable_test.c @@ -30,7 +30,7 @@ const uint64_t TEST_SN = 24; const uint64_t TEST_TS = 401706000; const uint8_t TEST_ID = 123; -void query_handler(const z_loaned_query_t *query, void *context) { +void query_handler(z_loaned_query_t *query, void *context) { static int value_num = 0; z_view_string_t params; diff --git a/tests/z_leak_pub_sub_test.c b/tests/z_leak_pub_sub_test.c index ae9bf54c4..22b32e505 100644 --- a/tests/z_leak_pub_sub_test.c +++ b/tests/z_leak_pub_sub_test.c @@ -24,7 +24,7 @@ const char *PUB_KEY_EXPR = "test/valgrind/data"; const char *SUB_KEY_EXPR = "test/valgrind/**"; -void data_handler(const z_loaned_sample_t *sample, void *context) { +void data_handler(z_loaned_sample_t *sample, void *context) { (void)context; z_view_string_t key_string; z_keyexpr_as_view_string(z_sample_keyexpr(sample), &key_string); diff --git a/tests/z_leak_queryable_get_test.c b/tests/z_leak_queryable_get_test.c index af1960f7a..343beaed8 100644 --- a/tests/z_leak_queryable_get_test.c +++ b/tests/z_leak_queryable_get_test.c @@ -24,7 +24,7 @@ const char *GET_KEY_EXPR = "test/valgrind/data"; const char *QUERYABLE_KEY_EXPR = "test/valgrind/**"; -void query_handler(const z_loaned_query_t *query, void *context) { +void query_handler(z_loaned_query_t *query, void *context) { (void)context; z_view_string_t key_string; z_keyexpr_as_view_string(z_query_keyexpr(query), &key_string);