[MLton-commit] r5811

Matthew Fluet fluet at mlton.org
Thu Aug 2 12:04:48 PDT 2007


Cleaner logic
----------------------------------------------------------------------

U   mlton/trunk/runtime/platform/sysctl.c

----------------------------------------------------------------------

Modified: mlton/trunk/runtime/platform/sysctl.c
===================================================================
--- mlton/trunk/runtime/platform/sysctl.c	2007-08-02 18:55:29 UTC (rev 5810)
+++ mlton/trunk/runtime/platform/sysctl.c	2007-08-02 19:04:47 UTC (rev 5811)
@@ -11,31 +11,31 @@
     unsigned long long int pageSize;
     if (-1 == sysctl (mib, 2, &pageSize, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned long long int)
-        || pageSize <= (unsigned long long int)SIZE_MAX) {
+    if (sizeof(size_t) >= sizeof(unsigned long long int)) {
       return (size_t)pageSize;
     } else {
-      return (size_t)SIZE_MAX;
+      pageSize = min(pageSize, (unsigned long long int)SIZE_MAX);
+      return (size_t)pageSize;
     }
   } else if (len == sizeof(unsigned long int)) {
     unsigned long int pageSize;
     if (-1 == sysctl (mib, 2, &pageSize, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned long int)
-        || pageSize <= (unsigned long int)SIZE_MAX) {
+    if (sizeof(size_t) >= sizeof(unsigned long int)) {
       return (size_t)pageSize;
     } else {
-      return (size_t)SIZE_MAX;
+      pageSize = min(pageSize, (unsigned long int)SIZE_MAX);
+      return (size_t)pageSize;
     }
   } else if (len == sizeof(unsigned int)) {
     unsigned int pageSize;
     if (-1 == sysctl (mib, 2, &pageSize, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned int)
-        || pageSize <= (unsigned int)SIZE_MAX) {
+    if (sizeof(size_t) >= sizeof(unsigned int)) {
       return (size_t)pageSize;
     } else {
-      return (size_t)SIZE_MAX;
+      pageSize = min(pageSize, (unsigned int)SIZE_MAX);
+      return (size_t)pageSize;
     }
   } else {
     die ("GC_pageSize");
@@ -59,31 +59,31 @@
     unsigned long long int physMem;
     if (-1 == sysctl (mib, 2, &physMem, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned long long int)
-        || physMem <= (unsigned long long int)SIZE_MAX) {
+    if (sizeof(size_t) >= sizeof(unsigned long long int)) {
       return (size_t)physMem;
     } else {
-      return (size_t)SIZE_MAX;
+      physMem = min(physMem, (unsigned long long int)SIZE_MAX);
+      return (size_t)physMem;
     }
   } else if (len == sizeof(unsigned long int)) {
     unsigned long int physMem;
     if (-1 == sysctl (mib, 2, &physMem, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned long int)
-        || physMem <= (unsigned long int)SIZE_MAX) {
+    if (sizeof(size_t) >= sizeof(unsigned long int)) {
       return (size_t)physMem;
     } else {
-      return (size_t)SIZE_MAX;
+      physMem = min(physMem, (unsigned long int)SIZE_MAX);
+      return (size_t)physMem;
     }
   } else if (len == sizeof(unsigned int)) {
     unsigned int physMem;
     if (-1 == sysctl (mib, 2, &physMem, &len, NULL, 0))
       diee ("sysctl failed");
-    if (sizeof(size_t) >= sizeof(unsigned int)
-        || physMem <= (unsigned int)SIZE_MAX) {
+    if (sizeof(size_t) >= sizeof(unsigned int)) {
       return (size_t)physMem;
     } else {
-      return (size_t)SIZE_MAX;
+      physMem = min(physMem, (unsigned int)SIZE_MAX);
+      return (size_t)physMem;
     }
   } else {
     die ("GC_totalRam");




More information about the MLton-commit mailing list