Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: raw-memory-pressure-nursery
Changeset: r52489:0385f8a3e803
Date: 2012-02-14 23:49 +0200
http://bitbucket.org/pypy/pypy/changeset/0385f8a3e803/

Log:    I think most modules now use the correct interface

diff --git a/pypy/module/_hashlib/interp_hashlib.py 
b/pypy/module/_hashlib/interp_hashlib.py
--- a/pypy/module/_hashlib/interp_hashlib.py
+++ b/pypy/module/_hashlib/interp_hashlib.py
@@ -23,6 +23,7 @@
     ctx = lltype.nullptr(ropenssl.EVP_MD_CTX.TO)
 
     def __init__(self, space, name):
+        rgc.add_memory_pressure(self, HASH_MALLOC_SIZE + self.digest_size)
         self.name = name
         digest_type = self.digest_type_by_name(space)
         self.digest_size = rffi.getintfield(digest_type, 'c_md_size')
@@ -33,7 +34,6 @@
         self.lock = Lock(space)
 
         ctx = lltype.malloc(ropenssl.EVP_MD_CTX.TO, flavor='raw')
-        rgc.add_memory_pressure(HASH_MALLOC_SIZE + self.digest_size)
         try:
             ropenssl.EVP_DigestInit(ctx, digest_type)
             self.ctx = ctx
diff --git a/pypy/module/_multiprocessing/interp_semaphore.py 
b/pypy/module/_multiprocessing/interp_semaphore.py
--- a/pypy/module/_multiprocessing/interp_semaphore.py
+++ b/pypy/module/_multiprocessing/interp_semaphore.py
@@ -208,7 +208,7 @@
 # don't forget to wrap them into OperationError
 
 if sys.platform == 'win32':
-    def create_semaphore(space, name, val, max):
+    def create_semaphore(space, self, name, val, max):
         rwin32.SetLastError(0)
         handle = _CreateSemaphore(rffi.NULL, val, max, rffi.NULL)
         # On Windows we should fail on ERROR_ALREADY_EXISTS
@@ -302,14 +302,14 @@
         return semlock_getvalue(self, space) == 0
 
 else:
-    def create_semaphore(space, name, val, max):
+    def create_semaphore(space, w_semaphore, name, val, max):
         sem = sem_open(name, os.O_CREAT | os.O_EXCL, 0600, val)
         try:
             sem_unlink(name)
         except OSError:
             pass
         else:
-            rgc.add_memory_pressure(SEM_T_SIZE)
+            rgc.add_memory_pressure(w_semaphore, SEM_T_SIZE)
         return sem
 
     def delete_semaphore(handle):
@@ -517,12 +517,12 @@
     counter = space.fromcache(CounterState).getCount()
     name = "/mp%d-%d" % (os.getpid(), counter)
 
+    self = space.allocate_instance(W_SemLock, w_subtype)
     try:
-        handle = create_semaphore(space, name, value, maxvalue)
+        handle = create_semaphore(space, self, name, value, maxvalue)
     except OSError, e:
         raise wrap_oserror(space, e)
 
-    self = space.allocate_instance(W_SemLock, w_subtype)
     self.__init__(handle, kind, maxvalue)
 
     return space.wrap(self)
diff --git a/pypy/module/_rawffi/interp_rawffi.py 
b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -7,6 +7,7 @@
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.rlib.unroll import unrolling_iterable
 import pypy.rlib.rposix as rposix
+from pypy.rlib import rgc
 
 _MS_WINDOWS = os.name == "nt"
 
@@ -267,8 +268,9 @@
         if address:
             self.ll_buffer = rffi.cast(rffi.VOIDP, address)
         else:
+            rgc.add_memory_pressure(self, size)
             self.ll_buffer = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw',
-                                           zero=True, add_memory_pressure=True)
+                                           zero=True)
             if tracker.DO_TRACING:
                 ll_buf = rffi.cast(lltype.Signed, self.ll_buffer)
                 tracker.trace_allocation(ll_buf, self)
diff --git a/pypy/module/array/interp_array.py 
b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -12,7 +12,7 @@
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rpython.lltypesystem import lltype, rffi
-
+from pypy.rlib import rgc
 
 @unwrap_spec(typecode=str)
 def w_array(space, w_cls, typecode, __args__):
@@ -226,8 +226,8 @@
                     some += size >> 3
                     self.allocated = size + some
                     new_buffer = lltype.malloc(mytype.arraytype,
-                                               self.allocated, flavor='raw',
-                                               add_memory_pressure=True)
+                                               self.allocated, flavor='raw')
+                    rgc.add_memory_pressure(self, self.allocated * 
rffi.sizeof(mytype.arraytype.OF))
                     for i in range(min(size, self.len)):
                         new_buffer[i] = self.buffer[i]
                 else:
diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -7,7 +7,7 @@
 from pypy.rlib.objectmodel import specialize
 from pypy.rlib.rarithmetic import LONG_BIT
 from pypy.rpython.lltypesystem import lltype, rffi
-
+from pypy.rlib import rgc
 
 UNSIGNEDLTR = "u"
 SIGNEDLTR = "i"
@@ -30,12 +30,12 @@
         self.alternate_constructors = alternate_constructors
         self.aliases = aliases
 
-    def malloc(self, length):
+    def malloc(self, array, length):
         # XXX find out why test_zjit explodes with tracking of allocations
-        return lltype.malloc(VOID_STORAGE, self.itemtype.get_element_size() * 
length,
-            zero=True, flavor="raw",
-            track_allocation=False, add_memory_pressure=True
-        )
+        size = self.itemtype.get_element_size() * length
+        rgc.add_memory_pressure(array, size)
+        return lltype.malloc(VOID_STORAGE, size, zero=True, flavor="raw",
+                             track_allocation=False)
 
     @specialize.argtype(1)
     def box(self, value):
diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -903,7 +903,7 @@
         if parent is not None:
             self.storage = parent.storage
         else:
-            self.storage = dtype.malloc(size)
+            self.storage = dtype.malloc(self, size)
         self.order = order
         self.dtype = dtype
         if self.strides is None:
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -11,7 +11,7 @@
 
 
 class MockDtype(object):
-    def malloc(self, size):
+    def malloc(self, array, size):
         return None
 
 
diff --git a/pypy/module/pyexpat/interp_pyexpat.py 
b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -407,6 +407,7 @@
 class W_XMLParserType(Wrappable):
 
     def __init__(self, space, parser, w_intern):
+        rgc.add_memory_pressure(XML_Parser_SIZE + 300)
         self.itself = parser
 
         self.w_intern = w_intern
@@ -824,7 +825,6 @@
     # Currently this is just the size of the pointer and some estimated bytes.
     # The struct isn't actually defined in expat.h - it is in xmlparse.c
     # XXX: find a good estimate of the XML_ParserStruct
-    rgc.add_memory_pressure(XML_Parser_SIZE + 300)
     if not xmlparser:
         raise OperationError(space.w_RuntimeError,
                              space.wrap('XML_ParserCreate failed'))
diff --git a/pypy/module/thread/ll_thread.py b/pypy/module/thread/ll_thread.py
--- a/pypy/module/thread/ll_thread.py
+++ b/pypy/module/thread/ll_thread.py
@@ -4,7 +4,7 @@
 import py
 from pypy.rlib import jit, rgc
 from pypy.rlib.debug import ll_assert
-from pypy.rlib.objectmodel import we_are_translated, specialize
+from pypy.rlib.objectmodel import we_are_translated, specialize, instantiate
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.tool import rffi_platform
 from pypy.tool import autopath
@@ -83,7 +83,10 @@
                               _nowrapper=True)
 
 def allocate_lock():
-    return Lock(allocate_ll_lock())
+    lock = instantiate(Lock)
+    ll_lock = allocate_ll_lock(lock)
+    lock.__init__(lock, ll_lock)
+    return lock
 
 @specialize.arg(0)
 def ll_start_new_thread(func):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to