diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2012-03-31 12:17:32 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2012-03-31 12:17:32 -0700 |
commit | cca4818eb7769d6e776bdc30516a5f871f1d6393 (patch) | |
tree | e67dd65d5c016028ae976b09b2d69f6b7525aa5f /upb/upb.h | |
parent | 26ed1e996171c8ffa2ced42ac69b1b82c1956e1f (diff) |
Sync from internal Google development.
Diffstat (limited to 'upb/upb.h')
-rw-r--r-- | upb/upb.h | 66 |
1 files changed, 45 insertions, 21 deletions
@@ -31,6 +31,10 @@ extern "C" { #define UPB_NORETURN #endif +#ifndef UINT16_MAX +#define UINT16_MAX 65535 +#endif + #define UPB_MAX(x, y) ((x) > (y) ? (x) : (y)) #define UPB_MIN(x, y) ((x) < (y) ? (x) : (y)) @@ -135,11 +139,21 @@ typedef struct { // // Construct a new upb_value from an int32. // upb_value upb_value_int32(int32_t val); -#define UPB_VALUE_ACCESSORS(name, membername, ctype, proto_type) \ - INLINE ctype upb_value_get ## name(upb_value val) { \ - assert(val.type == proto_type); \ - return val.val.membername; \ +#define WRITERS(name, membername, ctype, proto_type) \ + INLINE void upb_value_set ## name(upb_value *val, ctype cval) { \ + val->val.uint64 = 0; \ + SET_TYPE(val->type, proto_type); \ + val->val.membername = cval; \ } \ + INLINE upb_value upb_value_ ## name(ctype val) { \ + upb_value ret; \ + upb_value_set ## name(&ret, val); \ + return ret; \ + } + +#define ALL(name, membername, ctype, proto_type) \ + /* Can't reuse WRITERS() here unfortunately because "bool" is a macro \ + * that expands to _Bool, so it ends up defining eg. upb_value_set_Bool */ \ INLINE void upb_value_set ## name(upb_value *val, ctype cval) { \ val->val.uint64 = 0; \ SET_TYPE(val->type, proto_type); \ @@ -149,25 +163,39 @@ typedef struct { upb_value ret; \ upb_value_set ## name(&ret, val); \ return ret; \ + } \ + INLINE ctype upb_value_get ## name(upb_value val) { \ + assert(val.type == proto_type); \ + return val.val.membername; \ } -UPB_VALUE_ACCESSORS(int32, int32, int32_t, UPB_CTYPE_INT32); -UPB_VALUE_ACCESSORS(int64, int64, int64_t, UPB_CTYPE_INT64); -UPB_VALUE_ACCESSORS(uint32, uint32, uint32_t, UPB_CTYPE_UINT32); -UPB_VALUE_ACCESSORS(uint64, uint64, uint64_t, UPB_CTYPE_UINT64); -UPB_VALUE_ACCESSORS(double, _double, double, UPB_CTYPE_DOUBLE); -UPB_VALUE_ACCESSORS(float, _float, float, UPB_CTYPE_FLOAT); -UPB_VALUE_ACCESSORS(bool, _bool, bool, UPB_CTYPE_BOOL); -UPB_VALUE_ACCESSORS(ptr, _void, void*, UPB_CTYPE_PTR); -UPB_VALUE_ACCESSORS(byteregion, byteregion, struct _upb_byteregion*, - UPB_CTYPE_BYTEREGION); +ALL(int32, int32, int32_t, UPB_CTYPE_INT32); +ALL(int64, int64, int64_t, UPB_CTYPE_INT64); +ALL(uint32, uint32, uint32_t, UPB_CTYPE_UINT32); +ALL(uint64, uint64, uint64_t, UPB_CTYPE_UINT64); +ALL(bool, _bool, bool, UPB_CTYPE_BOOL); +ALL(ptr, _void, void*, UPB_CTYPE_PTR); +ALL(byteregion, byteregion, struct _upb_byteregion*, UPB_CTYPE_BYTEREGION); // upb_fielddef should never be modified from a callback // (ie. when they're getting passed through a upb_value). -UPB_VALUE_ACCESSORS(fielddef, fielddef, const struct _upb_fielddef*, - UPB_CTYPE_FIELDDEF); +ALL(fielddef, fielddef, const struct _upb_fielddef*, UPB_CTYPE_FIELDDEF); + +#ifdef __KERNEL__ +// Linux kernel modules are compiled without SSE and therefore are incapable +// of compiling functions that return floating-point values, so we define as +// macros instead and lose the type check. +WRITERS(double, _double, double, UPB_CTYPE_DOUBLE); +WRITERS(float, _float, float, UPB_CTYPE_FLOAT); +#define upb_value_getdouble(v) (v.val._double) +#define upb_value_getfloat(v) (v.val._float) +#else +ALL(double, _double, double, UPB_CTYPE_DOUBLE); +ALL(float, _float, float, UPB_CTYPE_FLOAT); +#endif /* __KERNEL__ */ -#undef UPB_VALUE_ACCESSORS +#undef WRITERS +#undef ALL extern upb_value UPB_NO_VALUE; @@ -218,10 +246,6 @@ INLINE void upb_status_seteof(upb_status *s) { s->eof = true; } const char *upb_status_getstr(const upb_status *s); void upb_status_copy(upb_status *to, const upb_status *from); -extern upb_errorspace upb_posix_errorspace; -void upb_status_fromerrno(upb_status *status); -bool upb_errno_is_wouldblock(); - // Like vasprintf (which allocates a string large enough for the result), but // uses *buf (which can be NULL) as a starting point and reallocates it only if // the new value will not fit. "size" is updated to reflect the allocated size |