diff options
author | Josh Haberman <jhaberman@gmail.com> | 2016-09-09 14:03:25 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2016-11-29 17:56:13 +0000 |
commit | 4b0c4ca7fb0aa9207af3398e04534b23fbb88f27 (patch) | |
tree | 045750c6262e74f366ae2ec29797d3816005c21a /upb/upb.h | |
parent | 77c97fd3f29caa5c243294b5f4e6763b3ed3c36f (diff) |
New upb_msg code and Lua bindings around it.
There are still some things that are unfinished,
but we are at parity with what Lua had before.
Diffstat (limited to 'upb/upb.h')
-rw-r--r-- | upb/upb.h | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -208,6 +208,12 @@ template <int N> class InlinedEnvironment; * exist in debug mode. This turns into regular assert. */ #define UPB_ASSERT_DEBUGVAR(expr) assert(expr) +#ifdef __GNUC__ +#define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0) +#else +#define UPB_UNREACHABLE() do { assert(0); } while(0) +#endif + /* Generic function type. */ typedef void upb_func(); @@ -441,17 +447,18 @@ struct upb_alloc { }; UPB_INLINE void *upb_malloc(upb_alloc *alloc, size_t size) { - UPB_ASSERT(size > 0); + UPB_ASSERT(alloc); return alloc->func(alloc, NULL, 0, size); } UPB_INLINE void *upb_realloc(upb_alloc *alloc, void *ptr, size_t oldsize, size_t size) { - UPB_ASSERT(size > 0); + UPB_ASSERT(alloc); return alloc->func(alloc, ptr, oldsize, size); } UPB_INLINE void upb_free(upb_alloc *alloc, void *ptr) { + assert(alloc); alloc->func(alloc, ptr, 0, 0); } @@ -500,7 +507,6 @@ UPB_BEGIN_EXTERN_C void upb_arena_init(upb_arena *a); void upb_arena_init2(upb_arena *a, void *mem, size_t n, upb_alloc *alloc); void upb_arena_uninit(upb_arena *a); -upb_alloc *upb_arena_alloc(upb_arena *a); bool upb_arena_addcleanup(upb_arena *a, upb_cleanup_func *func, void *ud); size_t upb_arena_bytesallocated(const upb_arena *a); void upb_arena_setnextblocksize(upb_arena *a, size_t size); @@ -585,6 +591,10 @@ struct upb_arena { void *future2; }; +UPB_BEGIN_EXTERN_C +UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return &a->alloc; } +UPB_END_EXTERN_C + /* upb::Environment ***********************************************************/ |