diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2024-12-12 20:41:01 +1100 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2025-02-01 14:14:40 +1100 |
| commit | c3f2930edc22407455b303612f46a684f23622b1 (patch) | |
| tree | 71e78392adf68d6a9b62075cd249b7832771fce4 /compiler/rustc_codegen_llvm/src | |
| parent | 5413d2bd6fd23103a8f44b306cdc6da1e109b6a2 (diff) | |
| download | rust-c3f2930edc22407455b303612f46a684f23622b1.tar.gz rust-c3f2930edc22407455b303612f46a684f23622b1.zip | |
Explain why (some) pointer/length strings are `*const c_uchar`
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 222e69df335..5c53a419a6c 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -1,3 +1,15 @@ +//! Bindings to the LLVM-C API (`LLVM*`), and to our own `extern "C"` wrapper +//! functions around the unstable LLVM C++ API (`LLVMRust*`). +//! +//! ## Passing pointer/length strings as `*const c_uchar` +//! +//! Normally it's a good idea for Rust-side bindings to match the corresponding +//! C-side function declarations as closely as possible. But when passing `&str` +//! or `&[u8]` data as a pointer/length pair, it's more convenient to declare +//! the Rust-side pointer as `*const c_uchar` instead of `*const c_char`. +//! Both pointer types have the same ABI, and using `*const c_uchar` avoids +//! the need for an extra cast from `*const u8` on the Rust side. + #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] |
