diff options
author | Thomas Heller <theller@ctypes.org> | 2008-01-17 18:46:55 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2008-01-17 18:46:55 (GMT) |
commit | ff72122184556afae962f32b7d7ac47bb2d5de33 (patch) | |
tree | 1a44c3b7fb2179e8ee0cc5559f4cbfc4d532423d /Lib | |
parent | 9893de1b83978249eafaebe575989537c01b484e (diff) | |
download | cpython-ff72122184556afae962f32b7d7ac47bb2d5de33.zip cpython-ff72122184556afae962f32b7d7ac47bb2d5de33.tar.gz cpython-ff72122184556afae962f32b7d7ac47bb2d5de33.tar.bz2 |
Merged revisions 60001,60003-60004,60008 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60001 | thomas.heller | 2008-01-16 20:16:27 +0100 (Mi, 16 Jan 2008) | 3 lines
Convert the internal ctypes array type cache to a WeakValueDict so
that array types do not live longer than needed.
........
r60003 | thomas.heller | 2008-01-16 20:37:33 +0100 (Mi, 16 Jan 2008) | 3 lines
Raise a TypeError if conflicting positional and named arguments are
passed to a Structure or Union constructor.
........
r60004 | thomas.heller | 2008-01-16 20:45:51 +0100 (Mi, 16 Jan 2008) | 3 lines
Raise a TypeError instead of a ValueError when too many initializers
are used in a Structure or Union constructor.
........
r60008 | thomas.heller | 2008-01-16 21:34:37 +0100 (Mi, 16 Jan 2008) | 3 lines
Use 'g' instead of 'D' as the ctypes typecode for c_longdouble, for
compliance with PEP 3118.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ctypes/__init__.py | 2 | ||||
-rw-r--r-- | Lib/ctypes/test/test_arrays.py | 14 | ||||
-rw-r--r-- | Lib/ctypes/test/test_structures.py | 13 |
3 files changed, 26 insertions, 3 deletions
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index f7d0970..8dd8e0a 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -182,7 +182,7 @@ class c_double(_SimpleCData): _check_size(c_double) class c_longdouble(_SimpleCData): - _type_ = "D" + _type_ = "g" if sizeof(c_longdouble) == sizeof(c_double): c_longdouble = c_double diff --git a/Lib/ctypes/test/test_arrays.py b/Lib/ctypes/test/test_arrays.py index dde77c1..142bae8 100644 --- a/Lib/ctypes/test/test_arrays.py +++ b/Lib/ctypes/test/test_arrays.py @@ -116,5 +116,19 @@ class ArrayTestCase(unittest.TestCase): self.failUnlessEqual(sz[1:4:2], "o") self.failUnlessEqual(sz.value, "foo") + def test_cache(self): + # Array types are cached internally in the _ctypes extension, + # in a WeakValueDictionary. Make sure the array type is + # removed from the cache when the itemtype goes away. This + # test will not fail, but will show a leak in the testsuite. + + # Create a new type: + class my_int(c_int): + pass + # Create a new array type based on it: + t1 = my_int * 1 + t2 = my_int * 1 + self.failUnless(t1 is t2) + if __name__ == '__main__': unittest.main() diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py index b50e4df..c4eee86 100644 --- a/Lib/ctypes/test/test_structures.py +++ b/Lib/ctypes/test/test_structures.py @@ -215,6 +215,15 @@ class StructureTestCase(unittest.TestCase): # too long self.assertRaises(ValueError, Person, "1234567", 5) + def test_conflicting_initializers(self): + class POINT(Structure): + _fields_ = [("x", c_int), ("y", c_int)] + # conflicting positional and keyword args + self.assertRaises(TypeError, POINT, 2, 3, x=4) + self.assertRaises(TypeError, POINT, 2, 3, y=4) + + # too many initializers + self.assertRaises(TypeError, POINT, 2, 3, 4) def test_keyword_initializers(self): class POINT(Structure): @@ -305,9 +314,9 @@ class StructureTestCase(unittest.TestCase): self.failUnlessEqual(cls, RuntimeError) if issubclass(Exception, object): self.failUnlessEqual(msg, - "(Phone) <type 'ValueError'>: too many initializers") + "(Phone) <type 'TypeError'>: too many initializers") else: - self.failUnlessEqual(msg, "(Phone) ValueError: too many initializers") + self.failUnlessEqual(msg, "(Phone) TypeError: too many initializers") def get_except(self, func, *args): |