rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.75k stars 258 forks source link

Snappy ffi example uses u8 instead of c_char #345

Open aboseley opened 2 years ago

aboseley commented 2 years ago

The ffi interface in the snappy examples doesn't match the c-library types in snappy-c.h.

Should the ffi interface use libc::c_char instead of u8

https://github.com/google/snappy/blob/main/snappy-c.h#L71

   snappy_status snappy_compress(const char* input,
                              size_t input_length,
                              char* compressed,
                              size_t* compressed_length);

example here https://doc.rust-lang.org/nomicon/ffi.html#calling-foreign-functions

   fn snappy_compress(input: *const u8,
                       input_length: size_t,
                       compressed: *mut u8,
                       compressed_length: *mut size_t) -> c_int;

Would it be clearer to have these function definition match then cast the pointer inside the rust function.