Changed return type of `os::pagesize` in stout.

Previously, `os::pagesize` returned a signed integer (`int`), where a
negative value indicated an error. This is problematic: several callers
neglected to check for errors and most callers ultimately want an
unsigned value anyway.

We could make this return `Try<size_t>`, but that seems heavyweight: the
Win32 implementation of this function will never fail and the POSIX
implementation (using `sysconf(3)`) seems unlikely to fail in
practice. Hence, this commit changes `os::pagesize` to return `size_t`.

Review: https://reviews.apache.org/r/51967/


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

Branch: refs/heads/master
Commit: f768df34a248f24cbbf3d7d1796eee89b315e312
Parents: 67d8518
Author: Neil Conway <neil.con...@gmail.com>
Authored: Sat Sep 17 00:09:57 2016 +0200
Committer: Michael Park <mp...@apache.org>
Committed: Sat Sep 17 03:17:17 2016 +0200

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/freebsd.hpp          |  4 ++--
 3rdparty/stout/include/stout/os/linux.hpp            |  5 +----
 3rdparty/stout/include/stout/os/osx.hpp              |  5 +----
 3rdparty/stout/include/stout/os/posix/pagesize.hpp   | 12 ++++++++----
 3rdparty/stout/include/stout/os/windows/pagesize.hpp |  2 +-
 5 files changed, 13 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f768df34/3rdparty/stout/include/stout/os/freebsd.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/freebsd.hpp 
b/3rdparty/stout/include/stout/os/freebsd.hpp
index 3f5142c..f331d15 100644
--- a/3rdparty/stout/include/stout/os/freebsd.hpp
+++ b/3rdparty/stout/include/stout/os/freebsd.hpp
@@ -42,7 +42,7 @@ inline Result<Process> process(pid_t pid)
 
   foreach (const kinfo_proc& kinfo, kinfos.get()) {
     if (kinfo.ki_pid == pid) {
-      int pagesize = os::pagesize();
+      size_t pagesize = os::pagesize();
       return Process(kinfo.ki_pid,
                      kinfo.ki_ppid,
                      kinfo.ki_pgid,
@@ -84,7 +84,7 @@ inline Try<Memory> memory()
   }
   memory.total = Bytes(physicalMemory.get());
 
-  const int pageSize = os::pagesize();
+  const size_t pageSize = os::pagesize();
 
   unsigned int freeCount;
   size_t length = sizeof(freeCount);

http://git-wip-us.apache.org/repos/asf/mesos/blob/f768df34/3rdparty/stout/include/stout/os/linux.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/linux.hpp 
b/3rdparty/stout/include/stout/os/linux.hpp
index 3382528..fc44700 100644
--- a/3rdparty/stout/include/stout/os/linux.hpp
+++ b/3rdparty/stout/include/stout/os/linux.hpp
@@ -84,10 +84,7 @@ inline pid_t clone(const lambda::function<int()>& func, int 
flags)
 inline Result<Process> process(pid_t pid)
 {
   // Page size, used for memory accounting.
-  static const int pageSize = os::pagesize();
-  if (pageSize <= 0) {
-    return Error("Failed to get `os::pagesize`");
-  }
+  static const size_t pageSize = os::pagesize();
 
   // Number of clock ticks per second, used for cpu accounting.
   static const long ticks = sysconf(_SC_CLK_TCK);

http://git-wip-us.apache.org/repos/asf/mesos/blob/f768df34/3rdparty/stout/include/stout/os/osx.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/osx.hpp 
b/3rdparty/stout/include/stout/os/osx.hpp
index 54d3412..770c85d 100644
--- a/3rdparty/stout/include/stout/os/osx.hpp
+++ b/3rdparty/stout/include/stout/os/osx.hpp
@@ -203,10 +203,7 @@ inline Try<Memory> memory()
 
   // Size of free memory is available in terms of number of
   // free pages on Mac OS X.
-  const int pageSize = os::pagesize();
-  if (pageSize < 0) {
-    return ErrnoError();
-  }
+  const size_t pageSize = os::pagesize();
 
   unsigned int freeCount;
   size_t length = sizeof(freeCount);

http://git-wip-us.apache.org/repos/asf/mesos/blob/f768df34/3rdparty/stout/include/stout/os/posix/pagesize.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/pagesize.hpp 
b/3rdparty/stout/include/stout/os/posix/pagesize.hpp
index f3ae69a..37463b3 100644
--- a/3rdparty/stout/include/stout/os/posix/pagesize.hpp
+++ b/3rdparty/stout/include/stout/os/posix/pagesize.hpp
@@ -15,14 +15,18 @@
 
 #include <unistd.h>
 
+#include <glog/logging.h>
+
 
 namespace os {
 
-// The alternative `getpagesize()` does not exist when enforcing
-// strict POSIX compliance.
-inline int pagesize()
+// The alternative `getpagesize()` is not defined by POSIX.
+inline size_t pagesize()
 {
-  return sysconf(_SC_PAGESIZE);
+  // We assume that `sysconf` will not fail in practice.
+  long result = ::sysconf(_SC_PAGESIZE);
+  CHECK(result >= 0);
+  return result;
 }
 
 } // namespace os {

http://git-wip-us.apache.org/repos/asf/mesos/blob/f768df34/3rdparty/stout/include/stout/os/windows/pagesize.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/pagesize.hpp 
b/3rdparty/stout/include/stout/os/windows/pagesize.hpp
index 6112e97..ddf23c1 100644
--- a/3rdparty/stout/include/stout/os/windows/pagesize.hpp
+++ b/3rdparty/stout/include/stout/os/windows/pagesize.hpp
@@ -18,7 +18,7 @@
 
 namespace os {
 
-inline int pagesize()
+inline size_t pagesize()
 {
   SYSTEM_INFO si;
   GetSystemInfo(&si);

Reply via email to