Skip to content

Commit

Permalink
[skip ci] Pass querying_subscriber as not owned
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Nov 23, 2023
1 parent 7c234f5 commit 49c61f0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
10 changes: 9 additions & 1 deletion include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,9 @@ typedef struct ze_querying_subscriber_options_t {
enum zcu_reply_keyexpr_t query_accept_replies;
uint64_t query_timeout_ms;
} ze_querying_subscriber_options_t;
typedef struct ze_querying_subscriber_t {
const struct ze_owned_querying_subscriber_t *_0;
} ze_querying_subscriber_t;
ZENOHC_API extern const unsigned int Z_ROUTER;
ZENOHC_API extern const unsigned int Z_PEER;
ZENOHC_API extern const unsigned int Z_CLIENT;
Expand Down Expand Up @@ -2092,9 +2095,14 @@ ZENOHC_API struct ze_publication_cache_options_t ze_publication_cache_options_de
*/
ZENOHC_API bool ze_querying_subscriber_check(const struct ze_owned_querying_subscriber_t *sub);
ZENOHC_API
int8_t ze_querying_subscriber_get(struct ze_owned_querying_subscriber_t *sub,
int8_t ze_querying_subscriber_get(struct ze_querying_subscriber_t sub,
struct z_keyexpr_t selector,
const struct z_get_options_t *options);
/**
* Returns a :c:type:`ze_querying_subscriber_loan` loaned from `p`.
*/
ZENOHC_API
struct ze_querying_subscriber_t ze_querying_subscriber_loan(const struct ze_owned_querying_subscriber_t *p);
/**
* Constructs a null safe-to-drop value of 'ze_owned_querying_subscriber_t' type
*/
Expand Down
20 changes: 11 additions & 9 deletions include/zenoh_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

// clang-format off
#define z_loan(x) \
_Generic((x), z_owned_session_t : z_session_loan, \
z_owned_keyexpr_t : z_keyexpr_loan, \
z_owned_config_t : z_config_loan, \
z_owned_publisher_t : z_publisher_loan, \
z_owned_subscriber_t : z_subscriber_loan, \
z_owned_pull_subscriber_t : z_pull_subscriber_loan, \
z_owned_encoding_t : z_encoding_loan, \
z_owned_hello_t : z_hello_loan, \
z_owned_str_t : z_str_loan \
_Generic((x), z_owned_session_t : z_session_loan, \
z_owned_keyexpr_t : z_keyexpr_loan, \
z_owned_config_t : z_config_loan, \
z_owned_publisher_t : z_publisher_loan, \
z_owned_subscriber_t : z_subscriber_loan, \
z_owned_pull_subscriber_t : z_pull_subscriber_loan, \
z_owned_encoding_t : z_encoding_loan, \
z_owned_hello_t : z_hello_loan, \
z_owned_str_t : z_str_loan, \
ze_owned_querying_subscriber_t : ze_querying_subscriber_loan \
)(&x)

#define z_drop(x) \
Expand Down Expand Up @@ -133,6 +134,7 @@ template<> inline z_pull_subscriber_t z_loan(const z_owned_pull_subscriber_t& x)
template<> inline z_encoding_t z_loan(const z_owned_encoding_t& x) { return z_encoding_loan(&x); }
template<> inline z_hello_t z_loan(const z_owned_hello_t& x) { return z_hello_loan(&x); }
template<> inline const char* z_loan(const z_owned_str_t& x) { return z_str_loan(&x); }
template<> inline ze_querying_subscriber_t z_loan(const ze_owned_querying_subscriber_t& x) { return ze_querying_subscriber_loan(&x); }

template<class T> struct zenoh_drop_type { typedef T type; };
template<class T> inline typename zenoh_drop_type<T>::type z_drop(T*);
Expand Down
12 changes: 10 additions & 2 deletions src/querying_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ pub unsafe extern "C" fn ze_declare_querying_subscriber(
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn ze_querying_subscriber_get(
sub: &mut ze_owned_querying_subscriber_t,
sub: ze_querying_subscriber_t,
selector: z_keyexpr_t,
options: Option<&z_get_options_t>,
) -> i8 {
unsafe impl Sync for z_get_options_t {}

if let Some(mut sub) = sub.as_mut().take() {
if let Some(sub) = sub.as_ref() {
match sub.session.upgrade() {
Some(s) => {
if let Err(e) = sub
Expand Down Expand Up @@ -289,3 +289,11 @@ pub extern "C" fn ze_undeclare_querying_subscriber(sub: &mut ze_owned_querying_s
pub extern "C" fn ze_querying_subscriber_check(sub: &ze_owned_querying_subscriber_t) -> bool {
sub.as_ref().is_some()
}

/// Returns a :c:type:`ze_querying_subscriber_loan` loaned from `p`.
#[no_mangle]
pub extern "C" fn ze_querying_subscriber_loan(
p: &ze_owned_querying_subscriber_t,
) -> ze_querying_subscriber_t {
ze_querying_subscriber_t(p)
}

0 comments on commit 49c61f0

Please sign in to comment.