From d869097400048af4b943e0679bab21b759facb80 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Sat, 9 Aug 2014 03:43:32 -0700 Subject: [PATCH] Make the absence of perf-cppflags give a good default build. Defaults are now: - thread-safe with GCC/Clang - Debugging not enabled (enable with -UNDEBUG) --- Makefile | 12 ++++-------- upb/refcounted.c | 2 +- upb/refcounted.h | 11 +++++++---- upb/table.c | 1 + 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 16b14b036d..5ad92517ac 100644 --- a/Makefile +++ b/Makefile @@ -7,17 +7,13 @@ # # Summary of compiler flags you may want to use: # -# * -DNDEBUG: makes binary smaller and faster by removing sanity checks. -# * -O3: optimize for maximum speed +# * -UNDEBUG: enables assertions() (makes binary larger and slower) +# * -O0: disable optimizations +# * -g: enable debug symbols # * -fomit-frame-pointer: makes code smaller and faster by freeing up a reg. # # Threading: -# * -DUPB_USE_PTHREADS: configures upb to use pthreads r/w lock. # * -DUPB_THREAD_UNSAFE: remove all thread-safety. -# * -pthread: required on GCC to enable pthreads (but what does it do?) -# -# Other: -# * -DUPB_UNALIGNED_READS_OK: makes code smaller, but not standard compliant .PHONY: all lib clean tests test benchmarks benchmark descriptorgen .PHONY: clean_leave_profile @@ -49,7 +45,7 @@ CXX=g++ CFLAGS=-std=gnu99 CXXFLAGS= INCLUDE=-Itests -I. -CPPFLAGS=$(INCLUDE) -Wall -Wextra -Wno-sign-compare $(USER_CFLAGS) +CPPFLAGS=$(INCLUDE) -DNDEBUG -Wall -Wextra -Wno-sign-compare $(USER_CFLAGS) LDLIBS=-lpthread upb/libupb.a LUA=lua # 5.1 and 5.2 should both be supported diff --git a/upb/refcounted.c b/upb/refcounted.c index cba535fa25..ca97d9fda8 100644 --- a/upb/refcounted.c +++ b/upb/refcounted.c @@ -35,7 +35,7 @@ const void *UPB_UNTRACKED_REF = &untracked_val; static void atomic_inc(uint32_t *a) { (*a)++; } static bool atomic_dec(uint32_t *a) { return --(*a) == 0; } -#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || __GNUC__ > 4 /////////////////// +#elif defined(__GNUC__) || defined(__clang__) ////////////////////////////////// static void atomic_inc(uint32_t *a) { __sync_fetch_and_add(a, 1); } static bool atomic_dec(uint32_t *a) { return __sync_sub_and_fetch(a, 1) == 0; } diff --git a/upb/refcounted.h b/upb/refcounted.h index 42251b1e28..3de4a12517 100644 --- a/upb/refcounted.h +++ b/upb/refcounted.h @@ -21,10 +21,13 @@ #include "upb/table.int.h" -// Reference tracking is designed to be used with a tool like Valgrind; when -// enabled, it will cause reference leaks to show up as actual memory leaks -// that are attributed to the code that leaked the ref, *not* the code that -// originally created the object. +// Reference tracking will check ref()/unref() operations to make sure the +// ref ownership is correct. Where possible it will also make tools like +// Valgrind attribute ref leaks to the code that took the leaked ref, not +// the code that originally created the object. +// +// Enabling this requires the application to define upb_lock()/upb_unlock() +// functions that acquire/release a global mutex (or #define UPB_THREAD_UNSAFE). #ifndef NDEBUG #define UPB_DEBUG_REFS #endif diff --git a/upb/table.c b/upb/table.c index e0cac642b1..3fd4b0f6fb 100644 --- a/upb/table.c +++ b/upb/table.c @@ -112,6 +112,7 @@ static bool lookup(const upb_table *t, upb_tabkey key, upb_value *v, // The given key must not already exist in the table. static void insert(upb_table *t, upb_tabkey key, upb_value val, hashfunc_t *hash, eqlfunc_t *eql) { + UPB_UNUSED(eql); assert(findentry(t, key, hash, eql) == NULL); assert(val.ctype == t->ctype); t->count++;