From 9bbd0116267de9a505cd1a2a973527395c3e644d Mon Sep 17 00:00:00 2001 From: Charles Vink Date: Thu, 8 Oct 2015 09:44:08 -0400 Subject: [PATCH 1/3] Squashed 'externals/coda-oss/' changes from fb34fe8..327e8b4 327e8b4 Hopefully adding OSX support to sys-c++ git-subtree-dir: externals/coda-oss git-subtree-split: 327e8b4a9f02186c66614aa881e92add3facae98 --- modules/c++/sys/source/OSUnix.cpp | 46 +++++++++++++++++++++++++++++++ modules/c++/sys/tests/OSTest.cpp | 7 +++++ 2 files changed, 53 insertions(+) diff --git a/modules/c++/sys/source/OSUnix.cpp b/modules/c++/sys/source/OSUnix.cpp index 9367cf1fd..f7ee2b6a0 100644 --- a/modules/c++/sys/source/OSUnix.cpp +++ b/modules/c++/sys/source/OSUnix.cpp @@ -30,6 +30,17 @@ #include #include +#if defined(__APPLE__) + +#include +#include +#include +#include +#include +#include + +#endif + #include "sys/OSUnix.h" #include "sys/File.h" @@ -275,12 +286,47 @@ size_t sysconfCaller(int name) void sys::OSUnix::getMemInfo(size_t &totalPhysMem, size_t &freePhysMem) const { + // Unfortunately sysctl is the best way to do this on OSX, + // but sysctl is deprecated in favor of sysconf on linux +#if defined(__APPLE__) + long long physMem = 0; + size_t size = sizeof(physMem); + int status = sysctlbyname("hw.memsize", &physMem, &length, 0, 0); + if(status) + { + throw sys::SystemException(Ctxt("Call to sysctl() has failed")); + } + + mach_port_t machPort = mach_host_self(); + mach_msg_type_number_t count = HOST_VM_INFO_COUNT; + vm_size_t pageSize = 0; + vm_statistics_data_t vmstat; + + if(KERN_SUCCESS != host_statistics(machPort, HOST_VM_INFO, + (host_info_t) &vmstat, &count)) + { + throw sys::SystemException(Ctxt("Call to host_statistics() has failed")); + } + + if(KERN_SUCCESS != host_page_size(machPort, &pageSize)) + { + throw sys::SystemException(Ctxt("Call to host_page_size has failed")); + } + + long long freeBytes = vmstat.free_count * pageSize; + + totalPhysMem = physMem / 1024 / 1024; + freePhysMem = freeBytes / 1024 / 1024; + +#else long long pageSize = sysconfCaller(_SC_PAGESIZE); long long totalNumPages = sysconfCaller(_SC_PHYS_PAGES); long long availNumPages = sysconfCaller(_SC_AVPHYS_PAGES); totalPhysMem = (pageSize*totalNumPages/1024)/1024; freePhysMem = (pageSize*availNumPages/1024)/1024; + +#endif } void sys::DirectoryUnix::close() diff --git a/modules/c++/sys/tests/OSTest.cpp b/modules/c++/sys/tests/OSTest.cpp index 753c7dd2b..70708e807 100644 --- a/modules/c++/sys/tests/OSTest.cpp +++ b/modules/c++/sys/tests/OSTest.cpp @@ -47,6 +47,13 @@ int main(int argc, char **argv) std::cout << "The delimiter on this platform: " << os.getDelimiter() << std::endl; std::cout << "The process id: " << os.getProcessId() << std::endl; + + size_t freeMemory = 0; + size_t physMemory = 0; + os.getMemInfo(physMemory, freeMemory); + std::cout << "Total physical memory (MB): " << physMemory << std::endl; + std::cout << "Total free memory (MB): " << freeMemory << std::endl; + //std::cout << "The user is: " << os.getUsername() << std::endl; ///////////////////////////////////////////// // File exists check!!! From 9c464523ba36db7422187e33d8286f142542e050 Mon Sep 17 00:00:00 2001 From: Charles Vink Date: Thu, 8 Oct 2015 15:22:55 -0400 Subject: [PATCH 2/3] Updated CSM wscript to recognized OSX platform --- projects/csm/wscript | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/projects/csm/wscript b/projects/csm/wscript index 1ccea34e9..473686d4d 100644 --- a/projects/csm/wscript +++ b/projects/csm/wscript @@ -5,6 +5,7 @@ PLUGIN = 'CSM' REMOVEPLUGINPREFIX = True import sys, os, re +from waflib import Errors DIRS = 'external' @@ -22,6 +23,7 @@ def configure(conf): linuxRegex = r'.*-.*-linux-.*|i686-pc-.*|linux' solarisRegex = r'sparc-sun.*|i.86-pc-solaris.*|sunos' winRegex = r'win32' + osxRegex = r'darwin' if re.match(linuxRegex, sys.platform): platformName = 'linux' elif re.match(solarisRegex, sys.platform): @@ -37,6 +39,8 @@ def configure(conf): # For example, if you're building with VS 2008 Express, use: # --enable-32bit "--msvc_version=msvc 9.0Exp" platformName = 'winVC' + str(conf.env['MSVC_VERSION']).replace('.', '') + elif re.match(osxRegex,sys.platform): + platformName='darwin' else: raise Errors.WafError('Unsupported platform %s' % sys.platform) From 1213bcecfed4051fc32a3a0ea242ef2326b5ac21 Mon Sep 17 00:00:00 2001 From: Charles Vink Date: Mon, 12 Oct 2015 08:39:23 -0400 Subject: [PATCH 3/3] Squashed 'externals/coda-oss/' changes from 327e8b4..2fc9ea7 2fc9ea7 Merge pull request #58 from mdaus/osx_config 0b70f4e Fixed typo in OSX code git-subtree-dir: externals/coda-oss git-subtree-split: 2fc9ea72e6672d544fdb8c1877adcad06bf52994 --- modules/c++/sys/source/OSUnix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/c++/sys/source/OSUnix.cpp b/modules/c++/sys/source/OSUnix.cpp index f7ee2b6a0..4ebeec1f3 100644 --- a/modules/c++/sys/source/OSUnix.cpp +++ b/modules/c++/sys/source/OSUnix.cpp @@ -291,7 +291,7 @@ void sys::OSUnix::getMemInfo(size_t &totalPhysMem, size_t &freePhysMem) const #if defined(__APPLE__) long long physMem = 0; size_t size = sizeof(physMem); - int status = sysctlbyname("hw.memsize", &physMem, &length, 0, 0); + int status = sysctlbyname("hw.memsize", &physMem, &size, 0, 0); if(status) { throw sys::SystemException(Ctxt("Call to sysctl() has failed"));