From b73ad7bc4504882f7b50ed72c2643653fdc43a61 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 21 Oct 2009 18:48:22 +0000 Subject: [PATCH] Treat the bitwise OR of two enum values as an int. This makes our interfaces usable from C++, which doesn't believe you can say "bufferevent_socket_nase(base, -1, BEV_OPT_CLOSE_ON_FREE|BEV_OPT_DEFER_CALLBACKS)" but which instead would demand "static_cast(BEV_OPT_CLOSE_ON_FREE| BEV_OPT_DEFER_CALLBACKS))" for the last argument. Diagnosis and patch from Chris Davis. svn:r1456 --- ChangeLog | 1 + bufferevent_filter.c | 4 ++-- bufferevent_openssl.c | 8 ++++---- bufferevent_pair.c | 6 +++--- bufferevent_sock.c | 2 +- event.c | 7 +++---- include/event2/bufferevent.h | 6 +++--- include/event2/bufferevent_ssl.h | 4 ++-- include/event2/event.h | 8 +++----- 9 files changed, 22 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 944818e7..6ad1a1d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -31,6 +31,7 @@ Changes in 2.0.3-alpha: o Make the event_base_loop() family of functions respect thread-safety better. This should clear up a few hard-to-debug race conditions. o Fix a bug when using a specialized memory allocator on win32. o Have the win32 select() backend label TCP-socket-connected events as EV_WRITE, not EV_READ. This should bring it in line with the other backends, and improve portability. Patch from Christopher Davis. + o Stop using enums as arguments or return values when what we mean is a bitfield of enum values. C++ doesn't believe that you can OR two enum values together and get another enum, and C++ takes its typing seriously. Patch from Christopher Davis. Changes in 2.0.2-alpha: diff --git a/bufferevent_filter.c b/bufferevent_filter.c index 9e5bb345..33966d05 100644 --- a/bufferevent_filter.c +++ b/bufferevent_filter.c @@ -165,12 +165,12 @@ struct bufferevent * bufferevent_filter_new(struct bufferevent *underlying, bufferevent_filter_cb input_filter, bufferevent_filter_cb output_filter, - enum bufferevent_options options, + int options, void (*free_context)(void *), void *ctx) { struct bufferevent_filtered *bufev_f; - enum bufferevent_options tmp_options = options & ~BEV_OPT_THREADSAFE; + int tmp_options = options & ~BEV_OPT_THREADSAFE; if (!input_filter) input_filter = be_null_filter; diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c index dd6f973a..6a32a41a 100644 --- a/bufferevent_openssl.c +++ b/bufferevent_openssl.c @@ -1047,11 +1047,11 @@ bufferevent_openssl_new_impl(struct event_base *base, evutil_socket_t fd, SSL *ssl, enum bufferevent_ssl_state state, - enum bufferevent_options options) + int options) { struct bufferevent_openssl *bev_ssl = NULL; struct bufferevent_private *bev_p = NULL; - enum bufferevent_options tmp_options = options & ~BEV_OPT_THREADSAFE; + int tmp_options = options & ~BEV_OPT_THREADSAFE; if (underlying != NULL && fd >= 0) return NULL; /* Only one can be set. */ @@ -1123,7 +1123,7 @@ bufferevent_openssl_filter_new(struct event_base *base, struct bufferevent *underlying, SSL *ssl, enum bufferevent_ssl_state state, - enum bufferevent_options options) + int options) { int close_flag = options & BEV_OPT_CLOSE_ON_FREE; BIO *bio; @@ -1143,7 +1143,7 @@ bufferevent_openssl_socket_new(struct event_base *base, evutil_socket_t fd, SSL *ssl, enum bufferevent_ssl_state state, - enum bufferevent_options options) + int options) { /* Does the SSL already have an fd? */ BIO *bio = SSL_get_wbio(ssl); diff --git a/bufferevent_pair.c b/bufferevent_pair.c index c0d62eda..1081975a 100644 --- a/bufferevent_pair.c +++ b/bufferevent_pair.c @@ -92,7 +92,7 @@ static void be_pair_outbuf_cb(struct evbuffer *, static struct bufferevent_pair * bufferevent_pair_elt_new(struct event_base *base, - enum bufferevent_options options) + int options) { struct bufferevent_pair *bufev; if (! (bufev = mm_calloc(1, sizeof(struct bufferevent_pair)))) @@ -113,11 +113,11 @@ bufferevent_pair_elt_new(struct event_base *base, } int -bufferevent_pair_new(struct event_base *base, enum bufferevent_options options, +bufferevent_pair_new(struct event_base *base, int options, struct bufferevent *pair[2]) { struct bufferevent_pair *bufev1 = NULL, *bufev2 = NULL; - enum bufferevent_options tmp_options; + int tmp_options; options |= BEV_OPT_DEFER_CALLBACKS; tmp_options = options & ~BEV_OPT_THREADSAFE; diff --git a/bufferevent_sock.c b/bufferevent_sock.c index 5ffed2fc..2f591bd2 100644 --- a/bufferevent_sock.c +++ b/bufferevent_sock.c @@ -261,7 +261,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg) struct bufferevent * bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, - enum bufferevent_options options) + int options) { struct bufferevent_private *bufev_p; struct bufferevent *bufev; diff --git a/event.c b/event.c index df0d2669..a6128121 100644 --- a/event.c +++ b/event.c @@ -230,7 +230,7 @@ event_is_method_disabled(const char *name) return (getenv(environment) != NULL); } -enum event_method_feature +int event_base_get_features(struct event_base *base) { return base->evsel->features; @@ -533,8 +533,7 @@ event_config_free(struct event_config *cfg) int -event_config_set_flag(struct event_config *cfg, - enum event_base_config_flag flag) +event_config_set_flag(struct event_config *cfg, int flag) { if (!cfg) return -1; @@ -561,7 +560,7 @@ event_config_avoid_method(struct event_config *cfg, const char *method) int event_config_require_features(struct event_config *cfg, - enum event_method_feature features) + int features) { if (!cfg) return (-1); diff --git a/include/event2/bufferevent.h b/include/event2/bufferevent.h index f8eae402..dd311853 100644 --- a/include/event2/bufferevent.h +++ b/include/event2/bufferevent.h @@ -141,7 +141,7 @@ enum bufferevent_options { error occurred @see bufferevent_free() */ -struct bufferevent *bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, enum bufferevent_options options); +struct bufferevent *bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, int options); /** Launch a connect() attempt with a socket. When the connect succeeds, @@ -451,7 +451,7 @@ struct bufferevent * bufferevent_filter_new(struct bufferevent *underlying, bufferevent_filter_cb input_filter, bufferevent_filter_cb output_filter, - enum bufferevent_options options, + int options, void (*free_context)(void *), void *ctx); @@ -466,7 +466,7 @@ bufferevent_filter_new(struct bufferevent *underlying, @return 0 on success, -1 on failure. */ int -bufferevent_pair_new(struct event_base *base, enum bufferevent_options options, +bufferevent_pair_new(struct event_base *base, int options, struct bufferevent *pair[2]); #ifdef __cplusplus diff --git a/include/event2/bufferevent_ssl.h b/include/event2/bufferevent_ssl.h index 0f5e5898..1ae4f611 100644 --- a/include/event2/bufferevent_ssl.h +++ b/include/event2/bufferevent_ssl.h @@ -53,14 +53,14 @@ bufferevent_openssl_filter_new(struct event_base *base, struct bufferevent *underlying, struct ssl_st *ssl, enum bufferevent_ssl_state state, - enum bufferevent_options options); + int options); struct bufferevent * bufferevent_openssl_socket_new(struct event_base *base, evutil_socket_t fd, struct ssl_st *ssl, enum bufferevent_ssl_state state, - enum bufferevent_options options); + int options); struct ssl_st * bufferevent_openssl_get_ssl(struct bufferevent *bufev); diff --git a/include/event2/event.h b/include/event2/event.h index 8fe1ba56..1a96260d 100644 --- a/include/event2/event.h +++ b/include/event2/event.h @@ -171,7 +171,7 @@ enum event_base_config_flag { /** Return a bitmask of the features implemented by an event base. */ -enum event_method_feature event_base_get_features(struct event_base *base); +int event_base_get_features(struct event_base *base); /** Enters a required event method feature that the application demands. @@ -194,13 +194,11 @@ enum event_method_feature event_base_get_features(struct event_base *base); Replaces values from previous calls to this function. @return 0 on success, -1 on failure. */ -int event_config_require_features(struct event_config *cfg, - enum event_method_feature feature); +int event_config_require_features(struct event_config *cfg, int feature); /** Sets a flag to configure what parts of the eventual event_base will * be initialized, and how they'll work. */ -int event_config_set_flag(struct event_config *cfg, - enum event_base_config_flag flag); +int event_config_set_flag(struct event_config *cfg, int flag); /** Initialize the event API.