]> granicus.if.org Git - libevent/commitdiff
Use BEV_UPCASE() everywhere
authorAzat Khuzhin <a3at.mail@gmail.com>
Fri, 30 Nov 2018 19:25:41 +0000 (22:25 +0300)
committerAzat Khuzhin <azat@libevent.org>
Sat, 2 Feb 2019 12:18:04 +0000 (15:18 +0300)
Done with coccinelle and manual line rewrap:
  $ cat > BEV_UPCAST.cocci
  @@
  expression field_;
  expression var;
  @@

  - EVUTIL_UPCAST(var, struct bufferevent_private, field_)
  + BEV_UPCAST(var)

  $ spatch --sp-file BEV_UPCASE.cocci --in-place bufferevent*.c > /dev/null

(cherry picked from commit 7bcf576b396b22f218074c446691526a3ce509a6)

bufferevent.c
bufferevent_ratelim.c
bufferevent_sock.c

index 89ad6e2b01563e13edf7c916ea9bedc58a1316aa..f7f97bcf896c49c96e1882baa696abfd97208334 100644 (file)
@@ -66,8 +66,7 @@ static void bufferevent_finalize_cb_(struct event_callback *evcb, void *arg_);
 void
 bufferevent_suspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what)
 {
-       struct bufferevent_private *bufev_private =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
        BEV_LOCK(bufev);
        if (!bufev_private->read_suspended)
                bufev->be_ops->disable(bufev, EV_READ);
@@ -78,8 +77,7 @@ bufferevent_suspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags w
 void
 bufferevent_unsuspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what)
 {
-       struct bufferevent_private *bufev_private =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
        BEV_LOCK(bufev);
        bufev_private->read_suspended &= ~what;
        if (!bufev_private->read_suspended && (bufev->enabled & EV_READ))
@@ -90,8 +88,7 @@ bufferevent_unsuspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags
 void
 bufferevent_suspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what)
 {
-       struct bufferevent_private *bufev_private =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
        BEV_LOCK(bufev);
        if (!bufev_private->write_suspended)
                bufev->be_ops->disable(bufev, EV_WRITE);
@@ -102,8 +99,7 @@ bufferevent_suspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags
 void
 bufferevent_unsuspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what)
 {
-       struct bufferevent_private *bufev_private =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
        BEV_LOCK(bufev);
        bufev_private->write_suspended &= ~what;
        if (!bufev_private->write_suspended && (bufev->enabled & EV_WRITE))
@@ -245,8 +241,7 @@ void
 bufferevent_run_readcb_(struct bufferevent *bufev, int options)
 {
        /* Requires that we hold the lock and a reference */
-       struct bufferevent_private *p =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *p = BEV_UPCAST(bufev);
        if (bufev->readcb == NULL)
                return;
        if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) {
@@ -262,8 +257,7 @@ void
 bufferevent_run_writecb_(struct bufferevent *bufev, int options)
 {
        /* Requires that we hold the lock and a reference */
-       struct bufferevent_private *p =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *p = BEV_UPCAST(bufev);
        if (bufev->writecb == NULL)
                return;
        if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) {
@@ -291,8 +285,7 @@ void
 bufferevent_run_eventcb_(struct bufferevent *bufev, short what, int options)
 {
        /* Requires that we hold the lock and a reference */
-       struct bufferevent_private *p =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *p = BEV_UPCAST(bufev);
        if (bufev->errorcb == NULL)
                return;
        if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) {
@@ -484,8 +477,7 @@ bufferevent_read_buffer(struct bufferevent *bufev, struct evbuffer *buf)
 int
 bufferevent_enable(struct bufferevent *bufev, short event)
 {
-       struct bufferevent_private *bufev_private =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
        short impl_events = event;
        int r = 0;
 
@@ -558,8 +550,7 @@ int
 bufferevent_disable_hard_(struct bufferevent *bufev, short event)
 {
        int r = 0;
-       struct bufferevent_private *bufev_private =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
 
        BEV_LOCK(bufev);
        bufev->enabled &= ~event;
@@ -595,8 +586,7 @@ void
 bufferevent_setwatermark(struct bufferevent *bufev, short events,
     size_t lowmark, size_t highmark)
 {
-       struct bufferevent_private *bufev_private =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
 
        BEV_LOCK(bufev);
        if (events & EV_WRITE) {
@@ -681,8 +671,7 @@ bufferevent_flush(struct bufferevent *bufev,
 void
 bufferevent_incref_and_lock_(struct bufferevent *bufev)
 {
-       struct bufferevent_private *bufev_private =
-           BEV_UPCAST(bufev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
        BEV_LOCK(bufev);
        ++bufev_private->refcnt;
 }
@@ -708,8 +697,7 @@ bufferevent_transfer_lock_ownership_(struct bufferevent *donor,
 int
 bufferevent_decref_and_unlock_(struct bufferevent *bufev)
 {
-       struct bufferevent_private *bufev_private =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
        int n_cbs = 0;
 #define MAX_CBS 16
        struct event_callback *cbs[MAX_CBS];
@@ -752,8 +740,7 @@ bufferevent_finalize_cb_(struct event_callback *evcb, void *arg_)
 {
        struct bufferevent *bufev = arg_;
        struct bufferevent *underlying;
-       struct bufferevent_private *bufev_private =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
 
        BEV_LOCK(bufev);
        underlying = bufferevent_get_underlying(bufev);
@@ -819,8 +806,7 @@ bufferevent_free(struct bufferevent *bufev)
 void
 bufferevent_incref(struct bufferevent *bufev)
 {
-       struct bufferevent_private *bufev_private =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_private = BEV_UPCAST(bufev);
 
        /* XXX: now that this function is public, we might want to
         * - return the count from this function
@@ -896,8 +882,7 @@ bufferevent_getfd(struct bufferevent *bev)
 enum bufferevent_options
 bufferevent_get_options_(struct bufferevent *bev)
 {
-       struct bufferevent_private *bev_p =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bev_p = BEV_UPCAST(bev);
        enum bufferevent_options options;
 
        BEV_LOCK(bev);
@@ -973,8 +958,7 @@ int
 bufferevent_generic_adj_timeouts_(struct bufferevent *bev)
 {
        const short enabled = bev->enabled;
-       struct bufferevent_private *bev_p =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bev_p = BEV_UPCAST(bev);
        int r1=0, r2=0;
        if ((enabled & EV_READ) && !bev_p->read_suspended &&
            evutil_timerisset(&bev->timeout_read))
index bde192021be14ad102011c0912ed0be8a695d04b..258749685353bd98da540ec6b2b970b67a26e645 100644 (file)
@@ -560,8 +560,7 @@ int
 bufferevent_set_rate_limit(struct bufferevent *bev,
     struct ev_token_bucket_cfg *cfg)
 {
-       struct bufferevent_private *bevp =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bevp = BEV_UPCAST(bev);
        int r = -1;
        struct bufferevent_rate_limit *rlim;
        struct timeval now;
@@ -737,8 +736,7 @@ bufferevent_add_to_rate_limit_group(struct bufferevent *bev,
     struct bufferevent_rate_limit_group *g)
 {
        int wsuspend, rsuspend;
-       struct bufferevent_private *bevp =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bevp = BEV_UPCAST(bev);
        BEV_LOCK(bev);
 
        if (!bevp->rate_limiting) {
@@ -789,8 +787,7 @@ int
 bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent *bev,
     int unsuspend)
 {
-       struct bufferevent_private *bevp =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bevp = BEV_UPCAST(bev);
        BEV_LOCK(bev);
        if (bevp->rate_limiting && bevp->rate_limiting->group) {
                struct bufferevent_rate_limit_group *g =
index c878aa95380b78cc05f370ebc3ce4a161777df6b..48d6c7e9590f5388099ecdf4a61476e01f498736 100644 (file)
@@ -99,17 +99,14 @@ const struct bufferevent_ops bufferevent_ops_socket = {
 const struct sockaddr*
 bufferevent_socket_get_conn_address_(struct bufferevent *bev)
 {
-       struct bufferevent_private *bev_p =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
-
+       struct bufferevent_private *bev_p = BEV_UPCAST(bev);
        return (struct sockaddr *)&bev_p->conn_address;
 }
 
 void
 bufferevent_socket_set_conn_address_fd_(struct bufferevent *bev, int fd)
 {
-       struct bufferevent_private *bev_p =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bev_p = BEV_UPCAST(bev);
 
        socklen_t len = sizeof(bev_p->conn_address);
 
@@ -122,8 +119,7 @@ void
 bufferevent_socket_set_conn_address_(struct bufferevent *bev,
        struct sockaddr *addr, size_t addrlen)
 {
-       struct bufferevent_private *bev_p =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bev_p = BEV_UPCAST(bev);
        EVUTIL_ASSERT(addrlen <= sizeof(bev_p->conn_address));
        memcpy(&bev_p->conn_address, addr, addrlen);
 }
@@ -134,8 +130,7 @@ bufferevent_socket_outbuf_cb(struct evbuffer *buf,
     void *arg)
 {
        struct bufferevent *bufev = arg;
-       struct bufferevent_private *bufev_p =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
 
        if (cbinfo->n_added &&
            (bufev->enabled & EV_WRITE) &&
@@ -153,8 +148,7 @@ static void
 bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
 {
        struct bufferevent *bufev = arg;
-       struct bufferevent_private *bufev_p =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
        struct evbuffer *input;
        int res = 0;
        short what = BEV_EVENT_READING;
@@ -235,8 +229,7 @@ static void
 bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
 {
        struct bufferevent *bufev = arg;
-       struct bufferevent_private *bufev_p =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
        int res = 0;
        short what = BEV_EVENT_WRITING;
        int connected = 0;
@@ -386,8 +379,7 @@ int
 bufferevent_socket_connect(struct bufferevent *bev,
     const struct sockaddr *sa, int socklen)
 {
-       struct bufferevent_private *bufev_p =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_p = BEV_UPCAST(bev);
 
        evutil_socket_t fd;
        int r = 0;
@@ -465,8 +457,7 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai,
     void *arg)
 {
        struct bufferevent *bev = arg;
-       struct bufferevent_private *bev_p =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bev_p = BEV_UPCAST(bev);
        int r;
        BEV_LOCK(bev);
 
@@ -504,8 +495,7 @@ bufferevent_socket_connect_hostname(struct bufferevent *bev,
 {
        char portbuf[10];
        struct evutil_addrinfo hint;
-       struct bufferevent_private *bev_p =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bev_p = BEV_UPCAST(bev);
 
        if (family != AF_INET && family != AF_INET6 && family != AF_UNSPEC)
                return -1;
@@ -537,8 +527,7 @@ int
 bufferevent_socket_get_dns_error(struct bufferevent *bev)
 {
        int rv;
-       struct bufferevent_private *bev_p =
-           EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
+       struct bufferevent_private *bev_p = BEV_UPCAST(bev);
 
        BEV_LOCK(bev);
        rv = bev_p->dns_error;
@@ -589,8 +578,7 @@ be_socket_enable(struct bufferevent *bufev, short event)
 static int
 be_socket_disable(struct bufferevent *bufev, short event)
 {
-       struct bufferevent_private *bufev_p =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
        if (event & EV_READ) {
                if (event_del(&bufev->ev_read) == -1)
                        return -1;
@@ -606,8 +594,7 @@ be_socket_disable(struct bufferevent *bufev, short event)
 static void
 be_socket_destruct(struct bufferevent *bufev)
 {
-       struct bufferevent_private *bufev_p =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
        evutil_socket_t fd;
        EVUTIL_ASSERT(BEV_IS_SOCKET(bufev));
 
@@ -630,8 +617,7 @@ be_socket_flush(struct bufferevent *bev, short iotype,
 static void
 be_socket_setfd(struct bufferevent *bufev, evutil_socket_t fd)
 {
-       struct bufferevent_private *bufev_p =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
 
        BEV_LOCK(bufev);
        EVUTIL_ASSERT(BEV_IS_SOCKET(bufev));
@@ -660,8 +646,7 @@ int
 bufferevent_priority_set(struct bufferevent *bufev, int priority)
 {
        int r = -1;
-       struct bufferevent_private *bufev_p =
-           EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
+       struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
 
        BEV_LOCK(bufev);
        if (!BEV_IS_SOCKET(bufev))