You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ga...@apache.org on 2022/04/29 16:55:20 UTC

[hadoop] branch trunk updated: HDFS-16468. Define ssize_t for Windows (#4228)

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

gaurava pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 88155cebe94 HDFS-16468. Define ssize_t for Windows (#4228)
88155cebe94 is described below

commit 88155cebe9461718c8d45ffacea29f15c8c4d966
Author: Gautham B A <ga...@gmail.com>
AuthorDate: Fri Apr 29 22:25:09 2022 +0530

    HDFS-16468. Define ssize_t for Windows (#4228)
    
    * Some C/C++ files use ssize_t data type.
      This isn't available for Windows and we
      need to define an alias for this and set it
      to an appropriate type to make it cross
      platform compatible.
---
 .../src/main/native/libhdfs-tests/CMakeLists.txt   |  1 +
 .../src/main/native/libhdfs/CMakeLists.txt         |  1 +
 .../src/main/native/libhdfs/jni_helper.c           |  1 +
 .../native/libhdfspp/examples/c/cat/CMakeLists.txt |  2 +-
 .../src/main/native/libhdfspp/examples/c/cat/cat.c |  1 +
 .../main/native/libhdfspp/examples/cc/cat/cat.cc   |  2 -
 .../src/main/native/libhdfspp/lib/fs/filehandle.cc |  1 +
 .../src/main/native/libhdfspp/lib/fs/filehandle.h  |  1 +
 .../libhdfspp/lib/x-platform/syscall_linux.cc      |  1 +
 .../main/native/libhdfspp/lib/x-platform/types.h   | 34 ++++++++++
 .../libhdfspp/tests/x-platform/CMakeLists.txt      |  5 ++
 .../libhdfspp/tests/x-platform/types_test.cc       | 22 ++++++
 .../native/libhdfspp/tests/x-platform/types_test.h | 78 ++++++++++++++++++++++
 .../main/native/libhdfspp/tools/tools_common.cc    |  2 -
 14 files changed, 147 insertions(+), 5 deletions(-)

diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/CMakeLists.txt b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/CMakeLists.txt
index f16cc9eb1b0..44bc87d17c6 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/CMakeLists.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/CMakeLists.txt
@@ -25,6 +25,7 @@ include_directories(
     ${CMAKE_CURRENT_SOURCE_DIR}/../libhdfs
     ${JNI_INCLUDE_DIRS}
     ${OS_DIR}
+    ../libhdfspp/lib
 )
 
 add_library(native_mini_dfs
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/CMakeLists.txt b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/CMakeLists.txt
index a7fb3111251..22d18708d6e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/CMakeLists.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/CMakeLists.txt
@@ -29,6 +29,7 @@ include_directories(
     main/native
     main/native/libhdfs
     ${OS_DIR}
+    ../libhdfspp/lib
 )
 
 hadoop_add_dual_library(hdfs
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c
index bbbc8b4602b..c834c74e4cd 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c
@@ -23,6 +23,7 @@
 #include "platform.h"
 #include "os/mutexes.h"
 #include "os/thread_local_storage.h"
+#include "x-platform/types.h"
 
 #include <errno.h>
 #include <dirent.h>
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/c/cat/CMakeLists.txt b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/c/cat/CMakeLists.txt
index 41a9ee87fde..d7dfb0a7443 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/c/cat/CMakeLists.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/c/cat/CMakeLists.txt
@@ -20,7 +20,7 @@
 #    it by add -DLIBHDFSPP_DIR=... to your cmake invocation
 set(LIBHDFSPP_DIR CACHE STRING ${CMAKE_INSTALL_PREFIX})
 
-include_directories( ${LIBHDFSPP_DIR}/include )
+include_directories( ${LIBHDFSPP_DIR}/include ../../lib )
 link_directories( ${LIBHDFSPP_DIR}/lib )
 
 add_executable(cat_c cat.c)
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/c/cat/cat.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/c/cat/cat.c
index bee5382c9ec..d0de0dc5fea 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/c/cat/cat.c
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/c/cat/cat.c
@@ -28,6 +28,7 @@
 #include "hdfspp/hdfs_ext.h"
 #include "uriparser2/uriparser2.h"
 #include "common/util_c.h"
+#include "x-platform/types.h"
 
 #define SCHEME "hdfs"
 #define BUF_SIZE 1048576 //1 MB
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/cc/cat/cat.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/cc/cat/cat.cc
index 9d400e7b00c..584af44924e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/cc/cat/cat.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/examples/cc/cat/cat.cc
@@ -62,7 +62,6 @@ int main(int argc, char *argv[]) {
   //wrapping file_raw into a unique pointer to guarantee deletion
   std::unique_ptr<hdfs::FileHandle> file(file_raw);
 
-  ssize_t total_bytes_read = 0;
   size_t last_bytes_read = 0;
 
   do{
@@ -71,7 +70,6 @@ int main(int argc, char *argv[]) {
     if(status.ok()) {
       //Writing file chunks to stdout
       fwrite(input_buffer, last_bytes_read, 1, stdout);
-      total_bytes_read += last_bytes_read;
     } else {
       if(status.is_invalid_offset()){
         //Reached the end of the file
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc
index 7c9e24c0d88..7cfd6df3b98 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc
@@ -22,6 +22,7 @@
 #include "connection/datanodeconnection.h"
 #include "reader/block_reader.h"
 #include "hdfspp/events.h"
+#include "x-platform/types.h"
 
 #include <future>
 #include <memory>
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.h
index 724b1a14bc2..0e4eed7af4e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.h
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.h
@@ -28,6 +28,7 @@
 
 #include "bad_datanode_tracker.h"
 #include "ClientNamenodeProtocol.pb.h"
+#include "x-platform/types.h"
 
 #include <memory>
 #include <mutex>
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_linux.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_linux.cc
index 15ec620c9ab..51907634bba 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_linux.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_linux.cc
@@ -24,6 +24,7 @@
 #include <vector>
 
 #include "syscall.h"
+#include "types.h"
 
 bool XPlatform::Syscall::WriteToStdout(const std::string& message) {
   return WriteToStdoutImpl(message.c_str());
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/types.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/types.h
new file mode 100644
index 00000000000..6df5b96f393
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/types.h
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NATIVE_LIBHDFSPP_LIB_CROSS_PLATFORM_TYPES
+#define NATIVE_LIBHDFSPP_LIB_CROSS_PLATFORM_TYPES
+
+#if _WIN64
+// Windows 64-bit.
+typedef long int ssize_t;
+#elif _WIN32
+// Windows 32-bit.
+typedef int ssize_t;
+#else
+// ssize_t is correctly defined by taking bit-ness into account on non-Windows
+// systems. So we just include the header file where ssize_t is defined.
+#include <sys/types.h>
+#endif
+
+#endif
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/CMakeLists.txt b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/CMakeLists.txt
index 6a7d0bec37e..e481ebc31e8 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/CMakeLists.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/CMakeLists.txt
@@ -31,3 +31,8 @@ add_test(x_platform_utils_test x_platform_utils_test)
 target_include_directories(x_platform_syscall_test PRIVATE ${LIBHDFSPP_LIB_DIR})
 target_link_libraries(x_platform_syscall_test gmock_main)
 add_test(x_platform_syscall_test x_platform_syscall_test)
+
+add_executable(x_platform_types_test types_test.cc)
+target_include_directories(x_platform_types_test PRIVATE ${LIBHDFSPP_LIB_DIR})
+target_link_libraries(x_platform_types_test gtest_main)
+add_test(x_platform_types_test x_platform_types_test)
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/types_test.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/types_test.cc
new file mode 100644
index 00000000000..b234fa2f107
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/types_test.cc
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "types_test.h"
+#include "x-platform/types.h"
+
+INSTANTIATE_TYPED_TEST_SUITE_P(SSizeTTest, XPlatformTypesTest, ssize_t);
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/types_test.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/types_test.h
new file mode 100644
index 00000000000..b24f6578806
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/types_test.h
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LIBHDFSPP_CROSS_PLATFORM_TYPES_TEST
+#define LIBHDFSPP_CROSS_PLATFORM_TYPES_TEST
+
+#include <limits>
+
+#include <gtest/gtest.h>
+
+/**
+ * {@class XPlatformTypesTest} tests the types defined in the XPlatform library.
+ */
+template <class T> class XPlatformTypesTest : public testing::Test {
+public:
+  XPlatformTypesTest() = default;
+  XPlatformTypesTest(const XPlatformTypesTest &) = delete;
+  XPlatformTypesTest(XPlatformTypesTest &&) = delete;
+  XPlatformTypesTest &operator=(const XPlatformTypesTest &) = delete;
+  XPlatformTypesTest &operator=(XPlatformTypesTest &&) = delete;
+  ~XPlatformTypesTest() override;
+};
+
+template <class T> XPlatformTypesTest<T>::~XPlatformTypesTest() = default;
+
+TYPED_TEST_SUITE_P(XPlatformTypesTest);
+
+/**
+ * Tests whether ssize_t can hold -1.
+ */
+TYPED_TEST_P(XPlatformTypesTest, SSizeTMinusOne) {
+  constexpr TypeParam value = -1;
+  ASSERT_EQ(value, -1);
+}
+
+/**
+ * Tests whether ssize_t can hold at least an int.
+ */
+TYPED_TEST_P(XPlatformTypesTest, SSizeTCanHoldInts) {
+  constexpr auto actual = std::numeric_limits<TypeParam>::max();
+  constexpr auto expected = std::numeric_limits<int>::max();
+  ASSERT_GE(actual, expected);
+}
+
+// For 64-bit systems.
+#if _WIN64 || __x86_64__ || __ppc64__
+/**
+ * Tests whether ssize_t can hold at least a long int.
+ */
+TYPED_TEST_P(XPlatformTypesTest, SSizeTCanHoldLongInts) {
+  constexpr auto actual = std::numeric_limits<TypeParam>::max();
+  constexpr auto expected = std::numeric_limits<long int>::max();
+  ASSERT_GE(actual, expected);
+}
+
+REGISTER_TYPED_TEST_SUITE_P(XPlatformTypesTest, SSizeTMinusOne,
+                            SSizeTCanHoldInts, SSizeTCanHoldLongInts);
+#else
+REGISTER_TYPED_TEST_SUITE_P(XPlatformTypesTest, SSizeTMinusOne,
+                            SSizeTCanHoldInts);
+#endif
+
+#endif
\ No newline at end of file
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/tools_common.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/tools_common.cc
index 6cc5a5b6922..ec59dfbcd24 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/tools_common.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/tools_common.cc
@@ -85,7 +85,6 @@ namespace hdfs {
   static char input_buffer[BUF_SIZE];
 
   void readFile(std::shared_ptr<hdfs::FileSystem> fs, std::string path, off_t offset, std::FILE* dst_file, bool to_delete) {
-    ssize_t total_bytes_read = 0;
     size_t last_bytes_read = 0;
 
     hdfs::FileHandle *file_raw = nullptr;
@@ -103,7 +102,6 @@ namespace hdfs {
       if(status.ok()) {
         //Writing file chunks to stdout
         fwrite(input_buffer, last_bytes_read, 1, dst_file);
-        total_bytes_read += last_bytes_read;
         offset += last_bytes_read;
       } else {
         if(status.is_invalid_offset()){


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org