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:14 UTC

[1/5] git commit: TS-302: Fix HTTPCacheAlt to use INK_MD5 directly instead of arrays of uin32_t. Simplify methods because of this.

Updated Branches:
  refs/heads/master 9b553698c -> 4e713d748


TS-302: Fix HTTPCacheAlt to use INK_MD5 directly instead of arrays of uin32_t. Simplify methods because of this.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/c40c601c
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/c40c601c
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/c40c601c

Branch: refs/heads/master
Commit: c40c601c9167c4937f972daf7825821e527a5f67
Parents: 0f1c78b
Author: Phil Sorber <so...@apache.org>
Authored: Fri Aug 16 13:41:16 2013 -0600
Committer: Phil Sorber <so...@apache.org>
Committed: Sat Aug 17 11:07:11 2013 -0600

----------------------------------------------------------------------
 proxy/hdrs/HTTP.cc | 17 +++--------------
 proxy/hdrs/HTTP.h  | 44 ++++++++------------------------------------
 2 files changed, 11 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c40c601c/proxy/hdrs/HTTP.cc
----------------------------------------------------------------------
diff --git a/proxy/hdrs/HTTP.cc b/proxy/hdrs/HTTP.cc
index 6ecaf35..18c6813 100644
--- a/proxy/hdrs/HTTP.cc
+++ b/proxy/hdrs/HTTP.cc
@@ -1693,18 +1693,11 @@ ClassAllocator<HTTPCacheAlt> httpCacheAltAllocator("httpCacheAltAllocator");
 HTTPCacheAlt::HTTPCacheAlt():
 m_magic(CACHE_ALT_MAGIC_ALIVE), m_writeable(1),
 m_unmarshal_len(-1),
-m_id(-1), m_rid(-1), m_request_hdr(),
+m_id(-1), m_rid(-1), m_object_key(), m_object_size(0), m_request_hdr(),
 m_response_hdr(), m_request_sent_time(0), m_response_received_time(0),
 m_frag_offset_count(0), m_frag_offsets(0),
 m_ext_buffer(NULL)
 {
-
-  m_object_key[0] = 0;
-  m_object_key[1] = 0;
-  m_object_key[2] = 0;
-  m_object_key[3] = 0;
-  m_object_size[0] = 0;
-  m_object_size[1] = 0;
 }
 
 void
@@ -1733,12 +1726,8 @@ HTTPCacheAlt::copy(HTTPCacheAlt *to_copy)
   m_unmarshal_len = to_copy->m_unmarshal_len;
   m_id = to_copy->m_id;
   m_rid = to_copy->m_rid;
-  m_object_key[0] = to_copy->m_object_key[0];
-  m_object_key[1] = to_copy->m_object_key[1];
-  m_object_key[2] = to_copy->m_object_key[2];
-  m_object_key[3] = to_copy->m_object_key[3];
-  m_object_size[0] = to_copy->m_object_size[0];
-  m_object_size[1] = to_copy->m_object_size[1];
+  m_object_key = to_copy->m_object_key;
+  m_object_size = to_copy->m_object_size;
 
   if (to_copy->m_request_hdr.valid()) {
     m_request_hdr.copy(&to_copy->m_request_hdr);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c40c601c/proxy/hdrs/HTTP.h
----------------------------------------------------------------------
diff --git a/proxy/hdrs/HTTP.h b/proxy/hdrs/HTTP.h
index 45a59bf..91b684d 100644
--- a/proxy/hdrs/HTTP.h
+++ b/proxy/hdrs/HTTP.h
@@ -1307,8 +1307,8 @@ struct HTTPCacheAlt
   int32_t m_id;
   int32_t m_rid;
 
-  int32_t m_object_key[4];
-  int32_t m_object_size[2];
+  INK_MD5 m_object_key;
+  int64_t m_object_size;
 
   HTTPHdr m_request_hdr;
   HTTPHdr m_response_hdr;
@@ -1447,65 +1447,37 @@ HTTPInfo::operator =(const HTTPInfo & m)
 inline INK_MD5
 HTTPInfo::object_key_get()
 {
-  INK_MD5 val;
-  int32_t* pi = reinterpret_cast<int32_t*>(&val);
-
-  pi[0] = m_alt->m_object_key[0];
-  pi[1] = m_alt->m_object_key[1];
-  pi[2] = m_alt->m_object_key[2];
-  pi[3] = m_alt->m_object_key[3];
-
-  return val;
+  return m_alt->m_object_key;
 }
 
 inline void
 HTTPInfo::object_key_get(INK_MD5 *md5)
 {
-  int32_t* pi = reinterpret_cast<int32_t*>(md5);
-  pi[0] = m_alt->m_object_key[0];
-  pi[1] = m_alt->m_object_key[1];
-  pi[2] = m_alt->m_object_key[2];
-  pi[3] = m_alt->m_object_key[3];
+  *md5 = m_alt->m_object_key;
 }
 
 inline bool
 HTTPInfo::compare_object_key(const INK_MD5 *md5)
 {
-  int32_t const* pi = reinterpret_cast<int32_t const*>(md5);
-  return ((m_alt->m_object_key[0] == pi[0]) &&
-          (m_alt->m_object_key[1] == pi[1]) &&
-          (m_alt->m_object_key[2] == pi[2]) &&
-          (m_alt->m_object_key[3] == pi[3])
-         );
+  return m_alt->m_object_key == *md5;
 }
 
 inline int64_t
 HTTPInfo::object_size_get()
 {
-  int64_t val;
-  int32_t* pi = reinterpret_cast<int32_t*>(&val);
-
-  pi[0] = m_alt->m_object_size[0];
-  pi[1] = m_alt->m_object_size[1];
-  return val;
+  return m_alt->m_object_size;
 }
 
 inline void
 HTTPInfo::object_key_set(INK_MD5 & md5)
 {
-  int32_t* pi = reinterpret_cast<int32_t*>(&md5);
-  m_alt->m_object_key[0] = pi[0];
-  m_alt->m_object_key[1] = pi[1];
-  m_alt->m_object_key[2] = pi[2];
-  m_alt->m_object_key[3] = pi[3];
+  m_alt->m_object_key = md5;
 }
 
 inline void
 HTTPInfo::object_size_set(int64_t size)
 {
-  int32_t* pi = reinterpret_cast<int32_t*>(&size);
-  m_alt->m_object_size[0] = pi[0];
-  m_alt->m_object_size[1] = pi[1];
+  m_alt->m_object_size = size;
 }
 
 inline HTTPInfo::FragOffset*


[4/5] git commit: TS-302: Switch to using Alias32 type so we aren't breaking strict aliasing.

Posted by so...@apache.org.
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);


[2/5] git commit: TS-302: Fix INK_MD5 to not break strict aliasing. Additional refactoring.

Posted by so...@apache.org.
TS-302: Fix INK_MD5 to not break strict aliasing. Additional refactoring.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/0f1c78b9
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/0f1c78b9
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/0f1c78b9

Branch: refs/heads/master
Commit: 0f1c78b9e6a32234924c7eafb61d5adab2a988b3
Parents: 9b55369
Author: Phil Sorber <so...@apache.org>
Authored: Fri Aug 16 13:39:14 2013 -0600
Committer: Phil Sorber <so...@apache.org>
Committed: Sat Aug 17 11:07:11 2013 -0600

----------------------------------------------------------------------
 lib/ts/INK_MD5.h | 78 ++++++++++++++++++++++++---------------------------
 1 file changed, 37 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0f1c78b9/lib/ts/INK_MD5.h
----------------------------------------------------------------------
diff --git a/lib/ts/INK_MD5.h b/lib/ts/INK_MD5.h
index fe26f6a..b046fa6 100644
--- a/lib/ts/INK_MD5.h
+++ b/lib/ts/INK_MD5.h
@@ -29,37 +29,41 @@
 
 struct INK_MD5
 {
-  uint64_t b[2];
+
+  // This union is needed to fix strict-aliasing warnings.
+  // It is anonymous so that the 'b' member can remain in
+  // the top level scope of the struct. This is because
+  // other code touches that directly. Once that code is
+  // also fixed we can make this an Alias64 type from
+  // ink_align.h
+  union
+  {
+    uint64_t b[2];   // Legacy placeholder
+    uint64_t u64[2];
+    uint32_t u32[4];
+    uint8_t  u8[16];
+  };
+
   const INK_MD5 & operator =(const INK_MD5 & md5)
   {
-    b[0] = md5.b[0];
-    b[1] = md5.b[1];
+    u64[0] = md5.u64[0];
+    u64[1] = md5.u64[1];
     return md5;
   }
   uint32_t word(int i)
   {
-    uint32_t *p = (uint32_t *) & b[0];
-    return p[i];
+    return u32[i];
   }
   unsigned char byte(int i)
   {
-    unsigned char *p = (unsigned char *) &b[0];
-    return p[i];
+    return u8[i];
   }
   INK_MD5 & loadFromBuffer(char *md5_buf) {
-    int i;
-    char *s, *d;
-
-    for (i = 0, s = md5_buf, d = (char *) (&(b[0])); i < 8; i++, *d++ = *s++);
-    for (i = 0, d = (char *) (&(b[1])); i < 8; i++, *d++ = *s++);
+    memcpy((void *) u8, (void *) md5_buf, 16);
     return (*this);
   }
   INK_MD5 & storeToBuffer(char *md5_buf) {
-    int i;
-    char *s, *d;
-
-    for (i = 0, d = md5_buf, s = (char *) (&(b[0])); i < 8; i++, *d++ = *s++);
-    for (i = 0, s = (char *) (&(b[1])); i < 8; i++, *d++ = *s++);
+    memcpy((void *) md5_buf, (void *) u8, 16);
     return (*this);
   }
   INK_MD5 & operator =(char *md5) {
@@ -71,18 +75,11 @@ struct INK_MD5
 
   char *toStr(char *md5_str)
   {
-    int i;
-    char *s, *d;
-
-    for (i = 0, d = md5_str, s = (char *) (&(b[0])); i < 8; i++, *d++ = *s++);
-    for (i = 0, s = (char *) (&(b[1])); i < 8; i++, *d++ = *s++);
-    return (md5_str);
+    return (char *) memcpy((void *) md5_str, (void *) u8, 16);
   }
   void encodeBuffer(unsigned char *buffer, int len)
   {
-    unsigned char md5[16];
-    ink_code_md5(buffer, len, md5);
-    *this = md5;
+    ink_code_md5(buffer, len, u8);
   }
   void encodeBuffer(const char *buffer, int len)
   {
@@ -90,7 +87,7 @@ struct INK_MD5
   }
   char *str()
   {
-    return ((char *) b);
+    return ((char *) u8);
   }
   char *toHexStr(char hex_md5[33])
   {
@@ -98,11 +95,11 @@ struct INK_MD5
   }
   void set(INK_MD5 & md5)
   {
-    loadFromBuffer((char *) &md5);
+    loadFromBuffer((char *) md5.u8);
   }
   void set(INK_MD5 * md5)
   {
-    loadFromBuffer((char *) md5);
+    loadFromBuffer((char *) md5->u8);
   }
   void set(char *p)
   {
@@ -110,18 +107,17 @@ struct INK_MD5
   }
   void set(uint64_t a1, uint64_t a2)
   {
-    b[0] = a1;
-    b[1] = a2;
+    u64[0] = a1;
+    u64[1] = a2;
   }
   char *string(char buf[33])
   {
     char hex_digits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
     int i, j;
-    unsigned char *u = (unsigned char *) &b[0];
 
     for (i = 0, j = 0; i < 16; i += 1, j += 2) {
-      buf[j + 0] = hex_digits[u[i] >> 4];
-      buf[j + 1] = hex_digits[u[i] & 0xF];
+      buf[j + 0] = hex_digits[u8[i] >> 4];
+      buf[j + 1] = hex_digits[u8[i] & 0xF];
     }
     buf[32] = '\0';
     return buf;
@@ -129,24 +125,24 @@ struct INK_MD5
 
   uint64_t fold() const
   {
-    return (b[0] ^ b[1]);
+    return (u64[0] ^ u64[1]);
   }
 
   uint64_t operator[] (int i) const
   {
-    return b[i];
+    return u64[i];
   }
   bool operator==(INK_MD5 const& md5)
   {
-    return b[0] == md5.b[0] && b[1] == md5.b[1];
+    return u64[0] == md5.u64[0] && u64[1] == md5.u64[1];
   }
   INK_MD5() {
-    b[0] = 0;
-    b[1] = 0;
+    u64[0] = 0;
+    u64[1] = 0;
   }
   INK_MD5(uint64_t a1, uint64_t a2) {
-    b[0] = a1;
-    b[1] = a2;
+    u64[0] = a1;
+    u64[1] = a2;
   }
 };
 


[3/5] git commit: TS-302: Switch to using Alias32 type so we aren't breaking strict aliasing. These instances should be converted to using inet_ntop or similar to make then v6 compliant.

Posted by so...@apache.org.
TS-302: Switch to using Alias32 type so we aren't breaking strict aliasing.
These instances should be converted to using inet_ntop or similar to make then
v6 compliant.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/45afd4ff
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/45afd4ff
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/45afd4ff

Branch: refs/heads/master
Commit: 45afd4ff5490fdc058c8376f8e36f0b349f80b89
Parents: c40c601
Author: Phil Sorber <so...@apache.org>
Authored: Sat Aug 17 12:12:01 2013 -0600
Committer: Phil Sorber <so...@apache.org>
Committed: Sat Aug 17 12:12:16 2013 -0600

----------------------------------------------------------------------
 iocore/cluster/ClusterHandlerBase.cc | 14 ++++++--------
 iocore/cluster/ClusterMachine.cc     |  7 +++----
 2 files changed, 9 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/45afd4ff/iocore/cluster/ClusterHandlerBase.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterHandlerBase.cc b/iocore/cluster/ClusterHandlerBase.cc
index 6647354..520e3a3 100644
--- a/iocore/cluster/ClusterHandlerBase.cc
+++ b/iocore/cluster/ClusterHandlerBase.cc
@@ -1453,13 +1453,12 @@ void
 ClusterHandler::dump_write_msg(int res)
 {
   // Debug support for inter cluster message trace
-  unsigned char x[4];
-  memset(x, 0, sizeof(x));
-  *(uint32_t *) & x = (uint32_t) ((struct sockaddr_in *)(net_vc->get_remote_addr()))->sin_addr.s_addr;
+  Alias32 x;
+  x.u32 = (uint32_t) ((struct sockaddr_in *)(net_vc->get_remote_addr()))->sin_addr.s_addr;
 
   fprintf(stderr,
           "[W] %hhu.%hhu.%hhu.%hhu SeqNo=%u, Cnt=%d, CntlCnt=%d Todo=%d, Res=%d\n",
-          x[0], x[1], x[2], x[3], write.sequence_number, write.msg.count, write.msg.control_bytes, write.to_do, res);
+          x.byte[0], x.byte[1], x.byte[2], x.byte[3], write.sequence_number, write.msg.count, write.msg.control_bytes, write.to_do, res);
   for (int i = 0; i < write.msg.count; ++i) {
     fprintf(stderr, "   d[%i] Type=%d, Chan=%d, SeqNo=%d, Len=%u\n",
             i, (write.msg.descriptor[i].type ? 1 : 0),
@@ -1472,12 +1471,11 @@ void
 ClusterHandler::dump_read_msg()
 {
   // Debug support for inter cluster message trace
-  unsigned char x[4];
-  memset(x, 0, sizeof(x));
-  *(uint32_t *) & x = (uint32_t) ((struct sockaddr_in *)(net_vc->get_remote_addr()))->sin_addr.s_addr;
+  Alias32 x;
+  x.u32 = (uint32_t) ((struct sockaddr_in *)(net_vc->get_remote_addr()))->sin_addr.s_addr;
 
   fprintf(stderr, "[R] %hhu.%hhu.%hhu.%hhu  SeqNo=%u, Cnt=%d, CntlCnt=%d\n",
-          x[0], x[1], x[2], x[3], read.sequence_number, read.msg.count, read.msg.control_bytes);
+          x.byte[0], x.byte[1], x.byte[2], x.byte[3], read.sequence_number, read.msg.count, read.msg.control_bytes);
   for (int i = 0; i < read.msg.count; ++i) {
     fprintf(stderr, "   d[%i] Type=%d, Chan=%d, SeqNo=%d, Len=%u\n",
             i, (read.msg.descriptor[i].type ? 1 : 0),

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/45afd4ff/iocore/cluster/ClusterMachine.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterMachine.cc b/iocore/cluster/ClusterMachine.cc
index afc4c11..00e99e6 100644
--- a/iocore/cluster/ClusterMachine.cc
+++ b/iocore/cluster/ClusterMachine.cc
@@ -132,10 +132,9 @@ ClusterMachine::ClusterMachine(char *ahostname, unsigned int aip, int aport)
     struct hostent *r = ink_gethostbyaddr_r((char *) &ip, sizeof(int), AF_INET, &data);
 
     if (r == NULL) {
-      unsigned char x[4];
-      memset(x, 0, sizeof(x));
-      *(uint32_t *) & x = (uint32_t) ip;
-      Debug("machine_debug", "unable to reverse DNS %u.%u.%u.%u: %d", x[0], x[1], x[2], x[3], data.herrno);
+      Alias32 x;
+      memcpy(&x.u32, &ip, sizeof(x.u32));
+      Debug("machine_debug", "unable to reverse DNS %u.%u.%u.%u: %d", x.byte[0], x.byte[1], x.byte[2], x.byte[3], data.herrno);
     } else
       hostname = ats_strdup(r->h_name);
   }


[5/5] git commit: TS-302: More cleanups to fix non strict aliasing.

Posted by so...@apache.org.
TS-302: More cleanups to fix non strict aliasing.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/4e713d74
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/4e713d74
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/4e713d74

Branch: refs/heads/master
Commit: 4e713d74899929fb3bdef03abe08b29265565152
Parents: 69fe3ee
Author: Phil Sorber <so...@apache.org>
Authored: Sat Aug 17 13:54:15 2013 -0600
Committer: Phil Sorber <so...@apache.org>
Committed: Sat Aug 17 13:54:15 2013 -0600

----------------------------------------------------------------------
 lib/ts/test_freelist.cc | 2 +-
 proxy/StatSystem.cc     | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4e713d74/lib/ts/test_freelist.cc
----------------------------------------------------------------------
diff --git a/lib/ts/test_freelist.cc b/lib/ts/test_freelist.cc
index 12ebefa..677da63 100644
--- a/lib/ts/test_freelist.cc
+++ b/lib/ts/test_freelist.cc
@@ -37,7 +37,7 @@ test(void *d)
   int id;
   void *m1, *m2, *m3;
 
-  id = *((int *) &d);
+  id = (intptr_t) d;
 
   time_t start = time(NULL);
   int count = 0;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4e713d74/proxy/StatSystem.cc
----------------------------------------------------------------------
diff --git a/proxy/StatSystem.cc b/proxy/StatSystem.cc
index ed33cc7..bdde869 100644
--- a/proxy/StatSystem.cc
+++ b/proxy/StatSystem.cc
@@ -607,7 +607,7 @@ dyn_stats_fsum_cb(void *data, void *res)
   ink_statval_t count, sum;
   READ_DYN_STAT((long) data, count, sum);
   (void)count;
-  *(float *) res = *(double *) &sum;
+  *(float *) res = (double) sum;
   return res;
 }
 
@@ -619,7 +619,7 @@ dyn_stats_favg_cb(void *data, void *res)
   if (count == 0) {
     *(float *) res = 0.0;
   } else {
-    *(float *) res = *(double *) &sum / *(double *) &count;
+    *(float *) res = (double) sum / (double) count;
   }
   return res;
 }
@@ -730,7 +730,7 @@ http_trans_stats_fsum_cb(void *data, void *res)
   ink_statval_t count, sum;
   READ_HTTP_TRANS_STAT((long) data, count, sum);
   (void)count;
-  *(float *) res = *(double *) &sum;
+  *(float *) res = (double) sum;
   return res;
 }
 
@@ -742,7 +742,7 @@ http_trans_stats_favg_cb(void *data, void *res)
   if (count == 0) {
     *(float *) res = 0.0;
   } else {
-    *(float *) res = *(double *) &sum / *(double *) &count;
+    *(float *) res = (double) sum / (double) count;
   }
   return res;
 }