nbdkit/0001-rust-Use-correct-type-...

125 lines
4.4 KiB
Diff

From 5b58b7f23c014878dcb499d1626c53a25960c7b0 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 10 Nov 2021 13:02:46 +0000
Subject: [PATCH] rust: Use correct type of C char on ARM and RISC-V platforms
On ARM and RISC-V platforms, C char is unsigned (compared to signed on
other platforms). This results in the error message attached when
compiling the rust plugin. This problem has probably existed for a
long time, but I only tried to compile the bindings on riscv64 and
aarch64 today.
The fix is to use c_char instead of i8. See:
https://stackoverflow.com/a/47684200
make: Entering directory '/home/rjones/d/nbdkit/plugins/rust'
cargo build --release
Compiling nbdkit v0.2.0 (/home/rjones/d/nbdkit/plugins/rust)
error[E0308]: mismatched types
--> src/lib.rs:985:19
|
985 | name: unsafe{ NAME.as_ptr() } as *const i8,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
|
= note: expected raw pointer `*const u8`
found raw pointer `*const i8`
error[E0308]: mismatched types
--> src/lib.rs:986:13
|
986 | longname,
| ^^^^^^^^ expected `u8`, found `i8`
|
= note: expected raw pointer `*const u8`
found raw pointer `*const i8`
error[E0308]: mismatched types
--> src/lib.rs:987:13
|
987 | version,
| ^^^^^^^ expected `u8`, found `i8`
|
= note: expected raw pointer `*const u8`
found raw pointer `*const i8`
error[E0308]: mismatched types
--> src/lib.rs:988:13
|
988 | description,
| ^^^^^^^^^^^ expected `u8`, found `i8`
|
= note: expected raw pointer `*const u8`
found raw pointer `*const i8`
error[E0308]: mismatched types
--> src/lib.rs:993:13
|
993 | config_help,
| ^^^^^^^^^^^ expected `u8`, found `i8`
|
= note: expected raw pointer `*const u8`
found raw pointer `*const i8`
error[E0308]: mismatched types
--> src/lib.rs:1015:13
|
1015 | magic_config_key,
| ^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
|
= note: expected raw pointer `*const u8`
found raw pointer `*const i8`
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0308`.
error: could not compile `nbdkit`
To learn more, run the command again with --verbose.
make: *** [Makefile:1063: target/release/libnbdkit.rlib] Error 101
make: Leaving directory '/home/rjones/d/nbdkit/plugins/rust'
(cherry picked from commit 413f3fa5a0c7c8d35fb273fb0ed62ad73ed7a4f5)
---
plugins/rust/src/lib.rs | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/plugins/rust/src/lib.rs b/plugins/rust/src/lib.rs
index 4f39b2ec..9fadfa98 100644
--- a/plugins/rust/src/lib.rs
+++ b/plugins/rust/src/lib.rs
@@ -965,25 +965,25 @@ impl Builder {
});
let config_help = S::config_help()
- .map(|_| unsafe {CONFIG_HELP.as_ptr()} as *const i8)
+ .map(|_| unsafe {CONFIG_HELP.as_ptr()} as *const c_char)
.unwrap_or(ptr::null());
let description = S::description()
- .map(|_| unsafe {DESCRIPTION.as_ptr()} as *const i8)
+ .map(|_| unsafe {DESCRIPTION.as_ptr()} as *const c_char)
.unwrap_or(ptr::null());
let longname = S::longname()
- .map(|_| unsafe {LONGNAME.as_ptr()} as *const i8)
+ .map(|_| unsafe {LONGNAME.as_ptr()} as *const c_char)
.unwrap_or(ptr::null());
let magic_config_key = S::magic_config_key()
- .map(|_| unsafe {MAGIC_CONFIG_KEY.as_ptr()} as *const i8)
+ .map(|_| unsafe {MAGIC_CONFIG_KEY.as_ptr()} as *const c_char)
.unwrap_or(ptr::null());
let version = S::version()
- .map(|_| unsafe {VERSION.as_ptr()} as *const i8)
+ .map(|_| unsafe {VERSION.as_ptr()} as *const c_char)
.unwrap_or(ptr::null());
let plugin = Plugin {
_struct_size: mem::size_of::<Plugin>() as u64,
_api_version: 2,
_thread_model: ThreadModel::Parallel as c_int,
- name: unsafe{ NAME.as_ptr() } as *const i8,
+ name: unsafe{ NAME.as_ptr() } as *const c_char,
longname,
version,
description,
--
2.31.1