xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libxl: Use LOG and LOGE macros in READ_WRITE_EXACTLY macro
@ 2013-11-11 13:06 Kelley Nielsen
  0 siblings, 0 replies; only message in thread
From: Kelley Nielsen @ 2013-11-11 13:06 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian.Campbell

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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-11-11 13:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-11 13:06 [PATCH] libxl: Use LOG and LOGE macros in READ_WRITE_EXACTLY macro Kelley Nielsen

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).