Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
016e0ac
chore(quest): claim quest/m1/ffi-refusals/ip-addr.md
kixelated Nov 14, 2026
d6cca4a
feat(ffi): IpAddr, Ipv4Addr, and Ipv6Addr cross by family
kixelated Nov 14, 2026
3073b7d
docs(ffi): IpAddr's mapping in each binding, and its quest done
kixelated Nov 14, 2026
84edf9b
docs(ffi): numbers' doc comment sits on fn numbers again
kixelated Nov 15, 2026
a5402ed
chore(quest): claim quest/m1/ffi-export/lossless.md
kixelated Nov 15, 2026
18d28be
Merge remote-tracking branch 'origin/quest/m1/ffi-refusals/ip-addr' i…
kixelated Nov 15, 2026
3fb0394
feat(ffi)!: lossless core: a C struct per address family, Hash export…
kixelated Nov 15, 2026
49afd92
feat(ffi)!: Python's Duration crosses whole, and a Hash type hashes b…
kixelated Nov 15, 2026
54f63f2
test(ffi): the WTF-8 decoder under Miri, and rustfmt
kixelated Nov 15, 2026
6200769
feat(ffi)!: lossless Swift: RustDuration, std::net's address types, P…
kixelated Nov 15, 2026
0cbf8a7
Merge branch 'lossless-swift' into quest/m1/ffi-export/lossless
kixelated Nov 15, 2026
352aa73
feat(ffi)!: lossless Dart: U64, RustDuration, PathBuf, std::net addre…
kixelated Nov 15, 2026
cdd4526
Merge branch 'lossless-dart' into quest/m1/ffi-export/lossless
kixelated Nov 15, 2026
194e4a6
feat(ffi)!: lossless Go types: rt.Duration, rt.U128, std::net's addre…
kixelated Nov 15, 2026
3cc3067
Merge branch 'lossless-go' into quest/m1/ffi-export/lossless
kixelated Nov 15, 2026
dedc8ec
feat(ffi)!: a path that is no Windows path raises in Go and Python
kixelated Nov 15, 2026
b16f3c5
feat(ffi)!: a zero passed for a NonZero raises ValueError in Python
kixelated Nov 15, 2026
61bb3c5
feat(ffi)!: a zero passed for a NonZero throws in Dart and fails the …
kixelated Nov 15, 2026
11bcc60
chore(quest): lossless binding types is done
kixelated Nov 15, 2026
01db934
feat(ffi)!: lossless Kotlin types: runtime Duration, addresses, and P…
kixelated Nov 15, 2026
81f7171
Merge branch 'lossless-kotlin' into quest/m1/ffi-export/lossless
kixelated Nov 15, 2026
3011632
feat(ffi)!: a zero passed for a NonZero throws IllegalArgumentExcepti…
kixelated Nov 15, 2026
790a22e
feat(ffi)!: a zero passed for a NonZero throws CheckError in Swift
kixelated Nov 15, 2026
1fe1700
fix(ffi)!: a NonZero's option and list are their own C structs
kixelated Nov 15, 2026
fbe4f9d
Merge branch 'lossless-swift-nonzero' into quest/m1/ffi-export/lossless
kixelated Nov 15, 2026
da31d53
docs(ffi): a NonZero's zero raises in every binding but C and C++
kixelated Nov 15, 2026
31c389a
Merge remote-tracking branch 'origin/main' into quest/m1/ffi-export/l…
kixelated Nov 15, 2026
50e52ae
fix(ffi): Kotlin's SocketAddrV6 refuses a scope java.net cannot hold
kixelated Nov 15, 2026
a08590b
fix(ffi): answer the lossless review round
kixelated Nov 15, 2026
a0f29bd
Merge origin/main up to before #821's squash
kixelated Nov 15, 2026
de321fd
Merge #821's squash, whose content this branch already holds
kixelated Nov 15, 2026
ca906a6
Merge origin/main into quest/m1/ffi-export/lossless
kixelated Nov 15, 2026
0bda61f
Merge remote-tracking branch 'origin/main' into quest-iterate/lossles…
kixelated Nov 15, 2026
2f9c10d
fix(ffi): Dart's PathBuf.fromBytes refuses what is not a byte
kixelated Nov 15, 2026
e71954e
feat(ffi)!: Swift's NonZero is the runtime's NonZero<T>
kixelated Nov 15, 2026
4244c0c
test(ffi): the runtime-names check reads a generic Swift type's name
kixelated Nov 15, 2026
eb97f4e
fix(ffi): Dart reserves the core names its runtime uses unqualified
kixelated Nov 15, 2026
a07916c
style(ffi): rustfmt dart.rs
kixelated Nov 15, 2026
8f0f355
docs(ffi): a Go path that is no Windows path fails the call too
kixelated Nov 15, 2026
bda726e
Merge remote-tracking branch 'origin/main' into quest-iterate/lossles…
kixelated Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 130 additions & 65 deletions ffi/README.md

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions ffi/fixtures/api/examples/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,80 @@ fn main() {
ip_hex(other)
);

// Lossless round trips: each type's edge values, passed through Rust and back.
let durations: Vec<String> = [
std::time::Duration::ZERO,
std::time::Duration::from_nanos(1),
std::time::Duration::from_nanos(i64::MAX as u64 + 1),
std::time::Duration::MAX,
]
.into_iter()
.map(|d| {
let d = api::same_duration(d);
format!("{}.{:09}", d.as_secs(), d.subsec_nanos())
})
.collect();
println!("lossless duration {}", durations.join(" "));
println!(
"lossless u64 {} {} {}",
api::same_u64(0),
api::same_u64(1 << 63),
api::same_u64(u64::MAX)
);
println!("lossless usize {} {}", api::same_usize(0), api::same_usize(usize::MAX));
println!(
"lossless isize {} {}",
api::same_isize(isize::MIN),
api::same_isize(isize::MAX)
);
println!(
"lossless u128 {:032x} {:032x} {:032x}",
api::same_u128(0),
api::same_u128(1 << 64),
api::same_u128(u128::MAX)
);
let chars: Vec<String> = ['\0', '\u{d7ff}', '\u{e000}', char::MAX]
.into_iter()
.map(|c| format!("{:x}", u32::from(api::same_char(c))))
.collect();
println!("lossless char {}", chars.join(" "));
let paths: Vec<String> = [std::path::PathBuf::from("a/é"), unspelled()]
.into_iter()
.map(|p| hex(api::same_path(p).as_os_str().as_encoded_bytes()))
.collect();
println!("lossless path {}", paths.join(" "));
let v4 = api::same_socket_addr_v4(std::net::SocketAddrV4::new(std::net::Ipv4Addr::BROADCAST, u16::MAX));
let v6 = api::same_socket_addr_v6(std::net::SocketAddrV6::new(
std::net::Ipv6Addr::new(1, 0, 0, 0, 0, 0, 0, 2),
3,
u32::MAX,
u32::MAX,
));
let addrs: Vec<String> = [v4.into(), v6.into()]
.into_iter()
.map(|a| socket_hex(api::same_socket_addr(a)))
.collect();
println!(
"lossless socket {} {} {}",
socket_hex(v4.into()),
socket_hex(v6.into()),
addrs.join(" ")
);
// A key hashes by Rust's `Hash`: equal keys alike, and these two apart.
let (a, b) = (api::Key::new("a"), api::Key::new("b"));
println!(
"key {} {}",
a.hash_of() == api::Key::new("a").hash_of(),
a.hash_of() == b.hash_of()
);
println!(
"lossless ip {} {}",
ip_hex(api::same_ip_addr(std::net::Ipv4Addr::BROADCAST.into())),
ip_hex(api::same_ip_addr(
std::net::Ipv6Addr::new(0xffff, 0, 0, 0, 0, 0, 0, 1).into()
))
);

// Standard and common types: serde_json's map iterator, std's instant, and tracing's
// level and its filter.
let sections: Vec<String> = api::sections(
Expand Down Expand Up @@ -991,11 +1065,40 @@ fn main() {
);
}

/// A path no Rust string spells: on Unix, bytes that are not UTF-8; on Windows, a lone
/// surrogate, which is WTF-8's `ed a0 80`.
#[cfg(unix)]
fn unspelled() -> std::path::PathBuf {
api::stray()
}

/// A path no Rust string spells: on Unix, bytes that are not UTF-8; on Windows, a lone
/// surrogate, which is WTF-8's `ed a0 80`.
#[cfg(windows)]
fn unspelled() -> std::path::PathBuf {
<std::ffi::OsString as std::os::windows::ffi::OsStringExt>::from_wide(&[0xd800]).into()
}

/// Lowercase hex of `bytes`, two digits each.
fn hex(bytes: &[u8]) -> String {
bytes.iter().map(|b| format!("{b:02x}")).collect()
}

/// A socket address as its IP's bytes in hex, its port, flow label, and scope, each
/// IPv6's alone, apart by colons.
fn socket_hex(addr: std::net::SocketAddr) -> String {
match addr {
std::net::SocketAddr::V4(v4) => format!("{}:{}", hex(&v4.ip().octets()), v4.port()),
std::net::SocketAddr::V6(v6) => format!(
"{}:{}:{}:{}",
hex(&v6.ip().octets()),
v6.port(),
v6.flowinfo(),
v6.scope_id()
),
}
}

/// An address's bytes in hex, so the length shows its family.
fn ip_hex(ip: std::net::IpAddr) -> String {
match ip {
Expand Down
85 changes: 85 additions & 0 deletions ffi/fixtures/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4026,3 +4026,88 @@ impl Handle {
Handle { count }
}
}

// Lossless round trips: each returns what it is given, so a binding passes a type's edge
// values through Rust and back, and prints what it holds.

/// `v`, as given: the longest `Duration` included.
pub fn same_duration(v: Duration) -> Duration {
v
}

/// `v`, as given: past `i64::MAX` included.
pub fn same_u64(v: u64) -> u64 {
v
}

/// `v`, as given: past a 32-bit target's included.
pub fn same_usize(v: usize) -> usize {
v
}

/// `v`, as given.
pub fn same_isize(v: isize) -> isize {
v
}

/// `v`, as given.
pub fn same_u128(v: u128) -> u128 {
v
}

/// `v`, as given.
pub fn same_char(v: char) -> char {
v
}

/// `v`, as given.
pub fn same_string(v: String) -> String {
v
}

/// `v`, as given: one whose bytes are not UTF-8 included, as a Unix path may be.
pub fn same_path(v: std::path::PathBuf) -> std::path::PathBuf {
v
}

/// `v`, as given: a flow label and scope included.
pub fn same_socket_addr(v: std::net::SocketAddr) -> std::net::SocketAddr {
v
}

/// `v`, as given.
pub fn same_socket_addr_v4(v: std::net::SocketAddrV4) -> std::net::SocketAddrV4 {
v
}

/// `v`, as given: a flow label and scope included.
pub fn same_socket_addr_v6(v: std::net::SocketAddrV6) -> std::net::SocketAddrV6 {
v
}

/// `v`, as given.
pub fn same_ip_addr(v: std::net::IpAddr) -> std::net::IpAddr {
v
}

/// A key: an object whose `Hash` agrees with its `PartialEq`, so a binding hashes it by
/// Rust's, as a map keyed by it needs.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Key {
name: String,
}

impl Key {
pub fn new(name: &str) -> Key {
Key { name: name.to_string() }
}

/// Its hash by std's hasher, which a binding's own of it must equal, as both hash
/// through Rust's `Hash` alike.
pub fn hash_of(&self) -> u64 {
std::hash::BuildHasher::hash_one(
&std::hash::BuildHasherDefault::<std::hash::DefaultHasher>::default(),
self,
)
}
}
6 changes: 3 additions & 3 deletions ffi/moq/bench/export.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Future<Map<String, Span>> round() async {
final demand = demanded.demand();
start = begin();
for (var i = 0; i < n; i++) {
sink += demand.sequence();
sink += demand.sequence().bits;
}
out['getter'] = end(start, 'getter');
demand.close();
Expand All @@ -154,14 +154,14 @@ Future<Map<String, Span>> round() async {
for (var g = 0; g < groups; g++) {
final group = track.appendGroup();
for (var f = 0; f < frames; f++) {
group.writeFrame(moq.Timestamp.fromMicros(micros++), frame);
group.writeFrame(moq.Timestamp.fromMicros(moq.U64(micros++)), frame);
}
group.finish();
group.close();
}
out['stamped'] = end(start, 'stamped');

final at = moq.Timestamp.fromMicros(micros);
final at = moq.Timestamp.fromMicros(moq.U64(micros));
start = begin();
for (var g = 0; g < groups; g++) {
final group = track.appendGroup();
Expand Down
18 changes: 9 additions & 9 deletions ffi/moq/moq.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,9 @@ int main(void) {
moq_vec_string_free(alpns);
moq_Versions_free(versions);
/* A socket address, crossing in a listener's bind, set on its config and read back. */
moq_tokio_listen_Bind bind = {.tag = MOQ_TOKIO_LISTEN_BIND_ADDR, .addr = {._0 = {.ip = {[15] = 1}, .port = 4443, .v6 = true}}};
moq_tokio_listen_Bind bind = {.tag = MOQ_TOKIO_LISTEN_BIND_ADDR, .addr = {._0 = {.v6 = true, .addr.v6 = {.ip.octets = {[15] = 1}, .port = 4443}}}};
CHECK(is(moq_tokio_listen_Bind_to_string(&bind), "[::1]:4443"));
moq_tokio_listen_Bind v4 = {.tag = MOQ_TOKIO_LISTEN_BIND_ADDR, .addr = {._0 = {.ip = {127, 0, 0, 1}, .port = 0}}};
moq_tokio_listen_Bind v4 = {.tag = MOQ_TOKIO_LISTEN_BIND_ADDR, .addr = {._0 = {.addr.v4 = {.ip.octets = {127, 0, 0, 1}, .port = 0}}}};
CHECK(is(moq_tokio_listen_Bind_to_string(&v4), "127.0.0.1:0"));
CHECK(!moq_tokio_listen_Bind_eq(&bind, &v4));
moq_tokio_listen_Config *listen = moq_tokio_listen_Config_default();
Expand All @@ -567,10 +567,10 @@ int main(void) {
CHECK(bound.some && moq_tokio_listen_Bind_eq(&bound.value, &bind));
moq_tokio_listen_Bind_free(&bound.value);
/* The preferred address of each family, which takes only that family. */
moq_socket_addr preferred = {.ip = {10, 0, 0, 1}, .port = 4443};
moq_tokio_listen_Config_preferred_v4_set(listen, (moq_option_socket_addr){.some = true, .value = preferred}, NULL);
moq_option_socket_addr preferred_v4 = moq_tokio_listen_Config_preferred_v4_get(listen, NULL);
CHECK(preferred_v4.some && !preferred_v4.value.v6 && preferred_v4.value.ip[0] == 10 && preferred_v4.value.port == 4443);
moq_socket_addr_v4 preferred = {.ip.octets = {10, 0, 0, 1}, .port = 4443};
moq_tokio_listen_Config_preferred_v4_set(listen, (moq_option_socket_addr_v4){.some = true, .value = preferred}, NULL);
moq_option_socket_addr_v4 preferred_v4 = moq_tokio_listen_Config_preferred_v4_get(listen, NULL);
CHECK(preferred_v4.some && preferred_v4.value.ip.octets[0] == 10 && preferred_v4.value.port == 4443);
CHECK(!moq_tokio_listen_Config_preferred_v6_get(listen, NULL).some);
moq_tokio_listen_Config_free(listen);
/* A constant slice, as an array of clones. */
Expand Down Expand Up @@ -598,7 +598,7 @@ int main(void) {

moq_tokio_server_Config *server_config = moq_tokio_server_Config_default();
moq_tokio_listen_Config *listen_config = moq_tokio_server_Config_listen_get(server_config, NULL);
moq_tokio_listen_Bind any = {.tag = MOQ_TOKIO_LISTEN_BIND_ADDR, .addr = {._0 = {.port = 0, .v6 = true}}};
moq_tokio_listen_Bind any = {.tag = MOQ_TOKIO_LISTEN_BIND_ADDR, .addr = {._0 = {.v6 = true}}};
moq_tokio_listen_Config_bind_set(listen_config, (moq_option_tokio_listen_Bind){.some = true, .value = any}, NULL);
moq_tokio_tls_Listen *tls_listen = moq_tokio_tls_Listen_default();
moq_buf names[] = {str("localhost")};
Expand All @@ -612,14 +612,14 @@ int main(void) {
moq_tokio_server_Config_free(server_config);
moq_socket_addr local;
CHECK(moq_tokio_Server_local_addr(server, &local, &tokio_err, NULL));
CHECK(local.v6 && local.port != 0);
CHECK(local.v6 && local.addr.v6.port != 0);
moq_origin_Consumer *published = moq_origin_Producer_consume(served, NULL);
serving = moq_tokio_Server_serve_publish(server, published, NULL);
moq_tokio_Server_free(server);
moq_origin_Consumer_free(published);

char address[32];
snprintf(address, sizeof address, "moqt://localhost:%u", (unsigned)local.port);
snprintf(address, sizeof address, "moqt://localhost:%u", (unsigned)local.addr.v6.port);
moq_tokio_connect_Config *dialing = moq_tokio_connect_Config_default();
CHECK(moq_Url_parse(str(address), &url, &parse_err));
moq_tokio_connect_Config_url_set(dialing, url, NULL);
Expand Down
14 changes: 8 additions & 6 deletions ffi/moq/moq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,20 @@ int main() {
CHECK(is(connect.url_get()->to_string(), "https://relay.example:4443/demo"));

// A listener's bind, a socket address.
moq::socket_addr_v6 addr_v6{};
addr_v6.ip.octets[15] = 1;
addr_v6.port = 4443;
moq::socket_addr addr{};
addr.ip[15] = 1;
addr.port = 4443;
addr.v6 = true;
addr.addr.v6 = addr_v6;
moq::tokio_listen_Config listen = moq::tokio_listen_Config::default_();
listen.bind_set(moq::tokio_listen_Bind(moq::tokio_listen_Bind_Addr{addr}));
auto bind = listen.bind_get();
CHECK(bind && is(moq::tokio_listen_Bind_to_string(*bind), "[::1]:4443"));
// The preferred address of each family, which takes only that family.
listen.preferred_v6_set(addr);
listen.preferred_v6_set(addr_v6);
auto preferred = listen.preferred_v6_get();
CHECK(preferred && preferred->v6 && preferred->port == 4443 && !listen.preferred_v4_get());
CHECK(preferred && preferred->port == 4443 && !listen.preferred_v4_get());
// A constant slice, as a vector of clones.
CHECK(!moq::ALPNS().empty());
}
Expand Down Expand Up @@ -404,14 +406,14 @@ int main() {
auto server = std::move(server_config).init();
CHECK(server);
auto local = server->local_addr();
CHECK(local && local->v6 && local->port != 0);
CHECK(local && local->v6 && local->addr.v6.port != 0);
worker serving_thread;
std::atomic<bool> stopped{false};
moq::task serving = std::move(*server).serve_publish(served.consume()).then(serving_thread.executor(),
[&](auto &&) { stopped = true; });

moq::tokio_connect_Config connect = moq::tokio_connect_Config::default_();
connect.url_set(moq::Url::parse("moqt://localhost:" + std::to_string(local->port)).value());
connect.url_set(moq::Url::parse("moqt://localhost:" + std::to_string(local->addr.v6.port)).value());
moq::tokio_tls_Connect insecure = connect.tls_get();
insecure.insecure_set(true);
connect.tls_set(std::move(insecure));
Expand Down
Loading