This is an automated email from the ASF dual-hosted git repository.

Jefffrey pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 794a844642 fix: take FFI_ArrowArrayStream errno values from libc 
(#10299)
794a844642 is described below

commit 794a844642ef37d64ce164d2da581734158ed233
Author: Fredrik Fornwall <[email protected]>
AuthorDate: Thu Jul 16 01:45:58 2026 +0200

    fix: take FFI_ArrowArrayStream errno values from libc (#10299)
    
    **Disclaimer**: The PR description and the code change was generated by
    claude code. I have reviewed it and think it makes sense, and is ready
    to dig into any eventual issues or make necessary modifications.
    
    The `errno` constants in `ffi_stream.rs` were hardcoded to a single set
    of values, but `ENOSYS` is `78` only on macOS/iOS and the BSDs — on
    Linux it is `38`, on Windows `40`, on Solaris/illumos `89`. On WASI even
    the other codes differ (`EINVAL` is `28`, `EIO` `29`, `ENOMEM` `48`),
    since WASI numbers its errnos independently. A stream exported on Linux
    therefore reported `ArrowError::NotYetImplemented` as `78`, which Linux
    errno tables read as an unrelated code, confusing C consumers that
    interpret the returned errno.
    
    Take the constants from libc instead, as an optional dependency of the
    ffi feature. It is target-gated off `wasm32-unknown-unknown` — the one
    target without a libc — where no OS interprets the codes anyway, so
    hardcoded Linux values remain.
    
    Signed-off-by: Fredrik Fornwall <[email protected]>
---
 Cargo.lock                    |  1 +
 arrow-array/Cargo.toml        |  7 ++++++-
 arrow-array/src/ffi_stream.rs | 13 ++++++++++++-
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 3873215342..d33ed9b78e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -222,6 +222,7 @@ dependencies = [
  "futures",
  "half",
  "hashbrown 0.17.1",
+ "libc",
  "num-complex",
  "num-integer",
  "num-traits",
diff --git a/arrow-array/Cargo.toml b/arrow-array/Cargo.toml
index df102c32b0..4ec358fe85 100644
--- a/arrow-array/Cargo.toml
+++ b/arrow-array/Cargo.toml
@@ -45,6 +45,11 @@ ahash = { version = "0.8", default-features = false, 
features = ["compile-time-r
 [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
 ahash = { version = "0.8", default-features = false, features = 
["runtime-rng"] }
 
+# Used by the ffi feature for platform-correct errno values. Excluded on
+# wasm32-unknown-unknown, which has no libc.
+[target.'cfg(not(all(target_family = "wasm", target_os = 
"unknown")))'.dependencies]
+libc = { version = "0.2", default-features = false, optional = true }
+
 [dependencies]
 arrow-buffer = { workspace = true }
 arrow-schema = { workspace = true }
@@ -63,7 +68,7 @@ all-features = true
 
 [features]
 async = ["dep:futures"]
-ffi = ["arrow-schema/ffi", "arrow-data/ffi"]
+ffi = ["arrow-schema/ffi", "arrow-data/ffi", "dep:libc"]
 force_validate = []
 # Enable memory tracking support
 pool = ["arrow-buffer/pool", "arrow-data/pool"]
diff --git a/arrow-array/src/ffi_stream.rs b/arrow-array/src/ffi_stream.rs
index 815d7c5760..9a09c3753d 100644
--- a/arrow-array/src/ffi_stream.rs
+++ b/arrow-array/src/ffi_stream.rs
@@ -74,10 +74,21 @@ use crate::record_batch::{RecordBatch, RecordBatchReader};
 
 type Result<T> = std::result::Result<T, ArrowError>;
 
+// Errno values returned through the C stream interface, taken from libc so 
they match
+// the platform the consumer interprets them against.
+#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
+use libc::{EINVAL, EIO, ENOMEM, ENOSYS};
+
+// wasm32-unknown-unknown has no libc, and no OS to interpret the codes either 
— any
+// non-zero value works there, so use Linux's.
+#[cfg(all(target_family = "wasm", target_os = "unknown"))]
 const ENOMEM: i32 = 12;
+#[cfg(all(target_family = "wasm", target_os = "unknown"))]
 const EIO: i32 = 5;
+#[cfg(all(target_family = "wasm", target_os = "unknown"))]
 const EINVAL: i32 = 22;
-const ENOSYS: i32 = 78;
+#[cfg(all(target_family = "wasm", target_os = "unknown"))]
+const ENOSYS: i32 = 38;
 
 /// ABI-compatible struct for `ArrayStream` from C Stream Interface
 /// See 
<https://arrow.apache.org/docs/format/CStreamInterface.html#structure-definitions>

Reply via email to