xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Kelley Nielsen <kelleynnn@gmail.com>
To: xen-devel@lists.xensource.com
Cc: Ian.Campbell@citrix.com
Subject: [PATCH] libxl: Use LOG and LOGE macros in READ_WRITE_EXACTLY macro
Date: Mon, 11 Nov 2013 05:06:36 -0800	[thread overview]
Message-ID: <1384175196-26458-1-git-send-email-kelleynnn@gmail.com> (raw)

The new coding style makes use of the LOG* family of convenience
macros. They rely on the availability of a libxl__gc gc*, but making
it available can make the code more complicated. In this case I
think it does so especially, and I'd like to ask if it's worth
changing in this case and in similar cases.

Suggested-by: Ian Campbell <Ian.Campbell@citrix.com>
Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com>
---
 tools/libxl/libxl_utils.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 135778f..4238316 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -363,33 +363,49 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
 
 #define READ_WRITE_EXACTLY(rw, zero_is_eof, constdata)                    \
                                                                           \
-  int libxl_##rw##_exactly(libxl_ctx *ctx, int fd,                 \
+  int libxl_##rw##_exactly(libxl_ctx *ctx, int fd,                        \
                            constdata void *data, ssize_t sz,              \
                            const char *source, const char *what) {        \
+      GC_INIT(ctx);                                                       \
       ssize_t got;                                                        \
+      int ret = 0;                                                            \
                                                                           \
       while (sz > 0) {                                                    \
           got = rw(fd, data, sz);                                         \
           if (got == -1) {                                                \
               if (errno == EINTR) continue;                               \
-              if (!ctx) return errno;                                     \
-              LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to " #rw " %s%s%s", \
+              if (!ctx)                                                   \
+	      {                                                           \
+	          ret = errno;                                            \
+	          goto out;                                               \
+	      }                                                           \
+              LOGE(ERROR, "failed to " #rw " %s%s%s",                     \
                            what?what:"", what?" from ":"", source);       \
-              return errno;                                               \
+              ret = errno;                                                \
+	      goto out;                                                   \
           }                                                               \
           if (got == 0) {                                                 \
-              if (!ctx) return EPROTO;                                    \
-              LIBXL__LOG(ctx, LIBXL__LOG_ERROR,                                   \
+              if (!ctx)                                                   \
+	      {                                                           \
+	          ret = EPROTO;                                           \
+	          goto out;	                                          \
+	      }                                                           \
+              LOG(ERROR,                                                  \
                      zero_is_eof                                          \
                      ? "file/stream truncated reading %s%s%s"             \
                      : "file/stream write returned 0! writing %s%s%s",    \
                      what?what:"", what?" from ":"", source);             \
-              return EPROTO;                                              \
+              ret = EPROTO;                                               \
+	      goto out;                                                   \
           }                                                               \
           sz -= got;                                                      \
           data = (char*)data + got;                                       \
       }                                                                   \
       return 0;                                                           \
+                                                                          \
+  out:                                                                    \
+      GC_FREE;                                                            \
+      return ret;                                                         \
   }
 
 READ_WRITE_EXACTLY(read, 1, /* */)
-- 
1.8.1.2

                 reply	other threads:[~2013-11-11 13:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1384175196-26458-1-git-send-email-kelleynnn@gmail.com \
    --to=kelleynnn@gmail.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).