Skip to content

Commit

Permalink
Add a new EVUTIL_UPCAST macro so that I do not need to keep figuring …
Browse files Browse the repository at this point in the history
…out the right offsetof magic over and over.

svn:r1160
  • Loading branch information
nmathewson committed Apr 12, 2009
1 parent bbd6a33 commit 0b47b12
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bufferevent_pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "defer-internal.h"
#include "bufferevent-internal.h"
#include "mm-internal.h"
#include "util-internal.h"

struct bufferevent_pair {
struct bufferevent bev;
Expand All @@ -56,8 +57,7 @@ upcast(struct bufferevent *bev)
struct bufferevent_pair *bev_p;
if (bev->be_ops != &bufferevent_ops_pair)
return NULL;
bev_p = (void*)( ((char*)bev) -
evutil_offsetof(struct bufferevent_pair, bev) );
bev_p = EVUTIL_UPCAST(bev, struct bufferevent_pair, bev);
assert(bev_p->bev.be_ops == &bufferevent_ops_pair);
return bev_p;
}
Expand Down
3 changes: 3 additions & 0 deletions util-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ extern const char EVUTIL_TOLOWER_TABLE[];
#define EVUTIL_TOLOWER(c) (EVUTIL_TOLOWER_TABLE[(ev_uint8_t)c])
#define EVUTIL_TOUPPER(c) (EVUTIL_TOUPPER_TABLE[(ev_uint8_t)c])

#define EVUTIL_UPCAST(ptr, type, field) \
((type *)((char*)ptr) - evutil_offsetof(type, field))

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 0b47b12

Please sign in to comment.