11import sys
22from _ctypes import (
3+ POINTER as POINTER ,
34 RTLD_GLOBAL as RTLD_GLOBAL ,
45 RTLD_LOCAL as RTLD_LOCAL ,
6+ ArgumentError as ArgumentError ,
57 Array as Array ,
8+ CFuncPtr as _CFuncPtr ,
69 Structure as Structure ,
710 Union as Union ,
11+ _CanCastTo as _CanCastTo ,
12+ _CArgObject as _CArgObject ,
813 _CData as _CData ,
914 _CDataMeta as _CDataMeta ,
1015 _CField as _CField ,
16+ _Pointer as _Pointer ,
17+ _PointerLike as _PointerLike ,
1118 _SimpleCData as _SimpleCData ,
1219 _StructUnionBase as _StructUnionBase ,
1320 _StructUnionMeta as _StructUnionMeta ,
21+ addressof as addressof ,
22+ alignment as alignment ,
23+ byref as byref ,
24+ get_errno as get_errno ,
25+ pointer as pointer ,
26+ resize as resize ,
27+ set_errno as set_errno ,
28+ sizeof as sizeof ,
1429)
15- from collections .abc import Callable , Sequence
16- from typing import Any , ClassVar , Generic , TypeVar , overload
30+ from typing import Any , ClassVar , Generic , TypeVar
1731from typing_extensions import TypeAlias
1832
33+ if sys .platform == "win32" :
34+ from _ctypes import FormatError as FormatError , get_last_error as get_last_error , set_last_error as set_last_error
35+
1936if sys .version_info >= (3 , 9 ):
2037 from types import GenericAlias
2138
2239_T = TypeVar ("_T" )
2340_DLLT = TypeVar ("_DLLT" , bound = CDLL )
24- _CT = TypeVar ("_CT" , bound = _CData )
2541
2642DEFAULT_MODE : int
2743
@@ -75,31 +91,11 @@ if sys.platform == "win32":
7591pydll : LibraryLoader [PyDLL ]
7692pythonapi : PyDLL
7793
78- class _CanCastTo (_CData ): ...
79- class _PointerLike (_CanCastTo ): ...
80-
81- _ECT : TypeAlias = Callable [[type [_CData ] | None , _FuncPointer , tuple [_CData , ...]], _CData ]
82- _PF : TypeAlias = tuple [int ] | tuple [int , str ] | tuple [int , str , Any ]
83-
84- class _FuncPointer (_PointerLike , _CData ):
85- restype : type [_CData ] | Callable [[int ], Any ] | None
86- argtypes : Sequence [type [_CData ]]
87- errcheck : _ECT
88- @overload
89- def __init__ (self , address : int ) -> None : ...
90- @overload
91- def __init__ (self , callable : Callable [..., Any ]) -> None : ...
92- @overload
93- def __init__ (self , func_spec : tuple [str | int , CDLL ], paramflags : tuple [_PF , ...] = ...) -> None : ...
94- @overload
95- def __init__ (self , vtlb_index : int , name : str , paramflags : tuple [_PF , ...] = ..., iid : _Pointer [c_int ] = ...) -> None : ...
96- def __call__ (self , * args : Any , ** kwargs : Any ) -> Any : ...
94+ class _FuncPointer (_CFuncPtr ): ...
9795
9896class _NamedFuncPointer (_FuncPointer ):
9997 __name__ : str
10098
101- class ArgumentError (Exception ): ...
102-
10399def CFUNCTYPE (
104100 restype : type [_CData ] | None , * argtypes : type [_CData ], use_errno : bool = ..., use_last_error : bool = ...
105101) -> type [_FuncPointer ]: ...
@@ -111,8 +107,6 @@ if sys.platform == "win32":
111107
112108def PYFUNCTYPE (restype : type [_CData ] | None , * argtypes : type [_CData ]) -> type [_FuncPointer ]: ...
113109
114- class _CArgObject : ...
115-
116110# Any type that can be implicitly converted to c_void_p when passed as a C function argument.
117111# (bytes is not included here, see below.)
118112_CVoidPLike : TypeAlias = _PointerLike | Array [Any ] | _CArgObject | int
@@ -122,10 +116,6 @@ _CVoidPLike: TypeAlias = _PointerLike | Array[Any] | _CArgObject | int
122116# when memmove(buf, b'foo', 4) was intended.
123117_CVoidConstPLike : TypeAlias = _CVoidPLike | bytes
124118
125- def addressof (obj : _CData ) -> int : ...
126- def alignment (obj_or_type : _CData | type [_CData ]) -> int : ...
127- def byref (obj : _CData , offset : int = ...) -> _CArgObject : ...
128-
129119_CastT = TypeVar ("_CastT" , bound = _CanCastTo )
130120
131121def cast (obj : _CData | _CArgObject | int , typ : type [_CastT ]) -> _CastT : ...
@@ -138,39 +128,10 @@ def create_unicode_buffer(init: int | str, size: int | None = None) -> Array[c_w
138128if sys .platform == "win32" :
139129 def DllCanUnloadNow () -> int : ...
140130 def DllGetClassObject (rclsid : Any , riid : Any , ppv : Any ) -> int : ... # TODO not documented
141- def FormatError (code : int = ...) -> str : ...
142131 def GetLastError () -> int : ...
143132
144- def get_errno () -> int : ...
145-
146- if sys .platform == "win32" :
147- def get_last_error () -> int : ...
148-
149133def memmove (dst : _CVoidPLike , src : _CVoidConstPLike , count : int ) -> int : ...
150134def memset (dst : _CVoidPLike , c : int , count : int ) -> int : ...
151- def POINTER (type : type [_CT ]) -> type [_Pointer [_CT ]]: ...
152-
153- class _Pointer (Generic [_CT ], _PointerLike , _CData ):
154- _type_ : type [_CT ]
155- contents : _CT
156- @overload
157- def __init__ (self ) -> None : ...
158- @overload
159- def __init__ (self , arg : _CT ) -> None : ...
160- @overload
161- def __getitem__ (self , __key : int ) -> Any : ...
162- @overload
163- def __getitem__ (self , __key : slice ) -> list [Any ]: ...
164- def __setitem__ (self , __key : int , __value : Any ) -> None : ...
165-
166- def pointer (__arg : _CT ) -> _Pointer [_CT ]: ...
167- def resize (obj : _CData , size : int ) -> None : ...
168- def set_errno (value : int ) -> int : ...
169-
170- if sys .platform == "win32" :
171- def set_last_error (value : int ) -> int : ...
172-
173- def sizeof (obj_or_type : _CData | type [_CData ]) -> int : ...
174135def string_at (address : _CVoidConstPLike , size : int = - 1 ) -> bytes : ...
175136
176137if sys .platform == "win32" :
0 commit comments