Skip to content

Commit 9be5468

Browse files
committed
option added to some decl_c_type
1 parent 2755e80 commit 9be5468

File tree

4 files changed

+26
-40
lines changed

4 files changed

+26
-40
lines changed

include/zenoh_commons.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4007,7 +4007,7 @@ void zc_session_clone(const struct z_loaned_session_t *this_,
40074007
#if (defined(SHARED_MEMORY) && defined(UNSTABLE))
40084008
ZENOHC_API
40094009
z_error_t zc_shm_client_list_add_client(z_protocol_id_t id,
4010-
struct z_owned_shm_client_t *client,
4010+
struct z_moved_shm_client_t client,
40114011
struct zc_loaned_shm_client_list_t *list);
40124012
#endif
40134013
/**

src/closures/response_channel.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ pub use crate::opaque_types::z_loaned_fifo_handler_reply_t;
2727
pub use crate::opaque_types::z_moved_fifo_handler_reply_t;
2828
pub use crate::opaque_types::z_owned_fifo_handler_reply_t;
2929
decl_c_type!(
30-
owned(
31-
z_owned_fifo_handler_reply_t,
32-
Option<flume::Receiver<Reply>>,
33-
),
34-
loaned(z_loaned_fifo_handler_reply_t, flume::Receiver<Reply>),
35-
moved(z_moved_fifo_handler_reply_t)
30+
owned(z_owned_fifo_handler_reply_t, option flume::Receiver<Reply>),
31+
loaned(z_loaned_fifo_handler_reply_t),
32+
moved(z_moved_fifo_handler_reply_t)
3633
);
3734

3835
/// Drops the handler and resets it to a gravestone state.
@@ -145,12 +142,9 @@ pub use crate::opaque_types::z_loaned_ring_handler_reply_t;
145142
pub use crate::opaque_types::z_moved_ring_handler_reply_t;
146143
pub use crate::opaque_types::z_owned_ring_handler_reply_t;
147144
decl_c_type!(
148-
owned(
149-
z_owned_ring_handler_reply_t,
150-
Option<RingChannelHandler<Reply>>,
151-
),
152-
loaned(z_loaned_ring_handler_reply_t, RingChannelHandler<Reply>),
153-
moved(z_moved_ring_handler_reply_t)
145+
owned(z_owned_ring_handler_reply_t, option RingChannelHandler<Reply>),
146+
loaned(z_loaned_ring_handler_reply_t),
147+
moved(z_moved_ring_handler_reply_t)
154148
);
155149

156150
/// Drops the handler and resets it to a gravestone state.

src/shm/client_storage/mod.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@
1515
use super::common::types::z_protocol_id_t;
1616
use crate::{
1717
errors::{z_error_t, Z_EINVAL, Z_OK},
18-
transmute::{LoanedCTypeRef, RustTypeRef, RustTypeRefUninit},
19-
z_loaned_shm_client_storage_t, z_moved_shm_client_storage_t, z_owned_shm_client_storage_t,
20-
z_owned_shm_client_t, zc_loaned_shm_client_list_t, zc_moved_shm_client_list_t,
21-
zc_owned_shm_client_list_t,
18+
transmute::{IntoRustType, LoanedCTypeRef, RustTypeRef, RustTypeRefUninit},
19+
z_loaned_shm_client_storage_t, z_moved_shm_client_storage_t, z_moved_shm_client_t,
20+
z_owned_shm_client_storage_t, z_owned_shm_client_t, zc_loaned_shm_client_list_t,
21+
zc_moved_shm_client_list_t, zc_owned_shm_client_list_t,
2222
};
2323
use std::{mem::MaybeUninit, sync::Arc};
2424
use zenoh::shm::{ProtocolID, ShmClient, ShmClientStorage, GLOBAL_CLIENT_STORAGE};
2525

2626
decl_c_type!(
27-
owned(
28-
zc_owned_shm_client_list_t,
29-
Option<Vec<(ProtocolID, Arc<dyn ShmClient>)>>,
30-
),
31-
loaned(zc_loaned_shm_client_list_t, Vec<(ProtocolID, Arc<dyn ShmClient>)>),
32-
moved(zc_moved_shm_client_list_t)
27+
owned(zc_owned_shm_client_list_t, option Vec<(ProtocolID, Arc<dyn ShmClient>)>),
28+
loaned(zc_loaned_shm_client_list_t),
29+
moved(zc_moved_shm_client_list_t)
3330
);
3431

3532
/// Creates a new empty list of SHM Clients
@@ -86,25 +83,20 @@ pub unsafe extern "C" fn zc_shm_client_list_loan_mut(
8683
#[no_mangle]
8784
pub extern "C" fn zc_shm_client_list_add_client(
8885
id: z_protocol_id_t,
89-
client: &mut z_owned_shm_client_t,
86+
client: z_moved_shm_client_t,
9087
list: &mut zc_loaned_shm_client_list_t,
9188
) -> z_error_t {
92-
match client.as_rust_type_mut().take() {
93-
Some(client) => {
94-
list.as_rust_type_mut().push((id, client));
95-
Z_OK
96-
}
97-
None => Z_EINVAL,
98-
}
89+
let Some(client) = client.into_rust_type() else {
90+
return Z_EINVAL;
91+
};
92+
list.as_rust_type_mut().push((id, client));
93+
Z_OK
9994
}
10095

10196
decl_c_type!(
102-
owned(
103-
z_owned_shm_client_storage_t,
104-
Option<Arc<ShmClientStorage>>,
105-
),
106-
loaned(z_loaned_shm_client_storage_t, Arc<ShmClientStorage>),
107-
moved(z_moved_shm_client_storage_t)
97+
owned(z_owned_shm_client_storage_t, option Arc<ShmClientStorage> ),
98+
loaned(z_loaned_shm_client_storage_t),
99+
moved(z_moved_shm_client_storage_t)
108100
);
109101

110102
#[no_mangle]

src/shm/provider/shm_provider.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ pub enum CSHMProvider {
5151
}
5252

5353
decl_c_type!(
54-
owned(z_owned_shm_provider_t, Option<CSHMProvider>),
55-
loaned(z_loaned_shm_provider_t, CSHMProvider),
56-
moved(z_moved_shm_provider_t)
54+
owned(z_owned_shm_provider_t, option CSHMProvider),
55+
loaned(z_loaned_shm_provider_t),
56+
moved(z_moved_shm_provider_t)
5757
);
5858

5959
/// Creates a new SHM Provider

0 commit comments

Comments
 (0)