Skip to content

Commit 8576c2b

Browse files
committed
zerror declared
1 parent 86ce22c commit 8576c2b

2 files changed

Lines changed: 41 additions & 30 deletions

File tree

zenoh-flat-jni/build.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,23 @@ fn main() {
2222
.source_module(pq!(zenoh_flat)) // how to prefix prebindgen-marked items (functions, types
2323
.package_prefix("io.zenoh.jni") // the package of the generated JNI bindings
2424
// Error model: zenoh's native `ZError` is the `E` of every fallible
25-
// `Result<_, ZError>`. It never crosses as a value — a CONVERTER
26-
// (`z_error_message -> String`) marked `.default()` auto-applies a
27-
// `convert_error` to EVERY declared fn returning `Result<_, ZError>`, so
28-
// the generated wrapper's `onError` callback receives the error string as
29-
// its single `ze` param (after the fixed binding `je: String?`). No throw
30-
// from zenoh-flat-jni; the caller's `onError` decides (zenoh-java throws
31-
// `ZError`).
25+
// `Result<_, ZError>`. A CONVERTER (`z_error_message -> String`) marked
26+
// `.default()` auto-applies a `convert_error` to EVERY declared fn
27+
// returning `Result<_, ZError>`, so the generated wrapper's `onError`
28+
// callback receives the error string as its single `ze` param (after the
29+
// fixed binding `je: String?`). No throw from zenoh-flat-jni; the caller's
30+
// `onError` decides (zenoh-java throws `ZError`).
31+
//
32+
// `ptr_class(ZError)` makes `ZError` a regular opaque-handle type so the
33+
// rank-2 `Result<T, ZError>` resolver finds its input/output converters
34+
// (jlong handle). The handle never actually crosses — the extern peels the
35+
// `Result` and delivers the error via `convert_error` — so the generated
36+
// `ZError` handle class + destructor are dead code, but this is the
37+
// idiomatic "ZError is FFI-representable" declaration (vs hand-written
38+
// dummy converters).
39+
.ptr_class(pq!(ZError))
3240
.converter(pq!(ZError), pq!(z_error_message))
3341
.default()
34-
// `ZError` has no value-crossing of its own — but the rank-2
35-
// `Result<T, ZError>` resolver still requires an output converter for the
36-
// `E` position. Register the same `→ String` lowering so `Result` types
37-
// resolve; for fallible fns the error plan peels the `Result` in the
38-
// extern, so this converter is resolved-but-unused (the error reaches the
39-
// callback via `convert_error`). Harmless and semantically correct.
40-
.output_wrapper(pq!(ZError), |_: &Registry<_>| {
41-
Some((pq!(String), None, pq!(zenoh_flat::z_error_message(&v))))
42-
})
43-
// Symmetric input side: required by the resolver's propagation through
44-
// the fallible constructors' `Result<_, ZError>` signatures, but **never
45-
// actually crossed** (no fn takes `ZError` from the JVM). A terminal that
46-
// ignores the wire and yields a dummy `ZError` satisfies resolution; it is
47-
// dead code (no extern param has `ZError` input).
48-
.input_wrapper(pq!(ZError), |_: &Registry<_>| {
49-
Some((
50-
pq!(ZError),
51-
None,
52-
pq!(<zenoh_flat::ZError as ::core::convert::From<::std::string::String>>::from(
53-
::std::string::String::new()
54-
)),
55-
))
56-
})
5742
.package("keyexpr")
5843
.ptr_class(pq!(ZKeyExpr))
5944
.package_fun(pq!(z_keyexpr_try_from))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Auto-generated by JniGen — do not edit by hand.
2+
package io.zenoh.jni
3+
4+
/** Typed handle for a native Zenoh `ZError`. */
5+
public class ZError(initialPtr: Long) : NativeHandle(initialPtr) {
6+
@Synchronized
7+
override fun close() {
8+
val p = ptr
9+
if (p != 0L) {
10+
ptr = 0L
11+
freePtr(p)
12+
}
13+
}
14+
15+
@Synchronized
16+
public fun take(): ZError {
17+
val p = ptr
18+
ptr = 0L
19+
return ZError(p)
20+
}
21+
22+
public companion object {
23+
@JvmStatic
24+
external fun freePtr(ptr: Long)
25+
}
26+
}

0 commit comments

Comments
 (0)