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/json/printer.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'upb/json/printer.h') diff --git a/upb/json/printer.h b/upb/json/printer.h index c73cb79..0b4e19c 100644 --- a/upb/json/printer.h +++ b/upb/json/printer.h @@ -18,11 +18,11 @@ namespace upb { namespace json { class Printer; -} // namespace json -} // namespace upb +} /* namespace json */ +} /* namespace upb */ #endif -UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer); +UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer) /* upb::json::Printer *********************************************************/ @@ -31,29 +31,29 @@ UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer); #ifdef __cplusplus -// Prints an incoming stream of data to a BytesSink in JSON format. +/* Prints an incoming stream of data to a BytesSink in JSON format. */ class upb::json::Printer { public: static Printer* Create(Environment* env, const upb::Handlers* handlers, BytesSink* output); - // The input to the printer. + /* The input to the printer. */ Sink* input(); - // Returns handlers for printing according to the specified schema. + /* Returns handlers for printing according to the specified schema. */ static reffed_ptr NewHandlers(const upb::MessageDef* md); static const size_t kSize = UPB_JSON_PRINTER_SIZE; private: - UPB_DISALLOW_POD_OPS(Printer, upb::json::Printer); + UPB_DISALLOW_POD_OPS(Printer, upb::json::Printer) }; #endif UPB_BEGIN_EXTERN_C -// Native C API. +/* Native C API. */ upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h, upb_bytessink *output); upb_sink *upb_json_printer_input(upb_json_printer *p); @@ -76,9 +76,9 @@ inline reffed_ptr Printer::NewHandlers( const Handlers* h = upb_json_printer_newhandlers(md, &h); return reffed_ptr(h, &h); } -} // namespace json -} // namespace upb +} /* namespace json */ +} /* namespace upb */ #endif -#endif // UPB_JSON_TYPED_PRINTER_H_ +#endif /* UPB_JSON_TYPED_PRINTER_H_ */ -- cgit v1.2.3