From 5e8551fbc0fc2c80e18d1d64ab40916d7181dc5a Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 24 Oct 2019 12:51:24 +0200 Subject: [PATCH] util: virbuffer: Remove @dynamic from virBufferGetIndent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the conversion of all callers that would pass true as @dynamic to a different function we can remove the unused argument now. Additionally modify the return type to 'size_t' as indentation can't be negative and remove checks whether @buf is passed as it's caller's duty to do so. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/conf/domain_conf.c | 2 +- src/conf/network_conf.c | 2 +- src/util/virbuffer.c | 12 +++--------- src/util/virbuffer.h | 4 ++-- tests/testutilsqemuschema.c | 2 +- tests/virbuftest.c | 12 ++++++------ 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6aeef3e5c5..d3156de522 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28487,7 +28487,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, xmlIndentTreeOutput = 1; xmlbuf = xmlBufferCreate(); if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, - virBufferGetIndent(buf, false) / 2, 1) < 0) { + virBufferGetIndent(buf) / 2, 1) < 0) { xmlBufferFree(xmlbuf); xmlIndentTreeOutput = oldIndentTreeOutput; goto error; diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 7f8e43b25c..1d20d28f46 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2458,7 +2458,7 @@ virNetworkDefFormatBuf(virBufferPtr buf, xmlIndentTreeOutput = 1; xmlbuf = xmlBufferCreate(); if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, - virBufferGetIndent(buf, false) / 2, 1) < 0) { + virBufferGetIndent(buf) / 2, 1) < 0) { xmlBufferFree(xmlbuf); xmlIndentTreeOutput = oldIndentTreeOutput; goto error; diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 0d2721b118..bf703fe7a5 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -102,18 +102,12 @@ virBufferSetIndent(virBufferPtr buf, int indent) /** * virBufferGetIndent: * @buf: the buffer - * @dynamic: if false, return set value; if true, return 0 unless next - * append would be affected by auto-indent * - * Return the current auto-indent value, or -1 if there has been an error. + * Return the current auto-indent setting of @buf. */ -int -virBufferGetIndent(const virBuffer *buf, bool dynamic) +size_t +virBufferGetIndent(const virBuffer *buf) { - if (!buf || buf->error) - return -1; - if (dynamic && buf->use && buf->content[buf->use - 1] != '\n') - return 0; return buf->indent; } diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 7156d9d0d8..6c41a7ea20 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -107,9 +107,9 @@ void virBufferSetIndent(virBufferPtr, int indent); * child buffer. */ #define virBufferSetChildIndent(childBuf_, parentBuf_) \ - virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_, false) + 2) + virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_) + 2) -int virBufferGetIndent(const virBuffer *buf, bool dynamic); +size_t virBufferGetIndent(const virBuffer *buf); size_t virBufferGetEffectiveIndent(const virBuffer *buf); void virBufferTrim(virBufferPtr buf, const char *trim, int len); diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 42b2550a03..9a1b1fea07 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -430,7 +430,7 @@ testQEMUSchemaValidateAlternate(virJSONValuePtr obj, virBufferAddLit(debug, "(\n"); virBufferAdjustIndent(debug, 3); - indent = virBufferGetIndent(debug, false); + indent = virBufferGetIndent(debug); n = virJSONValueArraySize(members); for (i = 0; i < n; i++) { diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 0c806908e1..34aa8b678b 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -18,7 +18,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) char *result = NULL; int ret = 0; - if (virBufferGetIndent(buf, false) != 0 || + if (virBufferGetIndent(buf) != 0 || virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; @@ -28,28 +28,28 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) VIR_TEST_DEBUG("Wrong content"); ret = -1; } - if (virBufferGetIndent(buf, false) != 3 || + if (virBufferGetIndent(buf) != 3 || virBufferGetEffectiveIndent(buf) != 3 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } virBufferAdjustIndent(buf, -2); - if (virBufferGetIndent(buf, false) != 1 || + if (virBufferGetIndent(buf) != 1 || virBufferGetEffectiveIndent(buf) != 1 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } virBufferAdjustIndent(buf, -3); - if (virBufferGetIndent(buf, false) != 0 || + if (virBufferGetIndent(buf) != 0 || virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Indentation level not truncated"); ret = -1; } virBufferAdjustIndent(buf, 3); virBufferFreeAndReset(buf); - if (virBufferGetIndent(buf, false) != 0 || + if (virBufferGetIndent(buf) != 0 || virBufferGetEffectiveIndent(buf) != 0 || virBufferError(buf)) { VIR_TEST_DEBUG("Reset didn't clear indentation"); @@ -65,7 +65,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) VIR_TEST_DEBUG("Wrong content"); ret = -1; } - if (virBufferGetIndent(buf, false) != 2 || + if (virBufferGetIndent(buf) != 2 || virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; -- GitLab