You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2022/12/30 13:20:38 UTC

[arrow-adbc] branch main updated: fix(c/driver/postgresql): define ntohll etc for macOS 10.9 (#305)

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

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 5855964  fix(c/driver/postgresql): define ntohll etc for macOS 10.9 (#305)
5855964 is described below

commit 5855964a53ae4d27a94f419a7061faa8feca5f2c
Author: David Li <li...@gmail.com>
AuthorDate: Fri Dec 30 08:20:34 2022 -0500

    fix(c/driver/postgresql): define ntohll etc for macOS 10.9 (#305)
    
    Fixes #304.
---
 c/driver/postgresql/util.h | 18 +++++++++++++-----
 ci/scripts/glib_test.sh    | 11 ++++++++++-
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/c/driver/postgresql/util.h b/c/driver/postgresql/util.h
index 69a48c4..fb12aec 100644
--- a/c/driver/postgresql/util.h
+++ b/c/driver/postgresql/util.h
@@ -29,6 +29,8 @@
 
 #if defined(__linux__)
 #include <endian.h>
+#elif defined(__APPLE__)
+#include <libkern/OSByteOrder.h>
 #endif
 
 #include "adbc.h"
@@ -38,9 +40,15 @@ namespace adbcpq {
 #define CONCAT(x, y) x##y
 #define MAKE_NAME(x, y) CONCAT(x, y)
 
-#if defined(__linux__)
-static inline uint64_t ntohll(uint64_t x) { return be64toh(x); }
-static inline uint64_t htonll(uint64_t x) { return htobe64(x); }
+#if defined(_WIN32)
+static inline uint64_t SwapNetworkToHost(uint64_t x) { return ntohll(x); }
+static inline uint64_t SwapHostToNetwork(uint64_t x) { return htonll(x); }
+#elif defined(__APPLE__)
+static inline uint64_t SwapNetworkToHost(uint64_t x) { return OSSwapBigToHostInt64(x); }
+static inline uint64_t SwapHostToNetwork(uint64_t x) { return OSSwapHostToBigInt64(x); }
+#else
+static inline uint64_t SwapNetworkToHost(uint64_t x) { return be64toh(x); }
+static inline uint64_t SwapHostToNetwork(uint64_t x) { return htobe64(x); }
 #endif
 
 // see arrow/util/string_builder.h
@@ -127,7 +135,7 @@ static inline uint32_t LoadNetworkUInt32(const char* buf) {
 static inline int64_t LoadNetworkUInt64(const char* buf) {
   uint64_t v = 0;
   std::memcpy(&v, buf, sizeof(uint64_t));
-  return ntohll(v);
+  return SwapNetworkToHost(v);
 }
 
 static inline int32_t LoadNetworkInt32(const char* buf) {
@@ -139,7 +147,7 @@ static inline int64_t LoadNetworkInt64(const char* buf) {
 }
 
 static inline uint64_t ToNetworkInt64(int64_t v) {
-  return htonll(static_cast<uint64_t>(v));
+  return SwapHostToNetwork(static_cast<uint64_t>(v));
 }
 
 }  // namespace adbcpq
diff --git a/ci/scripts/glib_test.sh b/ci/scripts/glib_test.sh
index 31022d6..c009fe3 100755
--- a/ci/scripts/glib_test.sh
+++ b/ci/scripts/glib_test.sh
@@ -36,6 +36,7 @@ test_subproject() {
     fi
 
     pushd "${source_dir}/glib"
+    echo "Testing GLib"
 
     if [[ "$(uname)" = "Darwin" ]]; then
         bundle config build.red-arrow -- \
@@ -51,6 +52,7 @@ test_subproject() {
 
     export GI_TYPELIB_PATH="${install_dir}/lib/girepository-1.0:${GI_TYPELIB_PATH}"
     pushd "${source_dir}/ruby"
+    echo "Testing Ruby"
 
     if [[ "$(uname)" = "Darwin" ]]; then
         bundle config build.red-arrow -- \
@@ -63,7 +65,14 @@ test_subproject() {
            env DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}" \
            ruby test/run.rb
     bundle exec rake build
-    gem install --install-dir "${build_dir}/gems" pkg/*.gem
+
+    echo "Testing Gem"
+    local gem_flags=""
+    if [[ "$(uname)" = "Darwin" ]]; then
+        gem_flags='-- --with-cflags="-D_LIBCPP_DISABLE_AVAILABILITY" --with-cppflags="-D_LIBCPP_DISABLE_AVAILABILITY"'
+    fi
+
+    gem install --install-dir "${build_dir}/gems" pkg/*.gem -- ${gem_flags}
     popd
 }