KalleOlaviNiemitalo commented on code in PR #3635:
URL: https://github.com/apache/avro/pull/3635#discussion_r2732420709
##########
lang/c/src/encoding.h:
##########
@@ -99,6 +99,9 @@ typedef struct avro_encoding_t avro_encoding_t;
#define AVRO_SKIP(reader, len) \
{ int rval = avro_skip( reader, len); if (rval) return rval; }
+#define AVRO_SAFE_READ(reader, buf, len, mem_size) \
+{ int rval = avro_read( reader, buf, len ); if(rval) { if(buf) avro_free(buf,
mem_size); buf = NULL; return rval; } }
Review Comment:
This kind of thing would typically have `do { ... } while (0)` so that it
swallows a trailing semicolon and can be used within `if` … `else' statements
in a natural-looking way. But I see the existing macros don't use that idiom
either.
##########
lang/c/src/encoding.h:
##########
@@ -99,6 +99,9 @@ typedef struct avro_encoding_t avro_encoding_t;
#define AVRO_SKIP(reader, len) \
{ int rval = avro_skip( reader, len); if (rval) return rval; }
+#define AVRO_SAFE_READ(reader, buf, len, mem_size) \
Review Comment:
I'd rather call it `AVRO_READ_OR_FREE` as it isn't particularly safer than
`AVRO_READ`.
Alternatively, write it inline instead of defining a macro. I think the
flow control would be easier to understand that way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]