[pypy-svn] pypy default: fix up get_total_memory on darwin to clip at addressable_size

etrepum commits-noreply at bitbucket.org
Fri Mar 18 18:36:12 CET 2011


Author: Bob Ippolito <bob at redivi.com>
Branch: 
Changeset: r42796:eec5b51676ae
Date: 2011-03-18 10:35 -0700
http://bitbucket.org/pypy/pypy/changeset/eec5b51676ae/

Log:	fix up get_total_memory on darwin to clip at addressable_size

diff --git a/pypy/rpython/memory/gc/test/test_env.py b/pypy/rpython/memory/gc/test/test_env.py
--- a/pypy/rpython/memory/gc/test/test_env.py
+++ b/pypy/rpython/memory/gc/test/test_env.py
@@ -15,6 +15,15 @@
     assert x == y
     assert type(x) == type(y)
 
+def test_get_total_memory_darwin():
+    # this only tests clipping
+    BIG = 2 * env.addressable_size
+    SMALL = env.addressable_size / 2
+    assert env.addressable_size == env.get_total_memory_darwin(0)
+    assert env.addressable_size == env.get_total_memory_darwin(-1)
+    assert env.addressable_size == env.get_total_memory_darwin(BIG)
+    assert SMALL == env.get_total_memory_darwin(SMALL)
+
 def test_get_total_memory():
     # total memory should be at least a megabyte
     assert env.get_total_memory() > 1024*1024

diff --git a/pypy/rpython/memory/gc/env.py b/pypy/rpython/memory/gc/env.py
--- a/pypy/rpython/memory/gc/env.py
+++ b/pypy/rpython/memory/gc/env.py
@@ -95,13 +95,26 @@
     return result
 
 
+def get_total_memory_darwin(result):
+    debug_start("gc-hardware")
+    if result <= 0:
+        debug_print("get_total_memory() failed")
+        result = addressable_size
+    else:
+        debug_print("memtotal = ", result)
+        if result > addressable_size:
+            result = addressable_size
+    debug_stop("gc-hardware")
+    return result
+
+
 if sys.platform == 'linux2':
     def get_total_memory():
         return get_total_memory_linux2('/proc/meminfo')
 
 elif sys.platform == 'darwin':
     def get_total_memory():
-        return get_darwin_sysctl_signed('hw.memsize')
+        return get_total_memory_darwin(get_darwin_sysctl_signed('hw.memsize'))
 
 else:
     def get_total_memory():


More information about the Pypy-commit mailing list