From 68bc62a7fa5febbf5c8ab2fe8f6171121d18690f Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 19 Apr 2016 14:57:31 -0700 Subject: Split upb::Arena/upb::Allocator from upb::Environment. (#58) * Split upb::Arena/upb::Allocator from upb::Environment. This will allow arenas and allocators to be used independently of environments, which will be important for an upcoming change (a message representation). Overall this design feels cleaner that the previous Environment/SeededAllocator design. As part of this change, moved all allocations in upb to use a global allocator instead of hard-coding malloc/free. This will allow injecting OOM faults for more robust testing. One place that doesn't use the global allocator is the tracked ref code. Instead of its previous approach of CHECK_OOM() after every malloc() or table insert, it simply uses an allocator that does this automatically. I moved Allocator/Arena/Environment into upb.h. This seems principled since these are the only types in upb whose size is directly exposed to users, since they form the basis of memory allocation strategy. * Cleaned up some header includes and fixed more malloc -> upb_gmalloc(). * Changes from PR review. * Don't use UINTPTR_MAX or UINT64_MAX. * Punt on adding line/file for now. * We actually can't store (uint64_t)-1, update comment and test. --- tests/test_def.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests/test_def.c') diff --git a/tests/test_def.c b/tests/test_def.c index de3bcb2..e9ca438 100644 --- a/tests/test_def.c +++ b/tests/test_def.c @@ -44,20 +44,23 @@ static upb_symtab *load_test_proto(void *owner) { upb_status status = UPB_STATUS_INIT; size_t len; char *data = upb_readfile(descriptor_file, &len); - upb_filedef **files; + upb_filedef **files, **files_ptr; ASSERT(s); ASSERT(data); files = upb_loaddescriptor(data, len, &files, &status); ASSERT(files); free(data); - while (*files) { + files_ptr = files; + while (*files_ptr) { bool ok = upb_symtab_addfile(s, *files, &status); ASSERT(ok); upb_filedef_unref(*files, &files); - files++; + files_ptr++; } + upb_gfree(files); + ASSERT(!upb_symtab_isfrozen(s)); upb_symtab_freeze(s); ASSERT(upb_symtab_isfrozen(s)); -- cgit v1.2.3