[pypy-svn] r79755 - pypy/trunk/lib_pypy/_ctypes

arigo at codespeak.net arigo at codespeak.net
Thu Dec 2 17:17:39 CET 2010


Author: arigo
Date: Thu Dec  2 17:17:37 2010
New Revision: 79755

Modified:
   pypy/trunk/lib_pypy/_ctypes/array.py
   pypy/trunk/lib_pypy/_ctypes/pointer.py
   pypy/trunk/lib_pypy/_ctypes/primitive.py
Log:
Remove the __new__ introduced to handle re-calling __init__()
explicitly.  Fix this case with just a hack.  The issue is that
the __new__ method is also called from various places in the
code, and we don't want to create (and autofree only at the next
gc collection) unneeded objects.  Doing so is enough to make
"pypy-c translate.py" run out of memory on 32-bit.



Modified: pypy/trunk/lib_pypy/_ctypes/array.py
==============================================================================
--- pypy/trunk/lib_pypy/_ctypes/array.py	(original)
+++ pypy/trunk/lib_pypy/_ctypes/array.py	Thu Dec  2 17:17:37 2010
@@ -158,12 +158,9 @@
     __metaclass__ = ArrayMeta
     _ffiargshape = 'P'
 
-    def __new__(cls, *args):
-        self = _CData.__new__(cls, *args)
-        self._buffer = self._ffiarray(self._length_, autofree=True)
-        return self
-
     def __init__(self, *args):
+        if not hasattr(self, '_buffer'):
+            self._buffer = self._ffiarray(self._length_, autofree=True)
         for i, arg in enumerate(args):
             self[i] = arg
 

Modified: pypy/trunk/lib_pypy/_ctypes/pointer.py
==============================================================================
--- pypy/trunk/lib_pypy/_ctypes/pointer.py	(original)
+++ pypy/trunk/lib_pypy/_ctypes/pointer.py	Thu Dec  2 17:17:37 2010
@@ -56,7 +56,8 @@
     def set_type(self, TP):
         ffiarray = _rawffi.Array('P')
         def __init__(self, value=None):
-            self._buffer = ffiarray(1, autofree=True)
+            if not hasattr(self, '_buffer'):
+                self._buffer = ffiarray(1, autofree=True)
             if value is not None:
                 self.contents = value
         self._ffiarray = ffiarray

Modified: pypy/trunk/lib_pypy/_ctypes/primitive.py
==============================================================================
--- pypy/trunk/lib_pypy/_ctypes/primitive.py	(original)
+++ pypy/trunk/lib_pypy/_ctypes/primitive.py	Thu Dec  2 17:17:37 2010
@@ -288,12 +288,9 @@
     __metaclass__ = SimpleType
     _type_ = 'i'
 
-    def __new__(cls, *args, **kwds):
-        self = _CData.__new__(cls, *args, **kwds)
-        self._buffer = self._ffiarray(1, autofree=True)
-        return self
-
     def __init__(self, value=DEFAULT_VALUE):
+        if not hasattr(self, '_buffer'):
+            self._buffer = self._ffiarray(1, autofree=True)
         if value is not DEFAULT_VALUE:
             self.value = value
 



More information about the Pypy-commit mailing list