liburlx-ffi — C ABI compatibility layer for liburlx.
This crate provides a libcurl-compatible C API, allowing liburlx to serve
as a drop-in replacement for libcurl at the binary level.
All unsafe code in the urlx project is confined to this crate.
Safety Invariants
The following safety contracts apply throughout this crate:
-
Handle pointers (
*mut c_voidfor easy/multi/share/url/mime handles): All callers must provide valid, non-null pointers obtained from the corresponding_initfunction. Every exported function null-checks its handle argument before dereferencing. Handles areBox-allocated and cast to*mut c_void;Box::from_rawreclaims ownership in_cleanup. -
C strings (
*const c_char): Callers must provide valid, null-terminated strings. The helperread_cstr()combines null-check +CStr::from_ptr+ UTF-8 validation. DirectCStr::from_ptrcalls appear whereread_cstris insufficient (e.g., when the pointer type differs or when non-UTF-8 data is acceptable). -
Output pointers in
curl_easy_getinfo: Callers must provide a valid pointer to the expected output type (*mut c_long,*mut f64,*mut *const c_char,*mut i64). Each match arm castsoutto the documented type and writes through it. The function null-checksoutbefore the match. -
Callback function pointers:
std::mem::transmuteconverts*const c_voidto the appropriate callback signature. Callers must ensure the pointer is actually a function with the documented C signature. Callbacks are invoked duringcurl_easy_performwith the corresponding*datapointer passed as the user-data argument. -
curl_slisttraversal: Linked-list nodes are caller-allocated. The list is walked via(*node).nextuntil null. Eachnode.datais a caller-owned C string.curl_slist_free_allreclaims all nodes. -
Panic safety: All exported
#[no_mangle]functions wrap their body instd::panic::catch_unwindto prevent Rust panics from unwinding across the FFI boundary.