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/descriptor/reader.h | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'upb/descriptor/reader.h') diff --git a/upb/descriptor/reader.h b/upb/descriptor/reader.h index bcd4b06..bb9565c 100644 --- a/upb/descriptor/reader.h +++ b/upb/descriptor/reader.h @@ -18,52 +18,52 @@ namespace upb { namespace descriptor { class Reader; -} // namespace descriptor -} // namespace upb +} /* namespace descriptor */ +} /* namespace upb */ #endif -UPB_DECLARE_TYPE(upb::descriptor::Reader, upb_descreader); +UPB_DECLARE_TYPE(upb::descriptor::Reader, upb_descreader) #ifdef __cplusplus -// Class that receives descriptor data according to the descriptor.proto schema -// and use it to build upb::Defs corresponding to that schema. +/* Class that receives descriptor data according to the descriptor.proto schema + * and use it to build upb::Defs corresponding to that schema. */ class upb::descriptor::Reader { public: - // These handlers must have come from NewHandlers() and must outlive the - // Reader. - // - // TODO: generate the handlers statically (like we do with the - // descriptor.proto defs) so that there is no need to pass this parameter (or - // to build/memory-manage the handlers at runtime at all). Unfortunately this - // is a bit tricky to implement for Handlers, but necessary to simplify this - // interface. + /* These handlers must have come from NewHandlers() and must outlive the + * Reader. + * + * TODO: generate the handlers statically (like we do with the + * descriptor.proto defs) so that there is no need to pass this parameter (or + * to build/memory-manage the handlers at runtime at all). Unfortunately this + * is a bit tricky to implement for Handlers, but necessary to simplify this + * interface. */ static Reader* Create(Environment* env, const Handlers* handlers); - // The reader's input; this is where descriptor.proto data should be sent. + /* The reader's input; this is where descriptor.proto data should be sent. */ Sink* input(); - // Returns an array of all defs that have been parsed, and transfers ownership - // of them to "owner". The number of defs is stored in *n. Ownership of the - // returned array is retained and is invalidated by any other call into - // Reader. - // - // These defs are not frozen or resolved; they are ready to be added to a - // symtab. + /* Returns an array of all defs that have been parsed, and transfers ownership + * of them to "owner". The number of defs is stored in *n. Ownership of the + * returned array is retained and is invalidated by any other call into + * Reader. + * + * These defs are not frozen or resolved; they are ready to be added to a + * symtab. */ upb::Def** GetDefs(void* owner, int* n); - // Builds and returns handlers for the reader, owned by "owner." + /* Builds and returns handlers for the reader, owned by "owner." */ static Handlers* NewHandlers(const void* owner); private: - UPB_DISALLOW_POD_OPS(Reader, upb::descriptor::Reader); + UPB_DISALLOW_POD_OPS(Reader, upb::descriptor::Reader) }; #endif UPB_BEGIN_EXTERN_C -// C API. +/* C API. */ upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h); upb_sink *upb_descreader_input(upb_descreader *r); upb_def **upb_descreader_getdefs(upb_descreader *r, void *owner, int *n); @@ -72,7 +72,7 @@ const upb_handlers *upb_descreader_newhandlers(const void *owner); UPB_END_EXTERN_C #ifdef __cplusplus -// C++ implementation details. ///////////////////////////////////////////////// +/* C++ implementation details. ************************************************/ namespace upb { namespace descriptor { inline Reader* Reader::Create(Environment* e, const Handlers *h) { @@ -82,8 +82,8 @@ inline Sink* Reader::input() { return upb_descreader_input(this); } inline upb::Def** Reader::GetDefs(void* owner, int* n) { return upb_descreader_getdefs(this, owner, n); } -} // namespace descriptor -} // namespace upb +} /* namespace descriptor */ +} /* namespace upb */ #endif -#endif // UPB_DESCRIPTOR_H +#endif /* UPB_DESCRIPTOR_H */ -- cgit v1.2.3