]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: buffer: Remove error handling internals
authorPeter Krempa <pkrempa@redhat.com>
Thu, 24 Oct 2019 12:09:42 +0000 (14:09 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 24 Oct 2019 17:35:34 +0000 (19:35 +0200)
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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virbuffer.c
src/util/virbuffer.h

index 9306b7970346d39620db03a89f3fddd533dc8594..e6480ca4efe50c331950f9c600d32f35e13cc9b1 100644 (file)
 #include <stdarg.h>
 
 #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 = 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 = indent;
@@ -171,7 +156,7 @@ virBufferApplyIndent(virBufferPtr buf)
 void
 virBufferAdd(virBufferPtr buf, const char *str, int len)
 {
-    if (!str || !buf || buf->error || (len == 0 && buf->indent == 0))
+    if (!str || !buf || (len == 0 && buf->indent == 0))
         return;
 
     virBufferInitialize(buf);
@@ -203,12 +188,6 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd)
     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 == 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 == 0)
-        return 0;
-
-    if (buf->error == ENOMEM) {
-        virReportOOMErrorFull(domcode, filename, funcname, linenr);
-        errno = ENOMEM;
-    } else {
-        virReportErrorHelper(domcode, VIR_ERR_INTERNAL_ERROR, filename,
-                             funcname, linenr, "%s",
-                             _("Invalid buffer API usage"));
-        errno = EINVAL;
-    }
-    return -1;
+    return 0;
 }
 
 /**
@@ -391,9 +351,6 @@ virBufferVasprintf(virBufferPtr buf, const char *format, va_list argptr)
     if ((format == NULL) || (buf == NULL))
         return;
 
-    if (buf->error)
-        return;
-
     virBufferInitialize(buf);
     virBufferApplyIndent(buf);
 
@@ -430,9 +387,6 @@ virBufferEscapeString(virBufferPtr buf, const char *format, const char *str)
     if ((format == NULL) || (buf == NULL) || (str == NULL))
         return;
 
-    if (buf->error)
-        return;
-
     len = strlen(str);
     if (strcspn(str, forbidden_characters) == len) {
         virBufferAsprintf(buf, format, str);
@@ -575,9 +529,6 @@ virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
     if ((format == NULL) || (buf == NULL) || (str == NULL))
         return;
 
-    if (buf->error)
-        return;
-
     len = strlen(str);
     if (strcspn(str, toescape) == len) {
         virBufferAsprintf(buf, format, str);
@@ -615,9 +566,6 @@ virBufferURIEncodeString(virBufferPtr buf, const char *str)
     if ((buf == NULL) || (str == NULL))
         return;
 
-    if (buf->error)
-        return;
-
     virBufferInitialize(buf);
     virBufferApplyIndent(buf);
 
@@ -643,9 +591,6 @@ virBufferEscapeShell(virBufferPtr buf, const char *str)
     if ((buf == NULL) || (str == 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 = va_arg(ap, char *)) != NULL)
         virBufferAdd(buf, str, -1);
 }
@@ -737,7 +679,7 @@ virBufferTrim(virBufferPtr buf, const char *str, int len)
 {
     size_t len2 = 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) {
index f5b3961f9b8978b23770cbb883713e70899535aa..9adec89f57d35497faa65fe4c167416ed73f3d0f 100644 (file)
 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, virBufferFreeAndReset);
  * 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);