Skip to content

Commit 05c3378

Browse files
committed
Revert changes
1 parent add1ed5 commit 05c3378

3 files changed

Lines changed: 100 additions & 114 deletions

File tree

Lib/_pyrepl/windows_console.py

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import os
2424
import sys
2525

26-
import ctypes.util
26+
import ctypes
2727
import types
2828
from dataclasses import dataclass
2929
from ctypes.wintypes import (
@@ -37,7 +37,7 @@
3737
WCHAR,
3838
SHORT,
3939
)
40-
from ctypes import POINTER, Union
40+
from ctypes import Structure, POINTER, Union
4141
from typing import TYPE_CHECKING
4242

4343
from _colorize import ANSIColors
@@ -723,56 +723,61 @@ def repaint(self) -> None:
723723

724724

725725
# Windows interop
726-
@ctypes.util.struct
727-
class CONSOLE_SCREEN_BUFFER_INFO:
728-
dwSize: _COORD
729-
dwCursorPosition: _COORD
730-
wAttributes: WORD
731-
srWindow: SMALL_RECT
732-
dwMaximumWindowSize: _COORD
726+
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
727+
_fields_ = [
728+
("dwSize", _COORD),
729+
("dwCursorPosition", _COORD),
730+
("wAttributes", WORD),
731+
("srWindow", SMALL_RECT),
732+
("dwMaximumWindowSize", _COORD),
733+
]
733734

734735

735-
@ctypes.util.struct
736-
class CONSOLE_CURSOR_INFO:
737-
dwSize: DWORD
738-
bVisible: BOOL
736+
class CONSOLE_CURSOR_INFO(Structure):
737+
_fields_ = [
738+
("dwSize", DWORD),
739+
("bVisible", BOOL),
740+
]
739741

740742

741-
@ctypes.util.struct
742-
class CHAR_INFO:
743-
UnicodeChar: WCHAR
744-
Attributes: WORD
743+
class CHAR_INFO(Structure):
744+
_fields_ = [
745+
("UnicodeChar", WCHAR),
746+
("Attributes", WORD),
747+
]
745748

746749

747750
class Char(Union):
748-
UnicodeChar: WCHAR
749-
Char: CHAR
751+
_fields_ = [
752+
("UnicodeChar", WCHAR),
753+
("Char", CHAR),
754+
]
750755

751756

752-
@ctypes.util.struct
753-
class KeyEvent:
754-
bKeyDown: BOOL
755-
wRepeatCount: WORD
756-
wVirtualKeyCode: WORD
757-
wVirtualScanCode: WORD
758-
uChar: Char
759-
dwControlKeyState: DWORD
757+
class KeyEvent(ctypes.Structure):
758+
_fields_ = [
759+
("bKeyDown", BOOL),
760+
("wRepeatCount", WORD),
761+
("wVirtualKeyCode", WORD),
762+
("wVirtualScanCode", WORD),
763+
("uChar", Char),
764+
("dwControlKeyState", DWORD),
765+
]
760766

761767

762-
@ctypes.util.struct
763-
class WindowsBufferSizeEvent:
764-
dwSize: _COORD
768+
class WindowsBufferSizeEvent(ctypes.Structure):
769+
_fields_ = [("dwSize", _COORD)]
765770

766771

767772
class ConsoleEvent(ctypes.Union):
768-
KeyEvent: KeyEvent
769-
WindowsBufferSizeEvent: WindowsBufferSizeEvent
773+
_fields_ = [
774+
("KeyEvent", KeyEvent),
775+
("WindowsBufferSizeEvent", WindowsBufferSizeEvent),
776+
]
770777

771778

772-
@ctypes.util.struct
773-
class INPUT_RECORD:
774-
EventType: WORD
775-
Event: ConsoleEvent
779+
class INPUT_RECORD(Structure):
780+
_fields_ = [("EventType", WORD), ("Event", ConsoleEvent)]
776781

777782

778783
KEY_EVENT = 0x01

Lib/ctypes/wintypes.py

Lines changed: 53 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# The most useful windows datatypes
2-
import ctypes.util
2+
import ctypes
33

44
BYTE = ctypes.c_ubyte
55
WORD = ctypes.c_ushort
@@ -102,84 +102,75 @@ def __repr__(self):
102102
################################################################
103103
# Some important structure definitions
104104

105-
@ctypes.util.struct
106-
class RECT:
107-
left: LONG
108-
top: LONG
109-
right: LONG
110-
bottom: LONG
105+
class RECT(ctypes.Structure):
106+
_fields_ = [("left", LONG),
107+
("top", LONG),
108+
("right", LONG),
109+
("bottom", LONG)]
111110
tagRECT = _RECTL = RECTL = RECT
112111

113-
@ctypes.util.struct
114-
class _SMALL_RECT:
115-
Left: SHORT
116-
Top: SHORT
117-
Right: SHORT
118-
Bottom: SHORT
112+
class _SMALL_RECT(ctypes.Structure):
113+
_fields_ = [('Left', SHORT),
114+
('Top', SHORT),
115+
('Right', SHORT),
116+
('Bottom', SHORT)]
119117
SMALL_RECT = _SMALL_RECT
120118

121-
@ctypes.util.struct
122-
class _COORD:
123-
X: SHORT
124-
Y: SHORT
119+
class _COORD(ctypes.Structure):
120+
_fields_ = [('X', SHORT),
121+
('Y', SHORT)]
125122

126-
@ctypes.util.struct
127-
class POINT:
128-
x: LONG
129-
y: LONG
123+
class POINT(ctypes.Structure):
124+
_fields_ = [("x", LONG),
125+
("y", LONG)]
130126
tagPOINT = _POINTL = POINTL = POINT
131127

132-
@ctypes.util.struct
133-
class SIZE:
134-
cx: LONG
135-
cy: LONG
128+
class SIZE(ctypes.Structure):
129+
_fields_ = [("cx", LONG),
130+
("cy", LONG)]
136131
tagSIZE = SIZEL = SIZE
137132

138133
def RGB(red, green, blue):
139134
return red + (green << 8) + (blue << 16)
140135

141-
@ctypes.util.struct
142-
class FILETIME:
143-
dwLowDateTime: DWORD
144-
dwHighDateTime: DWORD
136+
class FILETIME(ctypes.Structure):
137+
_fields_ = [("dwLowDateTime", DWORD),
138+
("dwHighDateTime", DWORD)]
145139
_FILETIME = FILETIME
146140

147-
@ctypes.util.struct
148-
class MSG:
149-
hWnd: HWND
150-
message: UINT
151-
wParam: WPARAM
152-
lParam: LPARAM
153-
time: DWORD
154-
pt: POINT
141+
class MSG(ctypes.Structure):
142+
_fields_ = [("hWnd", HWND),
143+
("message", UINT),
144+
("wParam", WPARAM),
145+
("lParam", LPARAM),
146+
("time", DWORD),
147+
("pt", POINT)]
155148
tagMSG = MSG
156149
MAX_PATH = 260
157150

158-
@ctypes.util.struct
159-
class WIN32_FIND_DATAA:
160-
dwFileAttributes: DWORD
161-
ftCreationTime: FILETIME
162-
ftLastAccessTime: FILETIME
163-
ftLastWriteTime: FILETIME
164-
nFileSizeHigh: DWORD
165-
nFileSizeLow: DWORD
166-
dwReserved0: DWORD
167-
dwReserved1: DWORD
168-
cFileName: CHAR * MAX_PATH
169-
cAlternateFileName: CHAR * 14
170-
171-
@ctypes.util.struct
172-
class WIN32_FIND_DATAW:
173-
dwFileAttributes: DWORD
174-
ftCreationTime: FILETIME
175-
ftLastAccessTime: FILETIME
176-
ftLastWriteTime: FILETIME
177-
nFileSizeHigh: DWORD
178-
nFileSizeLow: DWORD
179-
dwReserved0: DWORD
180-
dwReserved1: DWORD
181-
cFileName: WCHAR * MAX_PATH
182-
cAlternateFileName: WCHAR * 14
151+
class WIN32_FIND_DATAA(ctypes.Structure):
152+
_fields_ = [("dwFileAttributes", DWORD),
153+
("ftCreationTime", FILETIME),
154+
("ftLastAccessTime", FILETIME),
155+
("ftLastWriteTime", FILETIME),
156+
("nFileSizeHigh", DWORD),
157+
("nFileSizeLow", DWORD),
158+
("dwReserved0", DWORD),
159+
("dwReserved1", DWORD),
160+
("cFileName", CHAR * MAX_PATH),
161+
("cAlternateFileName", CHAR * 14)]
162+
163+
class WIN32_FIND_DATAW(ctypes.Structure):
164+
_fields_ = [("dwFileAttributes", DWORD),
165+
("ftCreationTime", FILETIME),
166+
("ftLastAccessTime", FILETIME),
167+
("ftLastWriteTime", FILETIME),
168+
("nFileSizeHigh", DWORD),
169+
("nFileSizeLow", DWORD),
170+
("dwReserved0", DWORD),
171+
("dwReserved1", DWORD),
172+
("cFileName", WCHAR * MAX_PATH),
173+
("cAlternateFileName", WCHAR * 14)]
183174

184175
################################################################
185176
# Pointer types

Lib/test/test_buffer.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
try:
3939
import ctypes
40-
import ctypes.util
4140
except ImportError:
4241
ctypes = None
4342

@@ -2850,11 +2849,8 @@ def test_memoryview_cast_1D_ND(self):
28502849

28512850
if ctypes:
28522851
# format: "T{>l:x:>d:y:}"
2853-
@ctypes.util.struct(endian='big')
2854-
class BEPoint:
2855-
x: ctypes.c_long
2856-
y: ctypes.c_double
2857-
2852+
class BEPoint(ctypes.BigEndianStructure):
2853+
_fields_ = [("x", ctypes.c_long), ("y", ctypes.c_double)]
28582854
point = BEPoint(100, 200.1)
28592855
m1 = memoryview(point)
28602856
m2 = m1.cast('B')
@@ -3254,11 +3250,8 @@ def test_memoryview_compare_special_cases(self):
32543250
# Some ctypes format strings are unknown to the struct module.
32553251
if ctypes:
32563252
# format: "T{>l:x:>l:y:}"
3257-
@ctypes.util.struct(endian='big')
3258-
class BEPoint:
3259-
x: ctypes.c_long
3260-
y: ctypes.c_long
3261-
3253+
class BEPoint(ctypes.BigEndianStructure):
3254+
_fields_ = [("x", ctypes.c_long), ("y", ctypes.c_long)]
32623255
point = BEPoint(100, 200)
32633256
a = memoryview(point)
32643257
b = memoryview(point)
@@ -3995,11 +3988,8 @@ def test_memoryview_tobytes(self):
39953988
# Unknown formats are handled: tobytes() purely depends on itemsize.
39963989
if ctypes:
39973990
# format: "T{>l:x:>l:y:}"
3998-
@ctypes.util.struct(endian='big')
3999-
class BEPoint:
4000-
x: ctypes.c_long
4001-
y: ctypes.c_long
4002-
3991+
class BEPoint(ctypes.BigEndianStructure):
3992+
_fields_ = [("x", ctypes.c_long), ("y", ctypes.c_long)]
40033993
point = BEPoint(100, 200)
40043994
a = memoryview(point)
40053995
self.assertEqual(a.tobytes(), bytes(point))

0 commit comments

Comments
 (0)