You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by so...@apache.org on 2013/08/17 21:59:17 UTC
[4/5] git commit: TS-302: Switch to using Alias32 type so we aren't
breaking strict aliasing.
TS-302: Switch to using Alias32 type so we aren't breaking strict aliasing.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/69fe3eed
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/69fe3eed
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/69fe3eed
Branch: refs/heads/master
Commit: 69fe3eed5c0c74616217db23335495df786387f2
Parents: 45afd4f
Author: Phil Sorber <so...@apache.org>
Authored: Sat Aug 17 13:51:58 2013 -0600
Committer: Phil Sorber <so...@apache.org>
Committed: Sat Aug 17 13:51:58 2013 -0600
----------------------------------------------------------------------
iocore/cluster/ClusterCache.cc | 20 ++++++-------
iocore/cluster/P_ClusterCacheInternal.h | 42 ++++++++++------------------
2 files changed, 25 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/69fe3eed/iocore/cluster/ClusterCache.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterCache.cc b/iocore/cluster/ClusterCache.cc
index ae3d1b6..8d4b6e5 100644
--- a/iocore/cluster/ClusterCache.cc
+++ b/iocore/cluster/ClusterCache.cc
@@ -1146,7 +1146,7 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
char *hostname = NULL;
int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
if (host_len) {
- hostname = (char *) msg->moi;
+ hostname = (char *) msg->moi.byte;
}
Cache *call_cache = caches[c->frag_type];
c->cache_action = call_cache->open_read(c, &key, c->frag_type, hostname, host_len);
@@ -1286,7 +1286,7 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
char *hostname = NULL;
int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
if (host_len) {
- hostname = (char *) msg->moi;
+ hostname = (char *) msg->moi.byte;
}
Cache *call_cache = caches[c->frag_type];
@@ -1386,7 +1386,7 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
char *hostname = NULL;
int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
if (host_len) {
- hostname = (char *) msg->moi;
+ hostname = (char *) msg->moi.byte;
}
Cache *call_cache = caches[c->frag_type];
@@ -1415,7 +1415,7 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
char *hostname = NULL;
int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
if (host_len) {
- hostname = (char *) msg->moi;
+ hostname = (char *) msg->moi.byte;
}
Cache *call_cache = caches[c->frag_type];
@@ -1441,7 +1441,7 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
char *hostname = NULL;
int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
if (host_len) {
- hostname = (char *) msg->moi;
+ hostname = (char *) msg->moi.byte;
}
Cache *call_cache = caches[c->frag_type];
@@ -1764,7 +1764,7 @@ CacheContinuation::replyOpEvent(int event, VConnection * cvc)
write_cluster_vc->remote_closed = 1; // avoid remote close msg
write_cluster_vc->do_io(VIO::CLOSE);
}
- *((int32_t *) reply->moi) = (int32_t) ((uintptr_t) cvc & 0xffffffff); // code describing failure
+ reply->moi.u32 = (int32_t) ((uintptr_t) cvc & 0xffffffff); // code describing failure
}
// Make reply message the current message
msg = reply;
@@ -2027,7 +2027,7 @@ cache_op_result_ClusterFunction(ClusterHandler *ch, void *d, int l)
{
// Unmarshal the error code
ink_assert(((len - flen) == sizeof(int32_t)));
- op_result_error = *(int32_t *) msg->moi;
+ op_result_error = msg->moi.u32;
if (mh->NeedByteSwap())
ats_swap32((uint32_t *) & op_result_error);
op_result_error = -op_result_error;
@@ -2599,7 +2599,7 @@ CacheContinuation::do_remote_lookup(Continuation * cont, CacheKey * key,
data = (char *) msg;
len = mlen;
if (hostname && hostname_len) {
- memcpy(msg->moi, hostname, hostname_len);
+ memcpy(msg->moi.byte, hostname, hostname_len);
}
} else {
//////////////////////////////////////////////////////////////
@@ -2667,7 +2667,7 @@ cache_lookup_ClusterFunction(ClusterHandler *ch, void *data, int len)
char *hostname;
int hostname_len = len - op_to_sizeof_fixedlen_msg(CACHE_LOOKUP_OP);
- hostname = (hostname_len ? (char *) msg->moi : 0);
+ hostname = (hostname_len ? (char *) msg->moi.byte : 0);
// Note: Hostname data invalid after return from lookup
Cache *call_cache = caches[msg->frag_type];
@@ -3109,7 +3109,7 @@ CacheContinuation::tunnelEvent(int event, VConnection * vc)
*reply = *msg;
// Marshal response data into reply message
- res = ci->marshal((char *) reply->moi, len);
+ res = ci->marshal((char *) reply->moi.byte, len);
ink_assert(res > 0);
// Make reply message the current message
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/69fe3eed/iocore/cluster/P_ClusterCacheInternal.h
----------------------------------------------------------------------
diff --git a/iocore/cluster/P_ClusterCacheInternal.h b/iocore/cluster/P_ClusterCacheInternal.h
index 4bc8c12..8b62d44 100644
--- a/iocore/cluster/P_ClusterCacheInternal.h
+++ b/iocore/cluster/P_ClusterCacheInternal.h
@@ -398,7 +398,7 @@ struct CacheLookupMsg:public ClusterMessageHeader
INK_MD5 url_md5;
uint32_t seq_number;
uint32_t frag_type;
- uint8_t moi[4];
+ Alias32 moi;
enum
{
MIN_VERSION = 1,
@@ -407,7 +407,7 @@ struct CacheLookupMsg:public ClusterMessageHeader
};
CacheLookupMsg(uint16_t vers = CACHE_LOOKUP_MESSAGE_VERSION):
ClusterMessageHeader(vers), seq_number(0), frag_type(0) {
- memset(moi, 0, sizeof(moi));
+ moi.u32 = 0;
}
//////////////////////////////////////////////////////////////////////////
@@ -418,10 +418,7 @@ struct CacheLookupMsg:public ClusterMessageHeader
}
static int sizeof_fixedlen_msg()
{
- CacheLookupMsg *p = 0;
-
- // Maybe use offsetoff here instead. /leif
- return (int) ALIGN_DOUBLE(&p->moi[0]);
+ return (int) ALIGN_DOUBLE(offsetof(CacheLookupMsg, moi));
}
void init(uint16_t vers = CACHE_LOOKUP_MESSAGE_VERSION) {
_init(vers);
@@ -449,7 +446,7 @@ struct CacheOpMsg_long:public ClusterMessageHeader
int32_t channel; // used by open interfaces
ClusterVCToken token;
int32_t buffer_size; // used by open read interface
- uint8_t moi[4];
+ Alias32 moi;
enum
{
MIN_VERSION = 1,
@@ -459,7 +456,7 @@ struct CacheOpMsg_long:public ClusterMessageHeader
CacheOpMsg_long(uint16_t vers = CACHE_OP_LONG_MESSAGE_VERSION):
ClusterMessageHeader(vers),
opcode(0), frag_type(0), cfl_flags(0), seq_number(0), nbytes(0), data(0), channel(0), buffer_size(0) {
- memset(moi, 0, sizeof(moi));
+ moi.u32 = 0;
}
//////////////////////////////////////////////////////////////////////////
@@ -470,10 +467,7 @@ struct CacheOpMsg_long:public ClusterMessageHeader
}
static int sizeof_fixedlen_msg()
{
- CacheOpMsg_long *p = 0;
-
- // Change to offsetof maybe? /leif
- return (int) ALIGN_DOUBLE(&p->moi[0]);
+ return (int) ALIGN_DOUBLE(offsetof(CacheOpMsg_long, moi));
}
void init(uint16_t vers = CACHE_OP_LONG_MESSAGE_VERSION) {
_init(vers);
@@ -509,7 +503,7 @@ struct CacheOpMsg_short:public ClusterMessageHeader
int32_t buffer_size; // used by open read interface
// Variable portion of message
- uint8_t moi[4];
+ Alias32 moi;
enum
{
MIN_VERSION = 1,
@@ -519,7 +513,7 @@ struct CacheOpMsg_short:public ClusterMessageHeader
CacheOpMsg_short(uint16_t vers = CACHE_OP_SHORT_MESSAGE_VERSION):
ClusterMessageHeader(vers),
opcode(0), frag_type(0), cfl_flags(0), seq_number(0), nbytes(0), data(0), channel(0), buffer_size(0) {
- memset(moi, 0, sizeof(moi));
+ moi.u32 = 0;
}
//////////////////////////////////////////////////////////////////////////
@@ -530,9 +524,7 @@ struct CacheOpMsg_short:public ClusterMessageHeader
}
static int sizeof_fixedlen_msg()
{
- CacheOpMsg_short *p = 0;
- // Use offsetof. /leif
- return (int) ALIGN_DOUBLE(&p->moi[0]);
+ return (int) ALIGN_DOUBLE(offsetof(CacheOpMsg_short, moi));
}
void init(uint16_t vers = CACHE_OP_SHORT_MESSAGE_VERSION) {
_init(vers);
@@ -563,7 +555,7 @@ struct CacheOpMsg_short_2:public ClusterMessageHeader
INK_MD5 md5_1;
INK_MD5 md5_2;
uint32_t seq_number;
- uint8_t moi[4];
+ Alias32 moi;
enum
{
MIN_VERSION = 1,
@@ -572,7 +564,7 @@ struct CacheOpMsg_short_2:public ClusterMessageHeader
};
CacheOpMsg_short_2(uint16_t vers = CACHE_OP_SHORT_2_MESSAGE_VERSION)
: ClusterMessageHeader(vers), opcode(0), frag_type(0), cfl_flags(0), seq_number(0) {
- memset(moi, 0, sizeof(moi));
+ moi.u32 = 0;
}
//////////////////////////////////////////////////////////////////////////
static int protoToVersion(int protoMajor)
@@ -582,9 +574,7 @@ struct CacheOpMsg_short_2:public ClusterMessageHeader
}
static int sizeof_fixedlen_msg()
{
- CacheOpMsg_short_2 *p = 0;
- // Use offsetof already. /leif
- return (int) ALIGN_DOUBLE(&p->moi[0]);
+ return (int) ALIGN_DOUBLE(offsetof(CacheOpMsg_short_2, moi));
}
void init(uint16_t vers = CACHE_OP_SHORT_2_MESSAGE_VERSION) {
_init(vers);
@@ -607,7 +597,7 @@ struct CacheOpReplyMsg:public ClusterMessageHeader
int32_t result;
ClusterVCToken token;
bool is_ram_cache_hit; // Entire object was from ram cache
- uint8_t moi[4]; // Used by CACHE_OPEN_READ & CACHE_LINK reply
+ Alias32 moi; // Used by CACHE_OPEN_READ & CACHE_LINK reply
enum
{
MIN_VERSION = 1,
@@ -616,7 +606,7 @@ struct CacheOpReplyMsg:public ClusterMessageHeader
};
CacheOpReplyMsg(uint16_t vers = CACHE_OP_REPLY_MESSAGE_VERSION)
: ClusterMessageHeader(vers), seq_number(0), result(0), is_ram_cache_hit(false) {
- memset(moi, 0, sizeof(moi));
+ moi.u32 = 0;
}
//////////////////////////////////////////////////////////////////////////
@@ -627,9 +617,7 @@ struct CacheOpReplyMsg:public ClusterMessageHeader
}
static int sizeof_fixedlen_msg()
{
- CacheOpReplyMsg *p = 0;
- // Use offsetof. /leif
- return (int) ALIGN_DOUBLE(&p->moi[0]);
+ return (int) ALIGN_DOUBLE(offsetof(CacheOpReplyMsg, moi));
}
void init(uint16_t vers = CACHE_OP_REPLY_MESSAGE_VERSION) {
_init(vers);