1111// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
1212//
1313
14- use std:: sync:: Arc ;
15-
1614use crate :: { errors:: ZResult , zerror} ;
1715use prebindgen_proc_macro:: prebindgen;
1816use zenoh:: key_expr:: { KeyExpr as ZKeyExpr , SetIntersectionLevel } ;
1917
2018/// Universal key-expression handle shared across the flat layer.
2119///
2220/// `ptr` is `None` for string-only expressions built via [`try_from`] /
23- /// [`autocanonize`]. `Some(md)` holds an `Arc<ZKeyExpr<'static>>` wrapped
24- /// in `ManuallyDrop` so it never auto-drops when the struct is destroyed:
25- /// the caller is responsible for releasing the Arc either by calling
26- /// `drop_key_expr` / `undeclare_key_expr` (session-declared) or simply
27- /// letting the undeclared variant be discarded (no-op).
21+ /// [`autocanonize`]. `Some(md)` holds a session-declared zenoh
22+ /// `ZKeyExpr<'static>`.
2823///
2924/// Field order (`ptr` first) matches the `KeyExpr(ptr: Long, string: String)`
3025/// Kotlin constructor so positional call sites need no update.
3126#[ prebindgen_proc_macro:: prebindgen]
3227#[ derive( Debug ) ]
3328pub struct KeyExpr {
34- pub ptr : Option < Arc < ZKeyExpr < ' static > > > ,
29+ pub ptr : Option < ZKeyExpr < ' static > > ,
3530 pub string : String ,
3631}
3732
3833impl KeyExpr {
3934 /// Materialize a borrowed zenoh `KeyExpr` for one-shot zenoh calls.
4035 ///
41- /// When `ptr != 0`, bumps the Arc strong count, clones the inner
42- /// `ZKeyExpr`, then drops the temporary Arc (net count unchanged).
36+ /// When `ptr != 0`, clones the stored `ZKeyExpr`.
4337 /// When `ptr == 0`, constructs from the already-validated string.
4438 pub ( crate ) fn as_zenoh ( & self ) -> ZKeyExpr < ' static > {
4539 if let Some ( md) = & self . ptr {
46- md. as_ref ( ) . clone ( )
40+ md. clone ( )
4741 } else {
4842 // SAFETY: every `KeyExpr` is built via the validating
4943 // constructors (`try_from`, `autocanonize`, join, concat).
@@ -105,7 +99,7 @@ pub fn join(a: &KeyExpr, other: String) -> ZResult<KeyExpr> {
10599 . map_err ( |err| zerror ! ( err) ) ?;
106100 let string = joined. to_string ( ) ;
107101 let ptr = if a. ptr . is_some ( ) {
108- Some ( Arc :: new ( ZKeyExpr :: from ( joined) ) )
102+ Some ( ZKeyExpr :: from ( joined) )
109103 } else {
110104 None
111105 } ;
@@ -123,22 +117,18 @@ pub fn concat(a: &KeyExpr, other: String) -> ZResult<KeyExpr> {
123117 . map_err ( |err| zerror ! ( err) ) ?;
124118 let string = concatenated. to_string ( ) ;
125119 let ptr = if a. ptr . is_some ( ) {
126- Some ( Arc :: new ( ZKeyExpr :: from ( concatenated) ) )
120+ Some ( ZKeyExpr :: from ( concatenated) )
127121 } else {
128122 None
129123 } ;
130124 Ok ( KeyExpr { ptr, string } )
131125}
132126
133127/// Drop a [`KeyExpr`] handle obtained from a session-declared key
134- /// expression. When `ptr != 0`, takes ownership of the `Arc<ZKeyExpr>`
135- /// (decrementing the strong count). String-only expressions are a no-op .
128+ /// expression. With value-owned storage, this is always a no-op because the
129+ /// wrapper drops naturally when consumed .
136130#[ prebindgen]
137131pub fn drop_key_expr ( key_expr : KeyExpr ) -> ZResult < ( ) > {
138- if let Some ( ptr) = key_expr. ptr {
139- // SAFETY: `ptr` was produced by `Arc::into_raw`; taking ownership
140- // here and letting the Arc drop releases the Java-side strong ref.
141- drop ( ptr) ;
142- }
132+ let _ = key_expr;
143133 Ok ( ( ) )
144134}
0 commit comments