mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
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.
This commit is contained in:
parent
fa9211b11d
commit
5ce8f35931
3 changed files with 26 additions and 0 deletions
|
|
@ -45,6 +45,7 @@ def __setattr__(self, attrname, value):
|
|||
|
||||
class BigEndianStructure(Structure, metaclass=_swapped_meta):
|
||||
"""Structure with big endian byte order"""
|
||||
__slots__ = ()
|
||||
_swappedbytes_ = None
|
||||
|
||||
elif sys.byteorder == "big":
|
||||
|
|
@ -53,6 +54,7 @@ class BigEndianStructure(Structure, metaclass=_swapped_meta):
|
|||
BigEndianStructure = Structure
|
||||
class LittleEndianStructure(Structure, metaclass=_swapped_meta):
|
||||
"""Structure with little endian byte order"""
|
||||
__slots__ = ()
|
||||
_swappedbytes_ = None
|
||||
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -22,6 +22,26 @@ def test_X(self):
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -124,6 +124,10 @@ Core and Builtins
|
|||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue