Browse files

Honor NDEBUG; build without warnings with NDEBUG; make NDEBUG always-…

…off in unit test code
  • Loading branch information...
1 parent 970e6ad commit 743f8665395e7e06800e1a09a0ae701b72290d02 Nick Mathewson committed Aug 23, 2010
Showing with 44 additions and 14 deletions.
  1. +2 −0 buffer.c
  2. +1 −1 bufferevent_openssl.c
  3. +21 −9 evrpc.c
  4. +1 −2 evthread.c
  5. +3 −0 test/regress_bufferevent.c
  6. +3 −0 test/regress_pthread.c
  7. +3 −0 test/regress_rpc.c
  8. +1 −2 test/regress_util.c
  9. +3 −0 test/regress_zlib.c
  10. +6 −0 util-internal.h
View
2 buffer.c
@@ -233,6 +233,7 @@ evbuffer_free_all_chains(struct evbuffer_chain *chain)
}
}
+#ifndef NDEBUG
static int
evbuffer_chains_all_empty(struct evbuffer_chain *chain)
{
@@ -242,6 +243,7 @@ evbuffer_chains_all_empty(struct evbuffer_chain *chain)
}
return 1;
}
+#endif
static void
evbuffer_chain_insert(struct evbuffer *buf,
View
2 bufferevent_openssl.c
@@ -879,7 +879,7 @@ do_handshake(struct bufferevent_openssl *bev_ssl)
default:
case BUFFEREVENT_SSL_OPEN:
EVUTIL_ASSERT(0);
- break;
+ return -1;
case BUFFEREVENT_SSL_CONNECTING:
case BUFFEREVENT_SSL_ACCEPTING:
r = SSL_do_handshake(bev_ssl->ssl);
View
30 evrpc.c
@@ -94,19 +94,23 @@ evrpc_free(struct evrpc_base *base)
struct evrpc *rpc;
struct evrpc_hook *hook;
struct evrpc_hook_ctx *pause;
+ int r;
while ((rpc = TAILQ_FIRST(&base->registered_rpcs)) != NULL) {
- EVUTIL_ASSERT(evrpc_unregister_rpc(base, rpc->uri));
+ r = evrpc_unregister_rpc(base, rpc->uri);
+ EVUTIL_ASSERT(r);
}
while ((pause = TAILQ_FIRST(&base->paused_requests)) != NULL) {
TAILQ_REMOVE(&base->paused_requests, pause, next);
mm_free(pause);
}
while ((hook = TAILQ_FIRST(&base->input_hooks)) != NULL) {
- EVUTIL_ASSERT(evrpc_remove_hook(base, EVRPC_INPUT, hook));
+ r = evrpc_remove_hook(base, EVRPC_INPUT, hook);
+ EVUTIL_ASSERT(r);
}
while ((hook = TAILQ_FIRST(&base->output_hooks)) != NULL) {
- EVUTIL_ASSERT(evrpc_remove_hook(base, EVRPC_OUTPUT, hook));
+ r = evrpc_remove_hook(base, EVRPC_OUTPUT, hook);
+ EVUTIL_ASSERT(r);
}
mm_free(base);
}
@@ -246,6 +250,7 @@ evrpc_unregister_rpc(struct evrpc_base *base, const char *name)
{
char *registered_uri = NULL;
struct evrpc *rpc;
+ int r;
/* find the right rpc; linear search might be slow */
TAILQ_FOREACH(rpc, &base->registered_rpcs, next) {
@@ -264,7 +269,8 @@ evrpc_unregister_rpc(struct evrpc_base *base, const char *name)
registered_uri = evrpc_construct_uri(name);
/* remove the http server callback */
- EVUTIL_ASSERT(evhttp_del_cb(base->http_server, registered_uri) == 0);
+ r = evhttp_del_cb(base->http_server, registered_uri);
+ EVUTIL_ASSERT(r == 0);
mm_free(registered_uri);
return (0);
@@ -526,6 +532,7 @@ evrpc_pool_free(struct evrpc_pool *pool)
struct evrpc_request_wrapper *request;
struct evrpc_hook_ctx *pause;
struct evrpc_hook *hook;
+ int r;
while ((request = TAILQ_FIRST(&pool->requests)) != NULL) {
TAILQ_REMOVE(&pool->requests, request, next);
@@ -543,11 +550,13 @@ evrpc_pool_free(struct evrpc_pool *pool)
}
while ((hook = TAILQ_FIRST(&pool->input_hooks)) != NULL) {
- EVUTIL_ASSERT(evrpc_remove_hook(pool, EVRPC_INPUT, hook));
+ r = evrpc_remove_hook(pool, EVRPC_INPUT, hook);
+ EVUTIL_ASSERT(r);
}
while ((hook = TAILQ_FIRST(&pool->output_hooks)) != NULL) {
- EVUTIL_ASSERT(evrpc_remove_hook(pool, EVRPC_OUTPUT, hook));
+ r = evrpc_remove_hook(pool, EVRPC_OUTPUT, hook);
+ EVUTIL_ASSERT(r);
}
mm_free(pool);
@@ -1019,10 +1028,13 @@ evrpc_hook_add_meta(void *ctx, const char *key,
if ((store = req->hook_meta) == NULL)
store = req->hook_meta = evrpc_hook_meta_new();
- EVUTIL_ASSERT((meta = mm_malloc(sizeof(struct evrpc_meta))) != NULL);
- EVUTIL_ASSERT((meta->key = mm_strdup(key)) != NULL);
+ meta = mm_malloc(sizeof(struct evrpc_meta));
+ EVUTIL_ASSERT(meta != NULL);
+ meta->key = mm_strdup(key);
+ EVUTIL_ASSERT(meta->key != NULL);
meta->data_size = data_size;
- EVUTIL_ASSERT((meta->data = mm_malloc(data_size)) != NULL);
+ meta->data = mm_malloc(data_size);
+ EVUTIL_ASSERT(meta->data != NULL);
memcpy(meta->data, data, data_size);
TAILQ_INSERT_TAIL(&store->meta_data, meta, next);
View
3 evthread.c
@@ -187,8 +187,7 @@ evthread_debug_lock_mark_unlocked(unsigned mode, struct debug_lock *lock)
else
EVUTIL_ASSERT((mode & (EVTHREAD_READ|EVTHREAD_WRITE)) == 0);
if (_evthread_id_fn) {
- unsigned long me = _evthread_id_fn();
- EVUTIL_ASSERT(lock->held_by == me);
+ EVUTIL_ASSERT(lock->held_by == _evthread_id_fn());
if (lock->count == 1)
lock->held_by = 0;
}
View
3 test/regress_bufferevent.c
@@ -25,6 +25,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/* The old tests here need assertions to work. */
+#undef NDEBUG
+
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
View
3 test/regress_pthread.c
@@ -24,6 +24,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/* The old tests here need assertions to work. */
+#undef NDEBUG
+
#include "event2/event-config.h"
#include <sys/types.h>
View
3 test/regress_rpc.c
@@ -25,6 +25,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/* The old tests here need assertions to work. */
+#undef NDEBUG
+
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
View
3 test/regress_util.c
@@ -49,7 +49,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include "event2/event.h"
#include "event2/util.h"
@@ -832,7 +831,7 @@ test_evutil_rand(void *arg)
buf2[j] |= buf1[j];
++counts[(unsigned char)buf1[j]];
} else {
- assert(buf1[j] == 0);
+ tt_assert(buf1[j] == 0);
tt_int_op(buf1[j], ==, 0);
}
View
3 test/regress_zlib.c
@@ -24,6 +24,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/* The old tests here need assertions to work. */
+#undef NDEBUG
+
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
View
6 util-internal.h
@@ -168,6 +168,10 @@ long _evutil_weakrand(void);
#endif
/* Replacement for assert() that calls event_errx on failure. */
+#ifdef NDEBUG
+#define EVUTIL_ASSERT(cond) _EVUTIL_NIL_STMT
+#define EVUTIL_FAILURE_CHECK(cond) 0
+#else
#define EVUTIL_ASSERT(cond) \
do { \
if (EVUTIL_UNLIKELY(!(cond))) { \
@@ -182,6 +186,8 @@ long _evutil_weakrand(void);
abort(); \
} \
} while (0)
+#define EVUTIL_FAILURE_CHECK(cond) EVUTIL_UNLIKELY(cond)
+#endif
/* Internal addrinfo error code. This one is returned from only from
* evutil_getaddrinfo_common, when we are sure that we'll have to hit a DNS

0 comments on commit 743f866

Please sign in to comment.