From nobody Mon Feb 9 04:09:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571925442; cv=none; d=zoho.com; s=zohoarc; b=d3KCR8ElMoBYH8kpR/0bFl5hWKjy9KqUpLp6MNHYDPCHXHbjDsj1VYXM0u2cgYQWnYlgg85f12QMzeHc41/YWV0Uf/hcdeKNDp4O1RL24R1H3Je+lpIehBDg8wEezkL8kEkROoZTW+scSR2kKzshF64Ekcj3czWDZjeN1Lhw4fo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925442; h=Content-Type:Content-Transfer-Encoding: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=kBJviRanzZA6QoQvv5i7PURQoxeAZTr7qf7yDJ1bvUc=; b=WaMYzq/ktCB7NtzclEJrlr1+bHmtwMxxdKfO5a95WoLaEBaMhn3DLD5M2Q0MMT0dVNUQnHt7lAv9J+7BA57GZwuGMZ0k+twLR/Qu0haii1brJYz+HWVptR2ba/lCfJXjlheHx76a7pwshAxNR65H2+FmOWMOHtAlZGlerBipJFY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571925442764759.6143950439712; Thu, 24 Oct 2019 06:57:22 -0700 (PDT) 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-138-XMWZc-I6OMOjZmjGXt-VJQ-1; Thu, 24 Oct 2019 09:57:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BFEAC800D4C; Thu, 24 Oct 2019 13:57:14 +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 96222614CE; Thu, 24 Oct 2019 13:57:14 +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 5313B1803B4E; Thu, 24 Oct 2019 13:57:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv8SK026439 for ; Thu, 24 Oct 2019 09:57:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 860BC100164D; Thu, 24 Oct 2019 13:57:08 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 100B210027A9 for ; Thu, 24 Oct 2019 13:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925441; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=kBJviRanzZA6QoQvv5i7PURQoxeAZTr7qf7yDJ1bvUc=; b=QaNJN3YkMd5a8JgiPkAYWrhYs9q4YCtb9gls6BCGjDCcyI+3UpBbX0nQc5b+VzsBXaQFQh A+nDQ7yXY5rY79l8v0H2xYVclRKKfeEiW4tgkJriekZGeAX3eERcXEEDhXPUo0G7tsP+AS 4EiMIRRSe51jqgRuhGKWl4viVuaLYTI= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:34 +0200 Message-Id: <0d92261f20e6a28234bac1b10d3665800daa259f.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 16/19] util: buffer: Remove error handling internals 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.13 X-MC-Unique: XMWZc-I6OMOjZmjGXt-VJQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Now that there are no errors reported and tracked in virBuffer, remove all the internals which were used to track them. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 78 ++++++-------------------------------------- src/util/virbuffer.h | 13 +++----- 2 files changed, 14 insertions(+), 77 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 9306b79703..e6480ca4ef 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -23,26 +23,11 @@ #include #include "virbuffer.h" -#include "virerror.h" #include "virstring.h" #include "viralloc.h" #define VIR_FROM_THIS VIR_FROM_NONE -/** - * virBufferFail - * @buf: the buffer - * @error: which error occurred (errno value, or -1 for usage) - * - * Mark the buffer as failed, free the content and set the error flag. - */ -static void -virBufferSetError(virBufferPtr buf, int error) -{ - virBufferFreeAndReset(buf); - buf->error =3D error; -} - /** * virBufferAdjustIndent: * @buf: the buffer @@ -58,7 +43,7 @@ virBufferSetError(virBufferPtr buf, int error) void virBufferAdjustIndent(virBufferPtr buf, int indent) { - if (!buf || buf->error) + if (!buf) return; if (indent > 0) { @@ -88,7 +73,7 @@ virBufferAdjustIndent(virBufferPtr buf, int indent) void virBufferSetIndent(virBufferPtr buf, int indent) { - if (!buf || buf->error) + if (!buf) return; buf->indent =3D indent; @@ -171,7 +156,7 @@ virBufferApplyIndent(virBufferPtr buf) void virBufferAdd(virBufferPtr buf, const char *str, int len) { - if (!str || !buf || buf->error || (len =3D=3D 0 && buf->indent =3D=3D = 0)) + if (!str || !buf || (len =3D=3D 0 && buf->indent =3D=3D 0)) return; virBufferInitialize(buf); @@ -203,12 +188,6 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toad= d) if (!buf) goto cleanup; - if (buf->error || toadd->error) { - if (!buf->error) - virBufferSetError(buf, toadd->error); - goto cleanup; - } - virBufferInitialize(buf); g_string_append_len(buf->str, toadd->str->str, toadd->str->len); @@ -243,7 +222,7 @@ virBufferAddChar(virBufferPtr buf, char c) const char * virBufferCurrentContent(virBufferPtr buf) { - if (!buf || buf->error) + if (!buf) return NULL; if (!buf->str || @@ -307,12 +286,9 @@ void virBufferFreeAndReset(virBufferPtr buf) * Return positive errno value or -1 on usage error, 0 if normal */ int -virBufferError(const virBuffer *buf) +virBufferError(const virBuffer *buf G_GNUC_UNUSED) { - if (buf =3D=3D NULL) - return -1; - - return buf->error; + return 0; } /** @@ -324,25 +300,9 @@ virBufferError(const virBuffer *buf) * Return -1 if an error has been reported, 0 otherwise. */ int -virBufferCheckErrorInternal(const virBuffer *buf, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) +virBufferCheckErrorInternal(const virBuffer *buf G_GNUC_UNUSED) { - if (buf->error =3D=3D 0) - return 0; - - if (buf->error =3D=3D ENOMEM) { - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno =3D ENOMEM; - } else { - virReportErrorHelper(domcode, VIR_ERR_INTERNAL_ERROR, filename, - funcname, linenr, "%s", - _("Invalid buffer API usage")); - errno =3D EINVAL; - } - return -1; + return 0; } /** @@ -391,9 +351,6 @@ virBufferVasprintf(virBufferPtr buf, const char *format= , va_list argptr) if ((format =3D=3D NULL) || (buf =3D=3D NULL)) return; - if (buf->error) - return; - virBufferInitialize(buf); virBufferApplyIndent(buf); @@ -430,9 +387,6 @@ virBufferEscapeString(virBufferPtr buf, const char *for= mat, const char *str) if ((format =3D=3D NULL) || (buf =3D=3D NULL) || (str =3D=3D NULL)) return; - if (buf->error) - return; - len =3D strlen(str); if (strcspn(str, forbidden_characters) =3D=3D len) { virBufferAsprintf(buf, format, str); @@ -575,9 +529,6 @@ virBufferEscape(virBufferPtr buf, char escape, const ch= ar *toescape, if ((format =3D=3D NULL) || (buf =3D=3D NULL) || (str =3D=3D NULL)) return; - if (buf->error) - return; - len =3D strlen(str); if (strcspn(str, toescape) =3D=3D len) { virBufferAsprintf(buf, format, str); @@ -615,9 +566,6 @@ virBufferURIEncodeString(virBufferPtr buf, const char *= str) if ((buf =3D=3D NULL) || (str =3D=3D NULL)) return; - if (buf->error) - return; - virBufferInitialize(buf); virBufferApplyIndent(buf); @@ -643,9 +591,6 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) if ((buf =3D=3D NULL) || (str =3D=3D NULL)) return; - if (buf->error) - return; - /* Only quote if str includes shell metacharacters. */ if (*str && !strpbrk(str, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~")) { virBufferAdd(buf, str, -1); @@ -693,9 +638,6 @@ virBufferStrcatVArgs(virBufferPtr buf, { char *str; - if (buf->error) - return; - while ((str =3D va_arg(ap, char *)) !=3D NULL) virBufferAdd(buf, str, -1); } @@ -737,7 +679,7 @@ virBufferTrim(virBufferPtr buf, const char *str, int le= n) { size_t len2 =3D 0; - if (!buf || buf->error || !buf->str) + if (!buf || !buf->str) return; if (!str && len < 0) @@ -775,7 +717,7 @@ virBufferAddStr(virBufferPtr buf, { const char *end; - if (!buf || !str || buf->error) + if (!buf || !str) return; while (*str) { diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index f5b3961f9b..9adec89f57 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -33,11 +33,10 @@ typedef struct _virBuffer virBuffer; typedef virBuffer *virBufferPtr; -#define VIR_BUFFER_INITIALIZER { NULL, 0, 0 } +#define VIR_BUFFER_INITIALIZER { NULL, 0 } struct _virBuffer { GString *str; - int error; /* errno value, or -1 for usage error */ int indent; }; @@ -45,11 +44,7 @@ const char *virBufferCurrentContent(virBufferPtr buf); char *virBufferContentAndReset(virBufferPtr buf); void virBufferFreeAndReset(virBufferPtr buf); int virBufferError(const virBuffer *buf); -int virBufferCheckErrorInternal(const virBuffer *buf, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) +int virBufferCheckErrorInternal(const virBuffer *buf) ATTRIBUTE_NONNULL(1); G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virBuffer, virBufferFreeAndReset); @@ -63,8 +58,8 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virBuffer, virBufferFree= AndReset); * and -1 is returned. */ #define virBufferCheckError(buf) \ - virBufferCheckErrorInternal(buf, VIR_FROM_THIS, __FILE__, __FUNCTION__= , \ - __LINE__) + virBufferCheckErrorInternal(buf) + size_t virBufferUse(const virBuffer *buf); void virBufferAdd(virBufferPtr buf, const char *str, int len); void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list