Skip to content
/ rust Public
forked from rust-lang/rust

Commit c3f2930

Browse files
committed
Explain why (some) pointer/length strings are *const c_uchar
1 parent 5413d2b commit c3f2930

File tree

1 file changed

+12
-0
lines changed
  • compiler/rustc_codegen_llvm/src/llvm

1 file changed

+12
-0
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
//! Bindings to the LLVM-C API (`LLVM*`), and to our own `extern "C"` wrapper
2+
//! functions around the unstable LLVM C++ API (`LLVMRust*`).
3+
//!
4+
//! ## Passing pointer/length strings as `*const c_uchar`
5+
//!
6+
//! Normally it's a good idea for Rust-side bindings to match the corresponding
7+
//! C-side function declarations as closely as possible. But when passing `&str`
8+
//! or `&[u8]` data as a pointer/length pair, it's more convenient to declare
9+
//! the Rust-side pointer as `*const c_uchar` instead of `*const c_char`.
10+
//! Both pointer types have the same ABI, and using `*const c_uchar` avoids
11+
//! the need for an extra cast from `*const u8` on the Rust side.
12+
113
#![allow(non_camel_case_types)]
214
#![allow(non_upper_case_globals)]
315

0 commit comments

Comments
 (0)