Martin Kletzander
2019-Jun-11 11:25 UTC
[Libguestfs] [nbdkit PATCH 0/2] Few rust plugin fixups/nitpicks
There are few more things that could be cleaned up related to the coding style and other things, like explicitly specifying the abi style after "extern" (i.e. `extern "C" fn` instead of `extern fn`), but since those are configurable in rustfmt config, I'm not sure whether the config needs to be added or complying with the defaults should be the priority. But this was just something I stumbled upon when I saw some warnings during build, nothing more. Martin Kletzander (2): rust: Do not use deprecated integer types rust: Remove libc dependency plugins/rust/Cargo.toml.in | 1 - plugins/rust/examples/ramdisk.rs | 15 ++++++------- plugins/rust/src/lib.rs | 37 +++++++++++++++----------------- 3 files changed, 24 insertions(+), 29 deletions(-) -- 2.21.0
Martin Kletzander
2019-Jun-11 11:25 UTC
[Libguestfs] [nbdkit PATCH 1/2] rust: Do not use deprecated integer types
In order to avoid warning like: warning: use of deprecated item 'libc::uint64_t': Use u64 instead. --> src/lib.rs:42:19 | 42 | _struct_size: uint64_t, | ^^^^^^^^ | = note: #[warn(deprecated)] on by default and warning: use of deprecated item 'libc::fixed_width_ints::int64_t': Use i64 instead. --> examples/ramdisk.rs:68:49 | 68 | extern fn ramdisk_get_size (_h: *mut c_void) -> int64_t { | ^^^^^^^ | = note: #[warn(deprecated)] on by default Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- plugins/rust/examples/ramdisk.rs | 12 ++++++------ plugins/rust/src/lib.rs | 32 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/plugins/rust/examples/ramdisk.rs b/plugins/rust/examples/ramdisk.rs index 1994421b69a5..caf6fc8d8455 100644 --- a/plugins/rust/examples/ramdisk.rs +++ b/plugins/rust/examples/ramdisk.rs @@ -65,12 +65,12 @@ extern fn ramdisk_close (h: *mut c_void) { drop (h); } -extern fn ramdisk_get_size (_h: *mut c_void) -> int64_t { - return DISK.lock().unwrap().capacity() as int64_t; +extern fn ramdisk_get_size (_h: *mut c_void) -> i64 { + return DISK.lock().unwrap().capacity() as i64; } -extern fn ramdisk_pread (_h: *mut c_void, buf: *mut c_char, count: uint32_t, - offset: uint64_t, _flags: uint32_t) -> c_int { +extern fn ramdisk_pread (_h: *mut c_void, buf: *mut c_char, count: u32, + offset: u64, _flags: u32) -> c_int { let offset = offset as usize; let count = count as usize; let disk = DISK.lock().unwrap(); @@ -80,8 +80,8 @@ extern fn ramdisk_pread (_h: *mut c_void, buf: *mut c_char, count: uint32_t, return 0; } -extern fn ramdisk_pwrite (_h: *mut c_void, buf: *const c_char, count: uint32_t, - offset: uint64_t, _flags: uint32_t) -> c_int { +extern fn ramdisk_pwrite (_h: *mut c_void, buf: *const c_char, count: u32, + offset: u64, _flags: u32) -> c_int { let offset = offset as usize; let count = count as usize; let mut disk = DISK.lock().unwrap(); diff --git a/plugins/rust/src/lib.rs b/plugins/rust/src/lib.rs index 2a7121ba6748..ea68e8a701d2 100644 --- a/plugins/rust/src/lib.rs +++ b/plugins/rust/src/lib.rs @@ -39,7 +39,7 @@ use std::mem; // function must return. #[repr(C)] pub struct Plugin { - _struct_size: uint64_t, + _struct_size: u64, _api_version: c_int, _thread_model: c_int, @@ -58,7 +58,7 @@ pub struct Plugin { pub open: extern fn (c_int) -> *mut c_void, pub close: Option<extern fn (*mut c_void)>, - pub get_size: extern fn (*mut c_void) -> int64_t, + pub get_size: extern fn (*mut c_void) -> i64, pub can_write: Option<extern fn (*mut c_void) -> c_int>, pub can_flush: Option<extern fn (*mut c_void) -> c_int>, @@ -79,19 +79,19 @@ pub struct Plugin { pub can_zero: Option<extern fn (*mut c_void) -> c_int>, pub can_fua: Option<extern fn (*mut c_void) -> c_int>, - pub pread: extern fn (h: *mut c_void, buf: *mut c_char, count: uint32_t, - offset: uint64_t, - flags: uint32_t) -> c_int, + pub pread: extern fn (h: *mut c_void, buf: *mut c_char, count: u32, + offset: u64, + flags: u32) -> c_int, pub pwrite: Option<extern fn (h: *mut c_void, buf: *const c_char, - count: uint32_t, offset: uint64_t, - flags: uint32_t) -> c_int>, - pub flush: Option<extern fn (h: *mut c_void, flags: uint32_t) -> c_int>, + count: u32, offset: u64, + flags: u32) -> c_int>, + pub flush: Option<extern fn (h: *mut c_void, flags: u32) -> c_int>, pub trim: Option<extern fn (h: *mut c_void, - count: uint32_t, offset: uint64_t, - flags: uint32_t) -> c_int>, + count: u32, offset: u64, + flags: u32) -> c_int>, pub zero: Option<extern fn (h: *mut c_void, - count: uint32_t, offset: uint64_t, - flags: uint32_t) -> c_int>, + count: u32, offset: u64, + flags: u32) -> c_int>, pub magic_config_key: *const c_char, @@ -109,12 +109,12 @@ impl Plugin { pub fn new (thread_model: ThreadModel, name: *const c_char, open: extern fn (c_int) -> *mut c_void, - get_size: extern fn (*mut c_void) -> int64_t, + get_size: extern fn (*mut c_void) -> i64, pread: extern fn (h: *mut c_void, buf: *mut c_char, - count: uint32_t, offset: uint64_t, - flags: uint32_t) -> c_int) -> Plugin { + count: u32, offset: u64, + flags: u32) -> c_int) -> Plugin { Plugin { - _struct_size: mem::size_of::<Plugin>() as uint64_t, + _struct_size: mem::size_of::<Plugin>() as u64, _api_version: 2, _thread_model: thread_model as c_int, name: name, -- 2.21.0
Martin Kletzander
2019-Jun-11 11:25 UTC
[Libguestfs] [nbdkit PATCH 2/2] rust: Remove libc dependency
Now that we don't use C-style fixed-sized integers, there is no need for libc any more. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- plugins/rust/Cargo.toml.in | 1 - plugins/rust/examples/ramdisk.rs | 3 +-- plugins/rust/src/lib.rs | 5 +---- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/rust/Cargo.toml.in b/plugins/rust/Cargo.toml.in index f7a9f41e2402..bb20adabda18 100644 --- a/plugins/rust/Cargo.toml.in +++ b/plugins/rust/Cargo.toml.in @@ -5,7 +5,6 @@ authors = ["Richard W.M. Jones <rjones@redhat.com>"] edition = "2018" [dependencies] -libc = "0.2" # lazy_static is used by the example. lazy_static = "1.2.0" diff --git a/plugins/rust/examples/ramdisk.rs b/plugins/rust/examples/ramdisk.rs index caf6fc8d8455..9d0af0eeddef 100644 --- a/plugins/rust/examples/ramdisk.rs +++ b/plugins/rust/examples/ramdisk.rs @@ -34,9 +34,8 @@ extern crate nbdkit; #[macro_use] extern crate lazy_static; -use libc::*; use std::ptr; -use std::os::raw::c_int; +use std::os::raw::{c_char, c_int, c_void}; use std::sync::Mutex; use nbdkit::*; diff --git a/plugins/rust/src/lib.rs b/plugins/rust/src/lib.rs index ea68e8a701d2..a3dbf43e1ae1 100644 --- a/plugins/rust/src/lib.rs +++ b/plugins/rust/src/lib.rs @@ -29,11 +29,8 @@ // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF // SUCH DAMAGE. -extern crate libc; - -use libc::*; -use std::os::raw::c_int; use std::mem; +use std::os::raw::{c_char, c_int, c_void}; // This struct describes the plugin ABI which your plugin_init() // function must return. -- 2.21.0
Eric Blake
2019-Jun-11 15:52 UTC
Re: [Libguestfs] [nbdkit PATCH 0/2] Few rust plugin fixups/nitpicks
On 6/11/19 6:25 AM, Martin Kletzander wrote:> There are few more things that could be cleaned up related to the coding style > and other things, like explicitly specifying the abi style after "extern" > (i.e. `extern "C" fn` instead of `extern fn`), but since those are configurable > in rustfmt config, I'm not sure whether the config needs to be added or > complying with the defaults should be the priority. But this was just something > I stumbled upon when I saw some warnings during build, nothing more. > > Martin Kletzander (2): > rust: Do not use deprecated integer types > rust: Remove libc dependency > > plugins/rust/Cargo.toml.in | 1 - > plugins/rust/examples/ramdisk.rs | 15 ++++++------- > plugins/rust/src/lib.rs | 37 +++++++++++++++----------------- > 3 files changed, 24 insertions(+), 29 deletions(-)I'm no Rust expert, but it doesn't break the build and doesn't look bad to me. Pushed. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org