summaryrefslogtreecommitdiff
path: root/upb/upb.h
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2016-12-07 17:07:05 -0800
committerGitHub <noreply@github.com>2016-12-07 17:07:05 -0800
commit076a82ee7edf35fb5f2a3430535e21a6dbd4cd6d (patch)
tree87969c375756dc4290478c9ecc5d0d87ae48f557 /upb/upb.h
parent9a91f7bba8c89ed4d1cb0d56b8a394a9590df029 (diff)
parent2b77da3da8234484ebc099c560671ea21ab7181b (diff)
Merge pull request #74 from haberman/msg
Added upb_msg and Lua bindings for using it.
Diffstat (limited to 'upb/upb.h')
-rw-r--r--upb/upb.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/upb/upb.h b/upb/upb.h
index 46bed8a..a2b79ca 100644
--- a/upb/upb.h
+++ b/upb/upb.h
@@ -209,6 +209,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();
@@ -442,17 +448,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);
}
@@ -501,11 +508,11 @@ 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);
void upb_arena_setmaxblocksize(upb_arena *a, size_t size);
+UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return (upb_alloc*)a; }
UPB_END_EXTERN_C
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback