This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new e6d7d13  THRIFT-5215: Remove portable_endian.h Client: cpp Patch: 
James Lacey
e6d7d13 is described below

commit e6d7d13c35f5c9fe57889d7e77b0ba63910b1052
Author: James Lacey <[email protected]>
AuthorDate: Fri May 22 08:46:26 2020 -0700

    THRIFT-5215: Remove portable_endian.h
    Client: cpp
    Patch: James Lacey
    
    This closes #2152
---
 LICENSE                                         |  15 ---
 lib/cpp/Makefile.am                             |   3 +-
 lib/cpp/src/thrift/portable_endian.h            | 131 ------------------------
 lib/cpp/src/thrift/transport/TWebSocketServer.h |  15 ++-
 4 files changed, 8 insertions(+), 156 deletions(-)

diff --git a/LICENSE b/LICENSE
index 7bf24c9..a66fb61 100644
--- a/LICENSE
+++ b/LICENSE
@@ -238,18 +238,3 @@ For the lib/nodejs/lib/thrift/json_parse.js:
 (By Douglas Crockford <[email protected]>)
 
 --------------------------------------------------
-For lib/cpp/src/thrift/portable_endian.h
-
-// endian.h
-//
-// https://gist.github.com/panzi/6856583
-//
-// I, Mathias Panzenböck, place this file hereby into the public domain. Use
-// it at your own risk for whatever you like. In case there are
-// jurisdictions that don't support putting things in the public domain you
-// can also consider it to be "dual licensed" under the BSD, MIT and Apache
-// licenses, if you want to. This code is trivial anyway. Consider it an
-// example on how to get the endian conversion functions on different
-// platforms.
-
---------------------------------------------------
diff --git a/lib/cpp/Makefile.am b/lib/cpp/Makefile.am
index bcc6a09..c73a17d 100755
--- a/lib/cpp/Makefile.am
+++ b/lib/cpp/Makefile.am
@@ -141,8 +141,7 @@ include_thrift_HEADERS = \
                          src/thrift/TApplicationException.h \
                          src/thrift/TLogging.h \
                          src/thrift/TToString.h \
-                         src/thrift/TBase.h \
-                         src/thrift/portable_endian.h
+                         src/thrift/TBase.h
 
 include_concurrencydir = $(include_thriftdir)/concurrency
 include_concurrency_HEADERS = \
diff --git a/lib/cpp/src/thrift/portable_endian.h 
b/lib/cpp/src/thrift/portable_endian.h
deleted file mode 100644
index e07010e..0000000
--- a/lib/cpp/src/thrift/portable_endian.h
+++ /dev/null
@@ -1,131 +0,0 @@
-//
-// endian.h
-//
-// https://gist.github.com/panzi/6856583
-//
-// I, Mathias Panzenböck, place this file hereby into the public domain. Use
-// it at your own risk for whatever you like. In case there are
-// jurisdictions that don't support putting things in the public domain you
-// can also consider it to be "dual licensed" under the BSD, MIT and Apache
-// licenses, if you want to. This code is trivial anyway. Consider it an
-// example on how to get the endian conversion functions on different
-// platforms.
-
-#ifndef PORTABLE_ENDIAN_H__
-#define PORTABLE_ENDIAN_H__
-
-#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && 
!defined(__WINDOWS__)
-
-#      define __WINDOWS__
-
-#endif
-
-#if defined(__linux__) || defined(__CYGWIN__)
-
-#      include <endian.h>
-
-#elif defined(__APPLE__)
-
-#      include <libkern/OSByteOrder.h>
-
-#      define htobe16(x) OSSwapHostToBigInt16(x)
-#      define htole16(x) OSSwapHostToLittleInt16(x)
-#      define be16toh(x) OSSwapBigToHostInt16(x)
-#      define le16toh(x) OSSwapLittleToHostInt16(x)
-
-#      define htobe32(x) OSSwapHostToBigInt32(x)
-#      define htole32(x) OSSwapHostToLittleInt32(x)
-#      define be32toh(x) OSSwapBigToHostInt32(x)
-#      define le32toh(x) OSSwapLittleToHostInt32(x)
-
-#      define htobe64(x) OSSwapHostToBigInt64(x)
-#      define htole64(x) OSSwapHostToLittleInt64(x)
-#      define be64toh(x) OSSwapBigToHostInt64(x)
-#      define le64toh(x) OSSwapLittleToHostInt64(x)
-
-#      define __BYTE_ORDER    BYTE_ORDER
-#      define __BIG_ENDIAN    BIG_ENDIAN
-#      define __LITTLE_ENDIAN LITTLE_ENDIAN
-#      define __PDP_ENDIAN    PDP_ENDIAN
-
-#elif defined(__OpenBSD__)
-
-#      include <sys/endian.h>
-
-#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
-
-#      include <sys/endian.h>
-
-#      define be16toh(x) betoh16(x)
-#      define le16toh(x) letoh16(x)
-
-#      define be32toh(x) betoh32(x)
-#      define le32toh(x) letoh32(x)
-
-#      define be64toh(x) betoh64(x)
-#      define le64toh(x) letoh64(x)
-
-#elif defined(__WINDOWS__)
-
-#      include <winsock2.h>
-
-#      if BYTE_ORDER == LITTLE_ENDIAN
-
-#              define htobe16(x) htons(x)
-#              define htole16(x) (x)
-#              define be16toh(x) ntohs(x)
-#              define le16toh(x) (x)
-
-#              define htobe32(x) htonl(x)
-#              define htole32(x) (x)
-#              define be32toh(x) ntohl(x)
-#              define le32toh(x) (x)
-
-#      if defined(__MINGW32__)
-#              define htobe64(x) __builtin_bswap64(x)
-#              define htole64(x) (x)
-#              define be64toh(x) __builtin_bswap64(x)
-#              define le64toh(x) (x)
-#      else
-#              define htobe64(x) htonll(x)
-#              define htole64(x) (x)
-#              define be64toh(x) ntohll(x)
-#              define le64toh(x) (x)
-#      endif
-
-#      elif BYTE_ORDER == BIG_ENDIAN
-
-               /* that would be xbox 360 */
-#              define htobe16(x) (x)
-#              define htole16(x) __builtin_bswap16(x)
-#              define be16toh(x) (x)
-#              define le16toh(x) __builtin_bswap16(x)
-
-#              define htobe32(x) (x)
-#              define htole32(x) __builtin_bswap32(x)
-#              define be32toh(x) (x)
-#              define le32toh(x) __builtin_bswap32(x)
-
-#              define htobe64(x) (x)
-#              define htole64(x) __builtin_bswap64(x)
-#              define be64toh(x) (x)
-#              define le64toh(x) __builtin_bswap64(x)
-
-#      else
-
-#              error byte order not supported
-
-#      endif
-
-#      define __BYTE_ORDER    BYTE_ORDER
-#      define __BIG_ENDIAN    BIG_ENDIAN
-#      define __LITTLE_ENDIAN LITTLE_ENDIAN
-#      define __PDP_ENDIAN    PDP_ENDIAN
-
-#else
-
-#      error platform not supported
-
-#endif
-
-#endif
diff --git a/lib/cpp/src/thrift/transport/TWebSocketServer.h 
b/lib/cpp/src/thrift/transport/TWebSocketServer.h
index 8edc286..2e94c83 100644
--- a/lib/cpp/src/thrift/transport/TWebSocketServer.h
+++ b/lib/cpp/src/thrift/transport/TWebSocketServer.h
@@ -20,8 +20,6 @@
 #ifndef _THRIFT_TRANSPORT_TWEBSOCKETSERVER_H_
 #define _THRIFT_TRANSPORT_TWEBSOCKETSERVER_H_ 1
 
-#include <thrift/portable_endian.h>
-
 #include <cstdlib>
 #include <iostream>
 #include <sstream>
@@ -29,6 +27,7 @@
 #include <openssl/sha.h>
 
 #include <thrift/config.h>
+#include <thrift/protocol/TProtocol.h>
 #include <thrift/transport/TSocket.h>
 #include <thrift/transport/THttpServer.h>
 #if defined(_MSC_VER) || defined(__MINGW32__)
@@ -200,7 +199,7 @@ private:
 
   void failConnection(CloseCode reason) {
     writeFrameHeader(Opcode::Close);
-    auto buffer = htobe16(static_cast<uint16_t>(reason));
+    auto buffer = htons(static_cast<uint16_t>(reason));
     transport_->write(reinterpret_cast<const uint8_t*>(&buffer), 2);
     transport_->flush();
     transport_->close();
@@ -255,13 +254,13 @@ private:
       if (read < 2) {
         return false;
       }
-      payloadLength = be16toh(*reinterpret_cast<uint16_t*>(headerBuffer));
+      payloadLength = ntohs(*reinterpret_cast<uint16_t*>(headerBuffer));
     } else if (payloadLength == 127) {
       read = transport_->read(headerBuffer, 8);
       if (read < 8) {
         return false;
       }
-      payloadLength = be64toh(*reinterpret_cast<uint64_t*>(headerBuffer));
+      payloadLength = 
THRIFT_ntohll(*reinterpret_cast<uint64_t*>(headerBuffer));
       if ((payloadLength & 0x8000000000000000) != 0) {
         failConnection(CloseCode::ProtocolError);
         throw TTransportException(
@@ -307,7 +306,7 @@ private:
       if (length >= 2) {
         uint8_t buffer[2];
         readBuffer_.read(buffer, 2);
-        CloseCode closeCode = 
static_cast<CloseCode>(be16toh(*reinterpret_cast<uint16_t*>(buffer)));
+        CloseCode closeCode = 
static_cast<CloseCode>(ntohs(*reinterpret_cast<uint16_t*>(buffer)));
         THRIFT_UNUSED_VARIABLE(closeCode);
         string closeReason = readBuffer_.readAsString(length - 2);
         T_DEBUG("Connection closed: %d %s", closeCode, closeReason);
@@ -359,10 +358,10 @@ private:
       header[1] = static_cast<uint8_t>(length);
     } else if (length < 65536) {
       header[1] = 126;
-      *reinterpret_cast<uint16_t*>(header + 2) = htobe16(length);
+      *reinterpret_cast<uint16_t*>(header + 2) = htons(length);
     } else {
       header[1] = 127;
-      *reinterpret_cast<uint64_t*>(header + 2) = htobe64(length);
+      *reinterpret_cast<uint64_t*>(header + 2) = THRIFT_htonll(length);
     }
 
     transport_->write(header, headerSize);

Reply via email to