Re: [PATCHv2 01/13] virbuf: fix const-correctness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 09/30/2011 12:22 AM, Eric Blake wrote:
Although the compiler wasn't complaining (since it was the pointer,
rather than what was being pointed to, that was actually const), it
looks quite suspicious to call a function with an argument labeled
const when the nature of the pointer (virBufferPtr) is hidden behind
a typedef.  Dropping const makes the function declarations easier
to read.

* src/util/buf.h: Drop const from all functions that modify buffer
argument.
* src/util/buf.c (virBufferSetError, virBufferAdd)
(virBufferContentAndReset, virBufferFreeAndReset)
(virBufferAsprintf, virBufferVasprintf, virBufferEscapeString)
(virBufferEscapeSexpr): Fix fallout.
---
  src/util/buf.c |   28 ++++++++++++++--------------
  src/util/buf.h |   22 ++++++++++++----------
  2 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/src/util/buf.c b/src/util/buf.c
index 5002486..c737696 100644
--- a/src/util/buf.c
+++ b/src/util/buf.c
@@ -39,7 +39,7 @@ struct _virBuffer {
   * freeing the content and setting the error flag.
   */
  static void
-virBufferSetError(const virBufferPtr buf)
+virBufferSetError(virBufferPtr buf)
  {
      VIR_FREE(buf->content);
      buf->size = 0;
@@ -113,7 +113,7 @@ virBufferAdd(const virBufferPtr buf, const char *str, int len)

Maybe a typo here?The virBufferPtr still remains const, but the declaration of this function in the buf.h shows this const is removed, too.
  /**
   * virBufferAddChar:
- * @buf: the buffer to add to
+ * @buf: the buffer to append to
   * @c: the character to add
   *
   * Add a single character 'c' to a buffer.
@@ -150,7 +150,7 @@ virBufferAddChar (virBufferPtr buf, char c)
   * Returns the buffer content or NULL in case of error.
   */
  char *
-virBufferContentAndReset(const virBufferPtr buf)
+virBufferContentAndReset(virBufferPtr buf)
  {
      char *str;
      if (buf == NULL)
@@ -172,7 +172,7 @@ virBufferContentAndReset(const virBufferPtr buf)
   *
   * Frees the buffer content and resets the buffer structure.
   */
-void virBufferFreeAndReset(const virBufferPtr buf)
+void virBufferFreeAndReset(virBufferPtr buf)
  {
      char *str = virBufferContentAndReset(buf);

@@ -214,14 +214,14 @@ virBufferUse(const virBufferPtr buf)

  /**
   * virBufferAsprintf:
- * @buf:  the buffer to dump
+ * @buf: the buffer to append to
   * @format:  the format
   * @...:  the variable list of arguments
   *
   * Do a formatted print to an XML buffer.
   */
  void
-virBufferAsprintf(const virBufferPtr buf, const char *format, ...)
+virBufferAsprintf(virBufferPtr buf, const char *format, ...)
  {
      va_list argptr;
      va_start(argptr, format);
@@ -238,7 +238,7 @@ virBufferAsprintf(const virBufferPtr buf, const char *format, ...)
   * Do a formatted print to an XML buffer.
   */
  void
-virBufferVasprintf(const virBufferPtr buf, const char *format, va_list argptr)
+virBufferVasprintf(virBufferPtr buf, const char *format, va_list argptr)
  {
      int size, count, grow_size;
      va_list copy;
@@ -285,7 +285,7 @@ virBufferVasprintf(const virBufferPtr buf, const char *format, va_list argptr)

  /**
   * virBufferEscapeString:
- * @buf:  the buffer to dump
+ * @buf: the buffer to append to
   * @format: a printf like format string but with only one %s parameter
   * @str:  the string argument which need to be escaped
   *
@@ -293,7 +293,7 @@ virBufferVasprintf(const virBufferPtr buf, const char *format, va_list argptr)
   * is escaped to avoid generating a not well-formed XML instance.
   */
  void
-virBufferEscapeString(const virBufferPtr buf, const char *format, const char *str)
+virBufferEscapeString(virBufferPtr buf, const char *format, const char *str)
  {
      int len;
      char *escaped, *out;
@@ -370,7 +370,7 @@ virBufferEscapeString(const virBufferPtr buf, const char *format, const char *st

  /**
   * virBufferEscapeSexpr:
- * @buf:  the buffer to dump
+ * @buf: the buffer to append to
   * @format: a printf like format string but with only one %s parameter
   * @str:  the string argument which need to be escaped
   *
@@ -379,7 +379,7 @@ virBufferEscapeString(const virBufferPtr buf, const char *format, const char *st
   * doesn't fully escape the sexpr, just enough for our code to work.
   */
  void
-virBufferEscapeSexpr(const virBufferPtr buf,
+virBufferEscapeSexpr(virBufferPtr buf,
                       const char *format,
                       const char *str)
  {
@@ -426,7 +426,7 @@ virBufferEscapeSexpr(const virBufferPtr buf,

  /**
   * virBufferURIEncodeString:
- * @buf:  the buffer to append to
+ * @buf: the buffer to append to
   * @str:  the string argument which will be URI-encoded
   *
   * Append the string to the buffer.  The string will be URI-encoded
@@ -434,7 +434,7 @@ virBufferEscapeSexpr(const virBufferPtr buf,
   * with '%xx' hex sequences).
   */
  void
-virBufferURIEncodeString (virBufferPtr buf, const char *str)
+virBufferURIEncodeString(virBufferPtr buf, const char *str)
  {
      int grow_size = 0;
      const char *p;
@@ -473,7 +473,7 @@ virBufferURIEncodeString (virBufferPtr buf, const char *str)

  /**
   * virBufferStrcat:
- * @buf:  the buffer to dump
+ * @buf: the buffer to append to
   * @...:  the variable list of strings, the last argument must be NULL
   *
   * Concatenate strings to an XML buffer.
diff --git a/src/util/buf.h b/src/util/buf.h
index 06d01ba..42a5044 100644
--- a/src/util/buf.h
+++ b/src/util/buf.h
@@ -36,21 +36,23 @@ struct _virBuffer {
  };
  # endif

-char *virBufferContentAndReset(const virBufferPtr buf);
-void virBufferFreeAndReset(const virBufferPtr buf);
+char *virBufferContentAndReset(virBufferPtr buf);
+void virBufferFreeAndReset(virBufferPtr buf);
  int virBufferError(const virBufferPtr buf);
  unsigned int virBufferUse(const virBufferPtr buf);
-void virBufferAdd(const virBufferPtr buf, const char *str, int len);
-void virBufferAddChar(const virBufferPtr buf, char c);
-void virBufferAsprintf(const virBufferPtr buf, const char *format, ...)
+void virBufferAdd(virBufferPtr buf, const char *str, int len);
+void virBufferAddChar(virBufferPtr buf, char c);
+void virBufferAsprintf(virBufferPtr buf, const char *format, ...)
    ATTRIBUTE_FMT_PRINTF(2, 3);
-void virBufferVasprintf(const virBufferPtr buf, const char *format, va_list ap)
+void virBufferVasprintf(virBufferPtr buf, const char *format, va_list ap)
    ATTRIBUTE_FMT_PRINTF(2, 0);
-void virBufferStrcat(const virBufferPtr buf, ...)
+void virBufferStrcat(virBufferPtr buf, ...)
    ATTRIBUTE_SENTINEL;
-void virBufferEscapeString(const virBufferPtr buf, const char *format, const char *str);
-void virBufferEscapeSexpr(const virBufferPtr buf, const char *format, const char *str);
-void virBufferURIEncodeString (const virBufferPtr buf, const char *str);
+void virBufferEscapeString(virBufferPtr buf, const char *format,
+                           const char *str);
+void virBufferEscapeSexpr(virBufferPtr buf, const char *format,
+                          const char *str);
+void virBufferURIEncodeString(virBufferPtr buf, const char *str);

  # define virBufferAddLit(buf_, literal_string_) \
    virBufferAdd (buf_, "" literal_string_ "", sizeof literal_string_ - 1)

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]