diff options
author | Josh Haberman <jhaberman@gmail.com> | 2015-05-18 10:55:20 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2015-06-02 15:55:45 -0700 |
commit | 919fea438a5ac5366684cfa26d2bb3d17519cb60 (patch) | |
tree | 6a2d282c3c7910263241e03f41be23c6a6cda710 /tests/test_util.h | |
parent | 6650b3c6527c17965adf7239850857a10d56ba62 (diff) |
Ported upb to C89, for greater portability.
A large part of this change contains surface-level
porting, like moving variable declarations to the
top of the block.
However there are a few more substantial things too:
- moved internal-only struct definitions to a separate
file (structdefs.int.h), for greater encapsulation
and ABI compatibility.
- removed the UPB_UPCAST macro, since it requires access
to the internal-only struct definitions. Replaced uses
with calls to inline, type-safe casting functions.
- removed the UPB_DEFINE_CLASS/UPB_DEFINE_STRUCT macros.
Class and struct definitions are now more explicit -- you
get to see the actual class/struct keywords in the source.
The casting convenience functions have been moved into
UPB_DECLARE_DERIVED_TYPE() and UPB_DECLARE_DERIVED_TYPE2().
- the new way that we duplicate base methods in derived types
is also more convenient and requires less duplication.
It is also less greppable, but hopefully that is not
too big a problem.
Compiler flags (-std=c89 -pedantic) should help to rigorously
enforce that the code is free of C99-isms.
A few functions are not available in C89 (strtoll). There
are temporary, hacky solutions in place.
Diffstat (limited to 'tests/test_util.h')
-rw-r--r-- | tests/test_util.h | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/tests/test_util.h b/tests/test_util.h index 27c2bb3..73a5c19 100644 --- a/tests/test_util.h +++ b/tests/test_util.h @@ -38,8 +38,8 @@ bool parse_buffer(upb::BytesSink* sink, void* subc, const char* buf, memcpy(buf2, buf + start, len); if (verbose) { - fprintf(stderr, "Calling parse(%zu) for bytes %zu-%zu of the input\n", - len, start, end); + fprintf(stderr, "Calling parse(%u) for bytes %u-%u of the input\n", + (unsigned)len, (unsigned)start, (unsigned)end); } size_t parsed = sink->PutBuffer(subc, buf2, len, &global_handle); @@ -48,18 +48,18 @@ bool parse_buffer(upb::BytesSink* sink, void* subc, const char* buf, if (verbose) { if (parsed == len) { fprintf(stderr, - "parse(%zu) = %zu, complete byte count indicates success\n", - len, len); + "parse(%u) = %u, complete byte count indicates success\n", + (unsigned)len, (unsigned)len); } else if (parsed > len) { fprintf(stderr, - "parse(%zu) = %zu, long byte count indicates success and skip" - "of the next %zu bytes\n", - len, parsed, parsed - len); + "parse(%u) = %u, long byte count indicates success and skip" + "of the next %u bytes\n", + (unsigned)len, (unsigned)parsed, (unsigned)(parsed - len)); } else { fprintf(stderr, - "parse(%zu) = %zu, short byte count indicates failure; " - "last %zu bytes were not consumed\n", - len, parsed, len - parsed); + "parse(%u) = %u, short byte count indicates failure; " + "last %u bytes were not consumed\n", + (unsigned)len, (unsigned)parsed, (unsigned)(len - parsed)); } } @@ -73,8 +73,8 @@ bool parse_buffer(upb::BytesSink* sink, void* subc, const char* buf, "Error: decode function returned complete byte count but set " "error status\n"); } - fprintf(stderr, "Status: %s, parsed=%zu, len=%zu\n", - status->error_message(), parsed, len); + fprintf(stderr, "Status: %s, parsed=%u, len=%u\n", + status->error_message(), (unsigned)parsed, (unsigned)len); ASSERT(false); } |