[waffle] [PATCH] waffle: use enum waffle_error instead of int

Brian Paul brianp at vmware.com
Fri Nov 15 11:30:06 PST 2013


Using the enum type instead of int makes debugging a little easier.
It just seems like the right thing to do anyway.
---
 include/waffle/waffle.h                |    4 ++--
 man/waffle_error.3.xml                 |    2 +-
 src/waffle/api/waffle_error.c          |    2 +-
 src/waffle/core/wcore_error.c          |    8 ++++----
 src/waffle/core/wcore_error.h          |    6 +++---
 src/waffle/core/wcore_error_unittest.c |    4 ++--
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
index 0987f36..5f29a5e 100644
--- a/include/waffle/waffle.h
+++ b/include/waffle/waffle.h
@@ -84,12 +84,12 @@ enum waffle_error {
 };
 
 struct waffle_error_info {
-    int32_t code;
+    enum waffle_error code;
     const char *message;
     size_t message_length;
 };
 
-WAFFLE_API int32_t
+WAFFLE_API enum waffle_error
 waffle_error_get_code(void);
 
 WAFFLE_API const struct waffle_error_info*
diff --git a/man/waffle_error.3.xml b/man/waffle_error.3.xml
index c0cbd65..14b01d5 100644
--- a/man/waffle_error.3.xml
+++ b/man/waffle_error.3.xml
@@ -58,7 +58,7 @@ struct waffle_error_info {
       </funcprototype>
 
       <funcprototype>
-        <funcdef>int32_t <function>waffle_error_get_code</function></funcdef>
+        <funcdef>enum waffle_error <function>waffle_error_get_code</function></funcdef>
         <void/>
       </funcprototype>
 
diff --git a/src/waffle/api/waffle_error.c b/src/waffle/api/waffle_error.c
index 01790bc..6e29061 100644
--- a/src/waffle/api/waffle_error.c
+++ b/src/waffle/api/waffle_error.c
@@ -32,7 +32,7 @@
 
 #include "wcore_error.h"
 
-int32_t
+enum waffle_error
 waffle_error_get_code(void)
 {
     return wcore_error_get_code();
diff --git a/src/waffle/core/wcore_error.c b/src/waffle/core/wcore_error.c
index edcb821..30e96fd 100644
--- a/src/waffle/core/wcore_error.c
+++ b/src/waffle/core/wcore_error.c
@@ -46,7 +46,7 @@ enum {
 
 struct wcore_error_tinfo {
     bool is_enabled;
-    int32_t code;
+    enum waffle_error code;
     char message[WCORE_ERROR_MESSAGE_BUFSIZE];
 
     /// @brief The user-visible portion of the error state.
@@ -99,7 +99,7 @@ wcore_error_reset(void)
 }
 
 void
-wcore_error(int error)
+wcore_error(enum waffle_error error)
 {
     struct wcore_error_tinfo *t = wcore_tinfo_get()->error;
 
@@ -118,7 +118,7 @@ wcore_error(int error)
 }
 
 void
-wcore_errorf(int error, const char *format, ...)
+wcore_errorf(enum waffle_error error, const char *format, ...)
 {
     struct wcore_error_tinfo *t = wcore_tinfo_get()->error;
     va_list ap;
@@ -213,7 +213,7 @@ _wcore_error_internal(const char *file, int line, const char *format, ...)
     snprintf(cur, end - cur, " (report this bug to chad at chad-versace.us)");
 }
 
-int
+enum waffle_error
 wcore_error_get_code(void)
 {
     return wcore_tinfo_get()->error->code;
diff --git a/src/waffle/core/wcore_error.h b/src/waffle/core/wcore_error.h
index d466612..882bb6a 100644
--- a/src/waffle/core/wcore_error.h
+++ b/src/waffle/core/wcore_error.h
@@ -57,14 +57,14 @@ wcore_error_reset(void);
 ///
 /// @param error is an `enum waffle_error`.
 void
-wcore_error(int error);
+wcore_error(enum waffle_error error);
 
 /// @brief Set error code and message for client.
 ///
 /// @param error is an `enum waffle_error`.
 /// @param format may be null.
 void
-wcore_errorf(int error, const char *format, ...);
+wcore_errorf(enum waffle_error error, const char *format, ...);
 
 /// @brief Emit error for errno.
 ///
@@ -87,7 +87,7 @@ wcore_error_errno(const char *format, ...);
     } while (0)
 
 /// @brief Get the last set error code.
-int
+enum waffle_error
 wcore_error_get_code(void);
 
 /// @brief Get the user-visible portion of the error state.
diff --git a/src/waffle/core/wcore_error_unittest.c b/src/waffle/core/wcore_error_unittest.c
index 086fb91..19edf99 100644
--- a/src/waffle/core/wcore_error_unittest.c
+++ b/src/waffle/core/wcore_error_unittest.c
@@ -156,14 +156,14 @@ struct thread_arg {
 static bool
 thread_start(struct thread_arg *a)
 {
-    static const int error_codes[NUM_THREADS] = {
+    static const enum waffle_error error_codes[NUM_THREADS] = {
         WAFFLE_ERROR_BAD_ATTRIBUTE,
         WAFFLE_ERROR_UNKNOWN,
         WAFFLE_ERROR_ALREADY_INITIALIZED,
     };
 
     bool ok = true;
-    int error_code = error_codes[a->thread_id];
+    enum waffle_error error_code = error_codes[a->thread_id];
 
     // Each thread begins in an error-free state.
     ok &= wcore_error_get_code() == WAFFLE_NO_ERROR;
-- 
1.7.10.4



More information about the waffle mailing list