Author: Armin Rigo <ar...@tunes.org>
Branch: release-5.x
Changeset: r83148:bbd45126bc69
Date: 2016-03-18 17:52 +0000
http://bitbucket.org/pypy/pypy/changeset/bbd45126bc69/

Log:    Add some "add_memory_pressure=True" at all places that malloc
        something that is likely to be a PyObject or attached to a PyObject,
        and thus relying on our GC to know when it must be freed. This
        change helps a lot on some examples.

diff --git a/pypy/module/cpyext/bytesobject.py 
b/pypy/module/cpyext/bytesobject.py
--- a/pypy/module/cpyext/bytesobject.py
+++ b/pypy/module/cpyext/bytesobject.py
@@ -80,7 +80,8 @@
     buflen = length + 1
     py_str.c_size = length
     py_str.c_buffer = lltype.malloc(rffi.CCHARP.TO, buflen,
-                                    flavor='raw', zero=True)
+                                    flavor='raw', zero=True,
+                                    add_memory_pressure=True)
     return py_str
 
 def string_attach(space, py_obj, w_obj):
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -17,7 +17,8 @@
 @cpython_api([Py_ssize_t], rffi.VOIDP)
 def PyObject_MALLOC(space, size):
     return lltype.malloc(rffi.VOIDP.TO, size,
-                         flavor='raw', zero=True)
+                         flavor='raw', zero=True,
+                         add_memory_pressure=True)
 
 @cpython_api([rffi.VOIDP], lltype.Void)
 def PyObject_FREE(space, ptr):
diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -50,7 +50,8 @@
             size += itemcount * pytype.c_tp_itemsize
         assert size >= rffi.sizeof(PyObject.TO)
         buf = lltype.malloc(rffi.VOIDP.TO, size,
-                            flavor='raw', zero=True)
+                            flavor='raw', zero=True,
+                            add_memory_pressure=True)
         pyobj = rffi.cast(PyObject, buf)
         pyobj.c_ob_refcnt = 1
         pyobj.c_ob_type = pytype
diff --git a/pypy/module/cpyext/tupleobject.py 
b/pypy/module/cpyext/tupleobject.py
--- a/pypy/module/cpyext/tupleobject.py
+++ b/pypy/module/cpyext/tupleobject.py
@@ -59,7 +59,8 @@
     py_tup = rffi.cast(PyTupleObject, py_obj)
 
     py_tup.c_ob_item = lltype.malloc(ObjectItems, length,
-                                     flavor='raw', zero=True)
+                                     flavor='raw', zero=True,
+                                     add_memory_pressure=True)
     py_tup.c_ob_size = length
     return py_tup
 
@@ -70,7 +71,8 @@
     """
     items_w = space.fixedview(w_obj)
     l = len(items_w)
-    p = lltype.malloc(ObjectItems, l, flavor='raw')
+    p = lltype.malloc(ObjectItems, l, flavor='raw',
+                      add_memory_pressure=True)
     i = 0
     try:
         while i < l:
@@ -177,7 +179,8 @@
     ref = rffi.cast(PyTupleObject, ref)
     oldsize = ref.c_ob_size
     oldp = ref.c_ob_item
-    newp = lltype.malloc(ObjectItems, newsize, zero=True, flavor='raw')
+    newp = lltype.malloc(ObjectItems, newsize, zero=True, flavor='raw',
+                         add_memory_pressure=True)
     try:
         if oldsize < newsize:
             to_cp = oldsize
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -421,7 +421,8 @@
             Py_DecRef(space, w_metatype)
 
     heaptype = lltype.malloc(PyHeapTypeObject.TO,
-                             flavor='raw', zero=True)
+                             flavor='raw', zero=True,
+                             add_memory_pressure=True)
     pto = heaptype.c_ht_type
     pto.c_ob_refcnt = 1
     pto.c_ob_type = metatype
diff --git a/pypy/module/cpyext/unicodeobject.py 
b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -55,7 +55,8 @@
     buflen = length + 1
     py_uni.c_size = length
     py_uni.c_buffer = lltype.malloc(rffi.CWCHARP.TO, buflen,
-                                    flavor='raw', zero=True)
+                                    flavor='raw', zero=True,
+                                    add_memory_pressure=True)
     return py_uni
 
 def unicode_attach(space, py_obj, w_obj):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to