From 05e6d527b13f271c760df1d82b42f918007f567a Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 27 Jul 2012 22:11:13 +0900 Subject: [PATCH] Fix compile error on netbsd Include config.h from sources under examples. Added kevent.udata type check. --- configure.ac | 21 +++++++++++++++++++++ examples/EventPoll.h | 4 +--- examples/EventPollEvent.h | 2 ++ examples/EventPoll_epoll.h | 2 ++ examples/EventPoll_kqueue.cc | 14 ++++++++++---- examples/EventPoll_kqueue.h | 2 ++ examples/HtmlParser.h | 4 +--- examples/Makefile.am | 2 +- examples/SpdyServer.h | 2 ++ examples/shrpx_spdy_upstream.cc | 11 ++++------- examples/spdy.h | 11 +++++++++-- examples/spdycat.cc | 4 +--- examples/spdylay_config.h | 32 ++++++++++++++++++++++++++++++++ examples/spdylay_ssl.h | 2 ++ examples/uri.h | 2 ++ examples/util.h | 2 ++ lib/spdylay_session.c | 4 ++-- tests/Makefile.am | 2 +- 18 files changed, 97 insertions(+), 26 deletions(-) create mode 100644 examples/spdylay_config.h diff --git a/configure.ac b/configure.ac index 0f37adde..a9509a1a 100644 --- a/configure.ac +++ b/configure.ac @@ -59,6 +59,10 @@ AM_CONDITIONAL([HAVE_STDCXX_11], # Checks for libraries. +# Search for dlsym function, which is used in tests. Linux needs -ldl, +# but netbsd does not need it. +AC_SEARCH_LIBS([dlsym], [dl]) + # zlib PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.3]) LIBS="$ZLIB_LIBS $LIBS" @@ -163,6 +167,23 @@ AM_CONDITIONAL([HAVE_EPOLL], [ test "x${have_epoll}" = "xyes" ]) AC_CHECK_FUNCS([kqueue], [have_kqueue=yes]) AM_CONDITIONAL([HAVE_KQUEUE], [test "x${have_kqueue}" = "xyes"]) +AC_MSG_CHECKING([whether struct kevent.udata is intptr_t]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +#include +]], +[[ +struct kevent event; +event.udata = (intptr_t*)(&event); +]])], +[kevent_udata_intptr_t=yes], [kevent_udata_intptr_t=no]) +AC_MSG_RESULT([$kevent_udata_intptr_t]) +if test "x$kevent_udata_intptr_t" = "xyes"; then + AC_DEFINE([KEVENT_UDATA_INTPTR_T], [1], + [Define to 1 if struct kevent.udata is intptr_t]) +fi + if test "x$maintainer_mode" != "xno"; then CFLAGS="$CFLAGS -Wall -Wextra -Werror" CFLAGS="$CFLAGS -Wmissing-prototypes -Wstrict-prototypes" diff --git a/examples/EventPoll.h b/examples/EventPoll.h index 7f1e5cba..17be1595 100644 --- a/examples/EventPoll.h +++ b/examples/EventPoll.h @@ -25,9 +25,7 @@ #ifndef EVENT_POLL_H #define EVENT_POLL_H -#ifdef HAVE_CONFIG_H -# include -#endif // HAVE_CONFIG_H +#include "spdylay_config.h" #ifdef HAVE_EPOLL # include "EventPoll_epoll.h" diff --git a/examples/EventPollEvent.h b/examples/EventPollEvent.h index 9c2ec4e2..d5e0d72b 100644 --- a/examples/EventPollEvent.h +++ b/examples/EventPollEvent.h @@ -25,6 +25,8 @@ #ifndef EVENT_POLL_EVENT_H #define EVENT_POLL_EVENT_H +#include "spdylay_config.h" + namespace spdylay { enum EventPollEvent { diff --git a/examples/EventPoll_epoll.h b/examples/EventPoll_epoll.h index b17ec90b..9205cf0d 100644 --- a/examples/EventPoll_epoll.h +++ b/examples/EventPoll_epoll.h @@ -25,6 +25,8 @@ #ifndef EVENT_POLL_EPOLL_H #define EVENT_POLL_EPOLL_H +#include "spdylay_config.h" + #include #include diff --git a/examples/EventPoll_kqueue.cc b/examples/EventPoll_kqueue.cc index e95d73f9..64c20b2d 100644 --- a/examples/EventPoll_kqueue.cc +++ b/examples/EventPoll_kqueue.cc @@ -29,6 +29,12 @@ #include #include +#ifdef KEVENT_UDATA_INTPTR_T +# define PTR_TO_UDATA(X) (reinterpret_cast(X)) +#else // !KEVENT_UDATA_INTPTR_T +# define PTR_TO_UDATA(X) (X) +#endif // !KEVENT_UDATA_INTPTR_T + namespace spdylay { EventPoll::EventPoll(size_t max_events) @@ -46,7 +52,7 @@ EventPoll::~EventPoll() } delete [] evlist_; } - + int EventPoll::poll(int timeout) { timespec ts, *ts_ptr; @@ -74,7 +80,7 @@ int EventPoll::get_num_events() void* EventPoll::get_user_data(size_t p) { - return evlist_[p].udata; + return reinterpret_cast(evlist_[p].udata); } int EventPoll::get_events(size_t p) @@ -96,10 +102,10 @@ int update_event(int kq, int fd, int events, void *user_data) struct kevent changelist[2]; EV_SET(&changelist[0], fd, EVFILT_READ, EV_ADD | ((events & EP_POLLIN) ? EV_ENABLE : EV_DISABLE), - 0, 0, user_data); + 0, 0, PTR_TO_UDATA(user_data)); EV_SET(&changelist[1], fd, EVFILT_WRITE, EV_ADD | ((events & EP_POLLOUT) ? EV_ENABLE : EV_DISABLE), - 0, 0, user_data); + 0, 0, PTR_TO_UDATA(user_data)); timespec ts = { 0, 0 }; return kevent(kq, changelist, 2, changelist, 0, &ts); } diff --git a/examples/EventPoll_kqueue.h b/examples/EventPoll_kqueue.h index 15138b8f..8ef01c7c 100644 --- a/examples/EventPoll_kqueue.h +++ b/examples/EventPoll_kqueue.h @@ -25,6 +25,8 @@ #ifndef EVENT_POLL_KQUEUE_H #define EVENT_POLL_KQUEUE_H +#include "spdylay_config.h" + #include #include diff --git a/examples/HtmlParser.h b/examples/HtmlParser.h index 1366d89e..79275bc9 100644 --- a/examples/HtmlParser.h +++ b/examples/HtmlParser.h @@ -25,9 +25,7 @@ #ifndef HTML_PARSER_H #define HTML_PARSER_H -#ifdef HAVE_CONFIG_H -# include -#endif // HAVE_CONFIG_H +#include "spdylay_config.h" #include #include diff --git a/examples/Makefile.am b/examples/Makefile.am index 2e0a4fa9..c2019c32 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -36,7 +36,7 @@ bin_PROGRAMS += shrpx endif # HAVE_LIBEVENT_OPENSSL HELPER_OBJECTS = uri.cc util.cc spdylay_ssl.cc -HELPER_HFILES = uri.h util.h spdylay_ssl.h +HELPER_HFILES = uri.h util.h spdylay_ssl.h spdylay_config.h EVENT_OBJECTS = EVENT_HFILES = EventPoll.h EventPollEvent.h diff --git a/examples/SpdyServer.h b/examples/SpdyServer.h index aaf262d1..2c188616 100644 --- a/examples/SpdyServer.h +++ b/examples/SpdyServer.h @@ -25,6 +25,8 @@ #ifndef SPDY_SERVER_H #define SPDY_SERVER_H +#include "spdylay_config.h" + #include #include diff --git a/examples/shrpx_spdy_upstream.cc b/examples/shrpx_spdy_upstream.cc index 617d70aa..181e5b8f 100644 --- a/examples/shrpx_spdy_upstream.cc +++ b/examples/shrpx_spdy_upstream.cc @@ -569,9 +569,8 @@ int SpdyUpstream::rst_stream(Downstream *downstream, int status_code) LOG(FATAL) << "spdylay_submit_rst_stream() failed: " << spdylay_strerror(rv); DIE(); - } else { - return 0; } + return 0; } int SpdyUpstream::window_update(Downstream *downstream) @@ -584,9 +583,8 @@ int SpdyUpstream::window_update(Downstream *downstream) LOG(FATAL) << "spdylay_submit_window_update() failed: " << spdylay_strerror(rv); DIE(); - } else { - return 0; } + return 0; } namespace { @@ -626,7 +624,7 @@ int SpdyUpstream::error_reply(Downstream *downstream, int status_code) return -1; } downstream->set_response_state(Downstream::MSG_COMPLETE); - + spdylay_data_provider data_prd; data_prd.source.ptr = downstream; data_prd.read_callback = spdy_data_read_callback; @@ -645,9 +643,8 @@ int SpdyUpstream::error_reply(Downstream *downstream, int status_code) LOG(FATAL) << "spdylay_submit_response() failed: " << spdylay_strerror(rv); DIE(); - } else { - return 0; } + return 0; } bufferevent_data_cb SpdyUpstream::get_downstream_readcb() diff --git a/examples/spdy.h b/examples/spdy.h index 0853c848..d2f921d9 100644 --- a/examples/spdy.h +++ b/examples/spdy.h @@ -22,6 +22,11 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#ifndef SPDY_H +#define SPDY_H + +#include "spdylay_config.h" + #include #include @@ -172,7 +177,7 @@ void on_request_recv_callback hd->submit_response(response_obj.get_status_string(), stream_id, response_obj.get_headers(), &data_prd); } - + class spdy { public: spdy() : server_(0) {} @@ -197,7 +202,7 @@ public: server_ = new SpdyServer(&config_); return server_->listen() == 0; } - + int run() { return server_->run(); @@ -232,3 +237,5 @@ int run(Server& server) } // namespace reactor } // namespace spdylay + +#endif // SPDY_H diff --git a/examples/spdycat.cc b/examples/spdycat.cc index 4a9b97cd..8fb3b491 100644 --- a/examples/spdycat.cc +++ b/examples/spdycat.cc @@ -22,9 +22,7 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifdef HAVE_CONFIG_H -# include -#endif // HAVE_CONFIG_H +#include "spdylay_config.h" #include #include diff --git a/examples/spdylay_config.h b/examples/spdylay_config.h new file mode 100644 index 00000000..3eba3e5d --- /dev/null +++ b/examples/spdylay_config.h @@ -0,0 +1,32 @@ +/* + * Spdylay - SPDY Library + * + * Copyright (c) 2012 Tatsuhiro Tsujikawa + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef SPDYLAY_CONFIG_H +#define SPDYLAY_CONFIG_H + +#ifdef HAVE_CONFIG_H +# include +#endif // HAVE_CONFIG_H + +#endif // SPDYLAY_CONFIG_H diff --git a/examples/spdylay_ssl.h b/examples/spdylay_ssl.h index 03e3f5ad..18add5ab 100644 --- a/examples/spdylay_ssl.h +++ b/examples/spdylay_ssl.h @@ -25,6 +25,8 @@ #ifndef SPDYLAY_SSL_H #define SPDYLAY_SSL_H +#include "spdylay_config.h" + #include #include #include diff --git a/examples/uri.h b/examples/uri.h index fc0baf1e..249e4acf 100644 --- a/examples/uri.h +++ b/examples/uri.h @@ -25,6 +25,8 @@ #ifndef URI_H #define URI_H +#include "spdylay_config.h" + #include #include diff --git a/examples/util.h b/examples/util.h index 8c208737..7ea9474d 100644 --- a/examples/util.h +++ b/examples/util.h @@ -25,6 +25,8 @@ #ifndef UTIL_H #define UTIL_H +#include "spdylay_config.h" + #include #include #include diff --git a/lib/spdylay_session.c b/lib/spdylay_session.c index 59932c31..2cd21eff 100644 --- a/lib/spdylay_session.c +++ b/lib/spdylay_session.c @@ -349,7 +349,7 @@ int spdylay_session_add_frame(spdylay_session *session, void *abs_frame, void *aux_data) { - int r; + int r = 0; spdylay_outbound_item *item; item = malloc(sizeof(spdylay_outbound_item)); if(item == NULL) { @@ -929,7 +929,7 @@ int spdylay_session_prep_credential(spdylay_session *session, static ssize_t spdylay_session_prep_frame(spdylay_session *session, spdylay_outbound_item *item) { - ssize_t framebuflen; + ssize_t framebuflen = 0; if(item->frame_cat == SPDYLAY_CTRL) { spdylay_frame *frame; spdylay_frame_type frame_type; diff --git a/tests/Makefile.am b/tests/Makefile.am index 32e36a61..71b23950 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -46,7 +46,7 @@ main_LDFLAGS = -static @CUNIT_LIBS@ failmalloc_SOURCES = failmalloc.c failmalloc_test.c failmalloc_test.h \ malloc_wrapper.c malloc_wrapper.h \ spdylay_test_helper.c spdylay_test_helper.h -failmalloc_LDADD = $(main_LDADD) -ldl +failmalloc_LDADD = $(main_LDADD) failmalloc_LDFLAGS = $(main_LDFLAGS) AM_CFLAGS = -Wall -I${top_srcdir}/lib -I${top_srcdir}/lib/includes -I${top_builddir}/lib/includes \