[Python-checkins] cpython: Issue #22098: ctypes' BigEndianStructure and LittleEndianStructure now define
antoine.pitrou
python-checkins at python.org
Sat Aug 30 00:39:10 CEST 2014
http://hg.python.org/cpython/rev/c499cc2c4a06
changeset: 92270:c499cc2c4a06
user: Antoine Pitrou <solipsis at pitrou.net>
date: Sat Aug 30 00:37:18 2014 +0200
summary:
Issue #22098: ctypes' BigEndianStructure and LittleEndianStructure now define an empty __slots__ so that subclasses don't always get an instance dict.
Patch by Claudiu Popa.
files:
Lib/ctypes/_endian.py | 2 ++
Lib/ctypes/test/test_byteswap.py | 20 ++++++++++++++++++++
Misc/NEWS | 4 ++++
3 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/Lib/ctypes/_endian.py b/Lib/ctypes/_endian.py
--- a/Lib/ctypes/_endian.py
+++ b/Lib/ctypes/_endian.py
@@ -45,6 +45,7 @@
class BigEndianStructure(Structure, metaclass=_swapped_meta):
"""Structure with big endian byte order"""
+ __slots__ = ()
_swappedbytes_ = None
elif sys.byteorder == "big":
@@ -53,6 +54,7 @@
BigEndianStructure = Structure
class LittleEndianStructure(Structure, metaclass=_swapped_meta):
"""Structure with little endian byte order"""
+ __slots__ = ()
_swappedbytes_ = None
else:
diff --git a/Lib/ctypes/test/test_byteswap.py b/Lib/ctypes/test/test_byteswap.py
--- a/Lib/ctypes/test/test_byteswap.py
+++ b/Lib/ctypes/test/test_byteswap.py
@@ -22,6 +22,26 @@
setattr(bits, "i%s" % i, 1)
dump(bits)
+ def test_slots(self):
+ class BigPoint(BigEndianStructure):
+ __slots__ = ()
+ _fields_ = [("x", c_int), ("y", c_int)]
+
+ class LowPoint(LittleEndianStructure):
+ __slots__ = ()
+ _fields_ = [("x", c_int), ("y", c_int)]
+
+ big = BigPoint()
+ little = LowPoint()
+ big.x = 4
+ big.y = 2
+ little.x = 2
+ little.y = 4
+ with self.assertRaises(AttributeError):
+ big.z = 42
+ with self.assertRaises(AttributeError):
+ little.z = 24
+
def test_endian_short(self):
if sys.byteorder == "little":
self.assertIs(c_short.__ctype_le__, c_short)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -124,6 +124,10 @@
Library
-------
+- Issue #22098: ctypes' BigEndianStructure and LittleEndianStructure now
+ define an empty __slots__ so that subclasses don't always get an instance
+ dict. Patch by Claudiu Popa.
+
- Issue #22185: Fix an occasional RuntimeError in threading.Condition.wait()
caused by mutation of the waiters queue without holding the lock. Patch
by Doug Zongker.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list