summaryrefslogtreecommitdiff
path: root/upb/shim
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2015-05-18 10:55:20 -0700
committerJosh Haberman <jhaberman@gmail.com>2015-06-02 15:55:45 -0700
commit919fea438a5ac5366684cfa26d2bb3d17519cb60 (patch)
tree6a2d282c3c7910263241e03f41be23c6a6cda710 /upb/shim
parent6650b3c6527c17965adf7239850857a10d56ba62 (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 'upb/shim')
-rw-r--r--upb/shim/shim.c8
-rw-r--r--upb/shim/shim.h24
2 files changed, 17 insertions, 15 deletions
diff --git a/upb/shim/shim.c b/upb/shim/shim.c
index 02da85d..2f7f215 100644
--- a/upb/shim/shim.c
+++ b/upb/shim/shim.c
@@ -9,7 +9,7 @@
#include <stdlib.h>
-// Fallback implementation if the shim is not specialized by the JIT.
+/* Fallback implementation if the shim is not specialized by the JIT. */
#define SHIM_WRITER(type, ctype) \
bool upb_shim_set ## type (void *c, const void *hd, ctype val) { \
uint8_t *m = c; \
@@ -31,12 +31,14 @@ SHIM_WRITER(bool, bool)
bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset,
int32_t hasbit) {
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ bool ok;
+
upb_shim_data *d = malloc(sizeof(*d));
if (!d) return false;
d->offset = offset;
d->hasbit = hasbit;
- upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
upb_handlerattr_sethandlerdata(&attr, d);
upb_handlerattr_setalwaysok(&attr, true);
upb_handlers_addcleanup(h, d, free);
@@ -45,7 +47,7 @@ bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset,
case UPB_TYPE_##u: \
ok = upb_handlers_set##l(h, f, upb_shim_set##l, &attr); break;
- bool ok = false;
+ ok = false;
switch (upb_fielddef_type(f)) {
TYPE(INT64, int64);
diff --git a/upb/shim/shim.h b/upb/shim/shim.h
index 0d090db..0ccd6fb 100644
--- a/upb/shim/shim.h
+++ b/upb/shim/shim.h
@@ -32,33 +32,33 @@ namespace upb {
struct Shim {
typedef upb_shim_data Data;
- // Sets a handler for the given field that writes the value to the given
- // offset and, if hasbit >= 0, sets a bit at the given bit offset. Returns
- // true if the handler was set successfully.
+ /* Sets a handler for the given field that writes the value to the given
+ * offset and, if hasbit >= 0, sets a bit at the given bit offset. Returns
+ * true if the handler was set successfully. */
static bool Set(Handlers *h, const FieldDef *f, size_t ofs, int32_t hasbit);
- // If this handler is a shim, returns the corresponding upb::Shim::Data and
- // stores the type in "type". Otherwise returns NULL.
+ /* If this handler is a shim, returns the corresponding upb::Shim::Data and
+ * stores the type in "type". Otherwise returns NULL. */
static const Data* GetData(const Handlers* h, Handlers::Selector s,
FieldDef::Type* type);
};
-} // namespace upb
+} /* namespace upb */
#endif
-UPB_BEGIN_EXTERN_C // {
+UPB_BEGIN_EXTERN_C
-// C API.
+/* C API. */
bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset,
int32_t hasbit);
const upb_shim_data *upb_shim_getdata(const upb_handlers *h, upb_selector_t s,
upb_fieldtype_t *type);
-UPB_END_EXTERN_C // }
+UPB_END_EXTERN_C
#ifdef __cplusplus
-// C++ Wrappers.
+/* C++ Wrappers. */
namespace upb {
inline bool Shim::Set(Handlers* h, const FieldDef* f, size_t ofs,
int32_t hasbit) {
@@ -68,7 +68,7 @@ inline const Shim::Data* Shim::GetData(const Handlers* h, Handlers::Selector s,
FieldDef::Type* type) {
return upb_shim_getdata(h, s, type);
}
-} // namespace upb
+} /* namespace upb */
#endif
-#endif // UPB_SHIM_H
+#endif /* UPB_SHIM_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback