From nobody Tue Nov 26 13:46:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1573595109; cv=none; d=zoho.com; s=zohoarc; b=XxbPYzwBfVtn2uuCh37bf6Q6DhuyRsO6INe/xg3FPNTvpxJ5cPiT90nU30abCqGU7Sj42JAp3eDhJBl+cKxKrmrmH0lEs9UjkM3QDPZJ4xhvgrKuCc81Jdrc6o98lwQmMGZlaQJNiOIZ1HQneMfLfcT5TvN3s/6/fhtvZqvLScw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573595109; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=P+iqLk98KU7/v7wnXvYiTXJ+DNGnApsyRXik2/j+KN4=; b=G3pR7aaEvUs5Ze8bzH8xDkr42Lzm4nHd0iKEr6IrM7eZfZJY8XZHF8/mEm9JuUTMmtWq7K4hGGnbY1ZDzdFQ2wGxX5XukwPV+GkgMU3o6yRdN02h4UOiMDLI/XsCSVabmJGyNztXS3VHwXuZKEWWasAb2JR1MUiarPUs3C3g0tM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1573595109780509.1930283802866; Tue, 12 Nov 2019 13:45:09 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-370-tXdlkrYNMJC-rN-UzrbEeQ-1; Tue, 12 Nov 2019 16:45:06 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F54D107ACFA; Tue, 12 Nov 2019 21:45:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50ADD60174; Tue, 12 Nov 2019 21:45:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 55D121803C37; Tue, 12 Nov 2019 21:45:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xACLiumU027050 for ; Tue, 12 Nov 2019 16:44:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4E9171C5B9; Tue, 12 Nov 2019 21:44:56 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A2FE17896 for ; Tue, 12 Nov 2019 21:44:56 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2CE148E3866 for ; Tue, 12 Nov 2019 21:44:56 +0000 (UTC) Received: from haggis.mythic-beasts.com (haggis.mythic-beasts.com [46.235.224.141]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-273-JI56I47xMteLmmOqQJzO2Q-1; Tue, 12 Nov 2019 16:44:54 -0500 Received: from [199.195.250.187] (port=57655 helo=hermes.aosc.io) by haggis.mythic-beasts.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1iUdy0-0004WO-6k; Tue, 12 Nov 2019 21:44:52 +0000 Received: from liushuyu.lan (unknown [172.22.1.1]) by hermes.aosc.io (Postfix) with ESMTPS id B56DD41B36; Tue, 12 Nov 2019 21:44:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573595108; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=P+iqLk98KU7/v7wnXvYiTXJ+DNGnApsyRXik2/j+KN4=; b=LVggIY/LuiE3r1is+FiVVCwhQLNmLmT+PrXMJ4U2licAebfE1jXNC+/AZljj7ynvve4zkz /lodav4Dpk8YlCH3iqdi6BwE2BrOQIJK83+NCvF5XtgKxyrZPDIKd5gNo75I2KjV3AdqLW Pb/MVcasomshaBT7zErHyo1IWpXzUIo= From: Zixing Liu To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 14:44:44 -0700 Message-Id: <20191112214445.14541-4-liushuyu@aosc.io> In-Reply-To: <20191112214445.14541-1-liushuyu@aosc.io> References: <20191112214445.14541-1-liushuyu@aosc.io> MIME-Version: 1.0 X-Spamd-Result: default: False [2.90 / 15.00] R_MISSING_CHARSET(2.50)[] BROKEN_CONTENT_TYPE(1.50)[] REPLY(-2.00)[] MID_CONTAINS_FROM(1.00)[] TO_DN_ALL(0.00)[] FROM_EQ_ENVFROM(0.00)[] MAILCOW_MOO(0.00)[] FROM_HAS_DN(0.00)[] TO_MATCH_ENVRCPT_ALL(0.00)[] RCPT_COUNT_THREE(0.00)[3] RCVD_COUNT_TWO(0.00)[2] MIME_GOOD(-0.10)[text/plain] X-Rspamd-Server: rspamd X-Rspamd-Scan-Time: 0.01 X-Rspamd-Queue-ID: B56DD41B36 X-BlackCat-Spam-Score: 50 X-Spam-Status: No, score=5.0 X-MC-Unique: JI56I47xMteLmmOqQJzO2Q-1 X-MC-Unique: tXdlkrYNMJC-rN-UzrbEeQ-1 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xACLiumU027050 X-loop: libvir-list@redhat.com Cc: Zixing Liu , sahid.ferdjaoui@canonical.com Subject: [libvirt] [PATCH Rust 3/4] libvirt-rust: stream: automated lint X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" * used rustfmt to clean up the code Signed-off-by: Zixing Liu --- src/stream.rs | 97 +++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/src/stream.rs b/src/stream.rs index 1ffd186..0d84fd7 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -18,8 +18,8 @@ =20 extern crate libc; =20 -use connect::Connect; use connect::sys::virConnectPtr; +use connect::Connect; use std::convert::TryFrom; =20 use error::Error; @@ -33,28 +33,28 @@ pub mod sys { =20 #[link(name =3D "virt")] extern "C" { - fn virStreamNew(c: virConnectPtr, - flags: libc::c_uint) - -> sys::virStreamPtr; - fn virStreamSend(c: sys::virStreamPtr, - data: *const libc::c_char, - nbytes: libc::size_t) - -> libc::c_int; - fn virStreamRecv(c: sys::virStreamPtr, - data: *mut libc::c_char, - nbytes: libc::size_t) - -> libc::c_int; + fn virStreamNew(c: virConnectPtr, flags: libc::c_uint) -> sys::virStre= amPtr; + fn virStreamSend( + c: sys::virStreamPtr, + data: *const libc::c_char, + nbytes: libc::size_t, + ) -> libc::c_int; + fn virStreamRecv( + c: sys::virStreamPtr, + data: *mut libc::c_char, + nbytes: libc::size_t, + ) -> libc::c_int; fn virStreamFree(c: sys::virStreamPtr) -> libc::c_int; fn virStreamAbort(c: sys::virStreamPtr) -> libc::c_int; fn virStreamFinish(c: sys::virStreamPtr) -> libc::c_int; - fn virStreamEventAddCallback(c: sys::virStreamPtr, - event: libc::c_int, - callback: StreamEventCallback, - opaque: *const libc::c_void, - ff: FreeCallback) - -> libc::c_int; - fn virStreamEventUpdateCallback(c: sys::virStreamPtr, - events: libc::c_int) -> libc::c_int; + fn virStreamEventAddCallback( + c: sys::virStreamPtr, + event: libc::c_int, + callback: StreamEventCallback, + opaque: *const libc::c_void, + ff: FreeCallback, + ) -> libc::c_int; + fn virStreamEventUpdateCallback(c: sys::virStreamPtr, events: libc::c_= int) -> libc::c_int; fn virStreamEventRemoveCallback(c: sys::virStreamPtr) -> libc::c_int; } =20 @@ -71,14 +71,16 @@ pub type StreamEventCallback =3D extern "C" fn(sys::vir= StreamPtr, libc::c_int, *co pub type FreeCallback =3D extern "C" fn(*mut libc::c_void); =20 // wrapper for callbacks -extern "C" fn event_callback(c: sys::virStreamPtr, flags: libc::c_int, opa= que: *const libc::c_void) { - let flags =3D flags as StreamFlags; - let shadow_self =3D unsafe { - &mut*(opaque as *mut Stream) - }; - if let Some(callback) =3D &mut shadow_self.callback { - callback(&Stream::from_ptr(c), flags); - } +extern "C" fn event_callback( + c: sys::virStreamPtr, + flags: libc::c_int, + opaque: *const libc::c_void, +) { + let flags =3D flags as StreamFlags; + let shadow_self =3D unsafe { &mut *(opaque as *mut Stream) }; + if let Some(callback) =3D &mut shadow_self.callback { + callback(&Stream::from_ptr(c), flags); + } } =20 extern "C" fn event_free(_opaque: *mut libc::c_void) {} @@ -93,16 +95,18 @@ impl Drop for Stream { fn drop(&mut self) { if self.ptr.is_some() { if let Err(e) =3D self.free() { - panic!("Unable to drop memory for Stream, code {}, message= : {}", - e.code, - e.message) + panic!( + "Unable to drop memory for Stream, code {}, message: {= }", + e.code, e.message + ) } } if self.callback.is_some() { if let Err(e) =3D self.event_remove_callback() { - panic!("Unable to remove event callback for Stream, code {= }, message: {}", - e.code, - e.message) + panic!( + "Unable to remove event callback for Stream, code {}, = message: {}", + e.code, e.message + ) } } } @@ -120,7 +124,10 @@ impl Stream { } =20 pub fn from_ptr(ptr: sys::virStreamPtr) -> Stream { - Stream { ptr: Some(ptr), callback: None } + Stream { + ptr: Some(ptr), + callback: None, + } } =20 pub fn as_ptr(&self) -> sys::virStreamPtr { @@ -160,7 +167,7 @@ impl Stream { virStreamSend( self.as_ptr(), data.as_ptr() as *mut libc::c_char, - data.len() + data.len(), ) }; usize::try_from(ret).map_err(|_| Error::new()) @@ -177,10 +184,20 @@ impl Stream { usize::try_from(ret).map_err(|_| Error::new()) } =20 - pub fn event_add_callback(&mut self, events: StreamEventType, cb: F) -> Result<(), Error> { + pub fn event_add_callback( + &mut self, + events: StreamEventType, + cb: F, + ) -> Result<(), Error> { let ret =3D unsafe { let ptr =3D &*self as *const _ as *const _; - virStreamEventAddCallback(self.as_ptr(), events as libc::c_int= , event_callback, ptr, event_free) + virStreamEventAddCallback( + self.as_ptr(), + events as libc::c_int, + event_callback, + ptr, + event_free, + ) }; if ret =3D=3D -1 { return Err(Error::new()); @@ -190,9 +207,7 @@ impl Stream { } =20 pub fn event_update_callback(&self, events: StreamEventType) -> Result= <(), Error> { - let ret =3D unsafe { - virStreamEventUpdateCallback(self.as_ptr(), events as libc::c_= int) - }; + let ret =3D unsafe { virStreamEventUpdateCallback(self.as_ptr(), e= vents as libc::c_int) }; if ret =3D=3D -1 { return Err(Error::new()); } --=20 2.24.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list