summaryrefslogtreecommitdiffstats
path: root/pb.h
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2015-01-03 10:59:19 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2015-01-03 10:59:19 +0200
commitb0d31468da7f644684be897cef5b0602ca10af0f (patch)
tree1a4bc2c093a46c8d82c816965f7ad3bad3b88df0 /pb.h
parent7be7c7769f9532b2aca98e271540a565a6a321e6 (diff)
Change PB_RETURN_ERROR() macro to avoid compiler warnings.
Update issue 140 Status: FixedInGit
Diffstat (limited to 'pb.h')
-rw-r--r--pb.h21
1 files changed, 10 insertions, 11 deletions
diff --git a/pb.h b/pb.h
index 442d9658..5a3340aa 100644
--- a/pb.h
+++ b/pb.h
@@ -508,22 +508,21 @@ struct pb_extension_s {
* is the true/false return value from functions.
* Some code space can be saved by disabling the error
* messages if not used.
+ *
+ * PB_SET_ERROR() sets the error message if none has been set yet.
+ * msg must be a constant string literal.
+ * PB_GET_ERROR() always returns a pointer to a string.
+ * PB_RETURN_ERROR() sets the error and returns false from current
+ * function.
*/
#ifdef PB_NO_ERRMSG
-#define PB_RETURN_ERROR(stream,msg) \
- do {\
- PB_UNUSED(stream); \
- return false; \
- } while(0)
+#define PB_SET_ERROR(stream, msg) PB_UNUSED(stream)
#define PB_GET_ERROR(stream) "(errmsg disabled)"
#else
-#define PB_RETURN_ERROR(stream,msg) \
- do {\
- if ((stream)->errmsg == NULL) \
- (stream)->errmsg = (msg); \
- return false; \
- } while(0)
+#define PB_SET_ERROR(stream, msg) (stream->errmsg = (stream)->errmsg ? (stream)->errmsg : (msg))
#define PB_GET_ERROR(stream) ((stream)->errmsg ? (stream)->errmsg : "(none)")
#endif
+#define PB_RETURN_ERROR(stream, msg) return PB_SET_ERROR(stream, msg), false
+
#endif