mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-09 20:41:27 -04:00
Add a new EVUTIL_UPCAST macro so that I do not need to keep figuring out the right offsetof magic over and over.
svn:r1160
This commit is contained in:
parent
bbd6a332e1
commit
0b47b125cf
@ -39,6 +39,7 @@
|
|||||||
#include "defer-internal.h"
|
#include "defer-internal.h"
|
||||||
#include "bufferevent-internal.h"
|
#include "bufferevent-internal.h"
|
||||||
#include "mm-internal.h"
|
#include "mm-internal.h"
|
||||||
|
#include "util-internal.h"
|
||||||
|
|
||||||
struct bufferevent_pair {
|
struct bufferevent_pair {
|
||||||
struct bufferevent bev;
|
struct bufferevent bev;
|
||||||
@ -56,8 +57,7 @@ upcast(struct bufferevent *bev)
|
|||||||
struct bufferevent_pair *bev_p;
|
struct bufferevent_pair *bev_p;
|
||||||
if (bev->be_ops != &bufferevent_ops_pair)
|
if (bev->be_ops != &bufferevent_ops_pair)
|
||||||
return NULL;
|
return NULL;
|
||||||
bev_p = (void*)( ((char*)bev) -
|
bev_p = EVUTIL_UPCAST(bev, struct bufferevent_pair, bev);
|
||||||
evutil_offsetof(struct bufferevent_pair, bev) );
|
|
||||||
assert(bev_p->bev.be_ops == &bufferevent_ops_pair);
|
assert(bev_p->bev.be_ops == &bufferevent_ops_pair);
|
||||||
return bev_p;
|
return bev_p;
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,9 @@ extern const char EVUTIL_TOLOWER_TABLE[];
|
|||||||
#define EVUTIL_TOLOWER(c) (EVUTIL_TOLOWER_TABLE[(ev_uint8_t)c])
|
#define EVUTIL_TOLOWER(c) (EVUTIL_TOLOWER_TABLE[(ev_uint8_t)c])
|
||||||
#define EVUTIL_TOUPPER(c) (EVUTIL_TOUPPER_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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user