|
|
|
@ -24,10 +24,6 @@ |
|
|
|
|
#include <string.h> |
|
|
|
|
#include "upb/upb.h" |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
extern "C" { |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* upb_value ******************************************************************/ |
|
|
|
|
|
|
|
|
@ -49,7 +45,7 @@ typedef enum { |
|
|
|
|
} upb_ctype_t; |
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
uint64_t val; |
|
|
|
|
upb_msgval val; |
|
|
|
|
#ifndef NDEBUG |
|
|
|
|
/* In debug mode we carry the value type around also so we can check accesses
|
|
|
|
|
* to be sure the right member is being read. */ |
|
|
|
@ -73,13 +69,13 @@ UPB_INLINE char *upb_gstrdup(const char *s) { |
|
|
|
|
return upb_strdup(s, &upb_alloc_global); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val, |
|
|
|
|
UPB_INLINE void _upb_value_setval(upb_value *v, upb_msgval val, |
|
|
|
|
upb_ctype_t ctype) { |
|
|
|
|
v->val = val; |
|
|
|
|
SET_TYPE(v->ctype, ctype); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) { |
|
|
|
|
UPB_INLINE upb_value _upb_value_val(upb_msgval val, upb_ctype_t ctype) { |
|
|
|
|
upb_value ret; |
|
|
|
|
_upb_value_setval(&ret, val, ctype); |
|
|
|
|
return ret; |
|
|
|
@ -95,7 +91,7 @@ UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) { |
|
|
|
|
* upb_value upb_value_int32(int32_t val); */ |
|
|
|
|
#define FUNCS(name, membername, type_t, converter, proto_type) \ |
|
|
|
|
UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \
|
|
|
|
|
val->val = (converter)cval; \
|
|
|
|
|
val->val = upb_msgval_ ## converter(cval); \
|
|
|
|
|
SET_TYPE(val->ctype, proto_type); \
|
|
|
|
|
} \
|
|
|
|
|
UPB_INLINE upb_value upb_value_ ## name(type_t val) { \
|
|
|
|
@ -105,18 +101,18 @@ UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) { |
|
|
|
|
} \
|
|
|
|
|
UPB_INLINE type_t upb_value_get ## name(upb_value val) { \
|
|
|
|
|
UPB_ASSERT_DEBUGVAR(val.ctype == proto_type); \
|
|
|
|
|
return (type_t)(converter)val.val; \
|
|
|
|
|
return (type_t)upb_msgval_get ## converter(val.val); \
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32) |
|
|
|
|
FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64) |
|
|
|
|
FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32) |
|
|
|
|
FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64) |
|
|
|
|
FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL) |
|
|
|
|
FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR) |
|
|
|
|
FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR) |
|
|
|
|
FUNCS(constptr, constptr, const void*, uintptr_t, UPB_CTYPE_CONSTPTR) |
|
|
|
|
FUNCS(fptr, fptr, upb_func*, uintptr_t, UPB_CTYPE_FPTR) |
|
|
|
|
FUNCS(int32, int32, int32_t, int32, UPB_CTYPE_INT32) |
|
|
|
|
FUNCS(int64, int64, int64_t, int64, UPB_CTYPE_INT64) |
|
|
|
|
FUNCS(uint32, uint32, uint32_t, uint32, UPB_CTYPE_UINT32) |
|
|
|
|
FUNCS(uint64, uint64, uint64_t, uint64, UPB_CTYPE_UINT64) |
|
|
|
|
FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL) |
|
|
|
|
FUNCS(cstr, cstr, char*, cstr, UPB_CTYPE_CSTR) |
|
|
|
|
FUNCS(ptr, ptr, void*, ptr, UPB_CTYPE_PTR) |
|
|
|
|
FUNCS(constptr, constptr, const void*, constptr, UPB_CTYPE_CONSTPTR) |
|
|
|
|
FUNCS(fptr, fptr, upb_func*, fptr, UPB_CTYPE_FPTR) |
|
|
|
|
|
|
|
|
|
#undef FUNCS |
|
|
|
|
|
|
|
|
@ -187,7 +183,7 @@ UPB_INLINE char *upb_tabstr(upb_tabkey key, uint32_t *len) { |
|
|
|
|
* This separate definition is necessary because in C++, UINTPTR_MAX isn't |
|
|
|
|
* reliably available. */ |
|
|
|
|
typedef struct { |
|
|
|
|
uint64_t val; |
|
|
|
|
upb_msgval val; |
|
|
|
|
} upb_tabval; |
|
|
|
|
|
|
|
|
|
#else |
|
|
|
@ -218,7 +214,7 @@ typedef union { |
|
|
|
|
} staticinit; |
|
|
|
|
|
|
|
|
|
/* The normal accessor that we use for everything at runtime. */ |
|
|
|
|
uint64_t val; |
|
|
|
|
upb_msgval val; |
|
|
|
|
} upb_tabval; |
|
|
|
|
|
|
|
|
|
#ifdef UPB_PTR_IS_64BITS |
|
|
|
@ -352,7 +348,7 @@ static const upb_tabent *upb_getentry(const upb_table *t, uint32_t hash) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE bool upb_arrhas(upb_tabval key) { |
|
|
|
|
return key.val != (uint64_t)-1; |
|
|
|
|
return key.val.u64 != (uint64_t)-1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Initialize and uninitialize a table, respectively. If memory allocation
|
|
|
|
@ -589,9 +585,6 @@ void upb_inttable_iter_setdone(upb_inttable_iter *i); |
|
|
|
|
bool upb_inttable_iter_isequal(const upb_inttable_iter *i1, |
|
|
|
|
const upb_inttable_iter *i2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
} /* extern "C" */ |
|
|
|
|
#endif |
|
|
|
|
UPB_END_EXTERN_C |
|
|
|
|
|
|
|
|
|
#endif /* UPB_TABLE_H_ */ |
|
|
|
|