[pypy-svn] r51581 - pypy/dist/pypy/lib/_ctypes

fijal at codespeak.net fijal at codespeak.net
Mon Feb 18 13:22:40 CET 2008


Author: fijal
Date: Mon Feb 18 13:22:39 2008
New Revision: 51581

Modified:
   pypy/dist/pypy/lib/_ctypes/union.py
Log:
Missing del


Modified: pypy/dist/pypy/lib/_ctypes/union.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/union.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/union.py	Mon Feb 18 13:22:39 2008
@@ -26,6 +26,7 @@
             # malloc size
             size = self.__class__._sizeofinstances()
             self.__dict__['_buffer'] = _rawffi.Array('c')(size)
+            self.__dict__['_needs_free'] = True
         res.__init__ = __init__
         return res
 
@@ -65,6 +66,7 @@
 class Union(_CData):
     __metaclass__ = UnionMeta
     _ffiletter = 'P'
+    _needs_free = False
 
     def __getattr__(self, name):
         try:
@@ -82,3 +84,9 @@
         cobj, value = fieldtype._CData_input(value)
         buf = self._ffiarrays[name].fromaddress(self._buffer.buffer, 1)
         buf[0] = value[0]
+
+    def __del__(self):
+        if self._needs_free:
+            self._buffer.free()
+            self._buffer = None
+            self._needs_free = False



More information about the Pypy-commit mailing list