From 919fea438a5ac5366684cfa26d2bb3d17519cb60 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Mon, 18 May 2015 10:55:20 -0700 Subject: 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. --- upb/upb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'upb/upb.c') diff --git a/upb/upb.c b/upb/upb.c index c58d307..cee7f56 100644 --- a/upb/upb.c +++ b/upb/upb.c @@ -20,10 +20,10 @@ bool upb_dumptostderr(void *closure, const upb_status* status) { return false; } -// Guarantee null-termination and provide ellipsis truncation. -// It may be tempting to "optimize" this by initializing these final -// four bytes up-front and then being careful never to overwrite them, -// this is safer and simpler. +/* Guarantee null-termination and provide ellipsis truncation. + * It may be tempting to "optimize" this by initializing these final + * four bytes up-front and then being careful never to overwrite them, + * this is safer and simpler. */ static void nullz(upb_status *status) { const char *ellipsis = "..."; size_t len = strlen(ellipsis); @@ -65,7 +65,7 @@ void upb_status_seterrf(upb_status *status, const char *fmt, ...) { void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) { if (!status) return; status->ok_ = false; - vsnprintf(status->msg, sizeof(status->msg), fmt, args); + _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args); nullz(status); } -- cgit v1.2.3