[pypy-svn] r51609 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes

fijal at codespeak.net fijal at codespeak.net
Mon Feb 18 21:53:49 CET 2008


Author: fijal
Date: Mon Feb 18 21:53:48 2008
New Revision: 51609

Modified:
   pypy/dist/pypy/lib/_ctypes/primitive.py
   pypy/dist/pypy/lib/app_test/ctypes/test_buffers.py
   pypy/dist/pypy/lib/app_test/ctypes/test_callbacks.py
   pypy/dist/pypy/lib/app_test/ctypes/test_cast.py
Log:
Keepalive logic for strings.


Modified: pypy/dist/pypy/lib/_ctypes/primitive.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/primitive.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/primitive.py	Mon Feb 18 21:53:48 2008
@@ -2,7 +2,8 @@
 
 SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv"
 
-from _ctypes.basics import _CData, _CDataMeta, cdata_from_address
+from _ctypes.basics import _CData, _CDataMeta, cdata_from_address,\
+     CArgObject
 from _ctypes.builtin import ConvMode
 
 class NULL(object):
@@ -76,7 +77,7 @@
                     self._objects = value
                     array = _rawffi.Array('c')(len(value)+1, value)
                     value = array.buffer
-                    # XXX free 'array' later
+                    self._objects = {'0': CArgObject(array)}
                 elif value is None:
                     value = 0
                 self._buffer[0] = value
@@ -99,7 +100,7 @@
                     self._objects = value
                     array = _rawffi.Array('u')(len(value)+1, value)
                     value = array.buffer
-                    # XXX free 'array' later
+                    self._objects = {'0': CArgObject(array)}
                 elif value is None:
                     value = 0
                 self._buffer[0] = value
@@ -118,8 +119,7 @@
                 if isinstance(value, str):
                     array = _rawffi.Array('c')(len(value)+1, value)
                     value = array.buffer
-                    self._objects = value
-                    # XXX free 'array' later
+                    self._objects = {'0': CArgObject(value)}
                 elif value is None:
                     value = 0
                 self._buffer[0] = value

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_buffers.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_buffers.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_buffers.py	Mon Feb 18 21:53:48 2008
@@ -1,6 +1,7 @@
 from ctypes import *
+from support import BaseCTypesTestChecker
 
-class TestStringBuffer:
+class TestStringBuffer(BaseCTypesTestChecker):
 
     def test_buffer(self):
         b = create_string_buffer(32)

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_callbacks.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_callbacks.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_callbacks.py	Mon Feb 18 21:53:48 2008
@@ -1,7 +1,8 @@
 from ctypes import *
 import py
+from support import BaseCTypesTestChecker
 
-class TestCallbacks:
+class TestCallbacks(BaseCTypesTestChecker):
     functype = CFUNCTYPE
 
 ##    def tearDown(self):
@@ -107,7 +108,7 @@
 
 ################################################################
 
-class TestSampleCallbacks:
+class TestSampleCallbacks(BaseCTypesTestChecker):
 
     def test_integrate(self):
         # Derived from some then non-working code, posted by David Foster

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_cast.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_cast.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_cast.py	Mon Feb 18 21:53:48 2008
@@ -1,7 +1,8 @@
 from ctypes import *
 import sys, py
+from support import BaseCTypesTestChecker
 
-class TestCast:
+class TestCast(BaseCTypesTestChecker):
 
     def test_array2pointer(self):
         array = (c_int * 3)(42, 17, 2)
@@ -30,9 +31,9 @@
         assert [ptr[i] for i in range(3)] == [42, 17, 2]
 
     def test_p2a_objects(self):
-        py.test.skip("keepalive logic")
+        py.test.skip("We don't keep alive strings")
         array = (c_char_p * 5)()
-        assert array._objects == None
+        assert array._objects is None
         array[0] = "foo bar"
         assert array._objects == {'0': "foo bar"}
 
@@ -60,6 +61,7 @@
     def test_char_p(self):
         # This didn't work: bad argument to internal function
         s = c_char_p("hiho")
+        
         assert cast(cast(s, c_void_p), c_char_p).value == (
                              "hiho")
 



More information about the Pypy-commit mailing list