Improve cffi (#13710)

This commit is contained in:
Semyon Moroz
2025-03-25 17:40:20 +04:00
committed by GitHub
parent 8d67718c0c
commit 2dba4324e1
9 changed files with 221 additions and 208 deletions
-3
View File
@@ -1,6 +1,3 @@
# TODO: missing from stub
cffi.__all__
# added dynamically and not detected by stubtest
cffi.(api.)?FFI.CData
cffi.(api.)?FFI.CType
+7 -3
View File
@@ -1,11 +1,15 @@
from typing import Final
from .api import FFI as FFI
from .error import (
CDefError as CDefError,
FFIError as FFIError,
PkgConfigError as PkgConfigError,
VerificationError as VerificationError,
VerificationMissing as VerificationMissing,
)
__version__: str
__version_info__: tuple[int, int, int]
__version_verifier_modules__: str
__all__ = ["FFI", "VerificationError", "VerificationMissing", "CDefError", "FFIError"]
__version__: Final[str]
__version_info__: Final[tuple[int, int, int]]
__version_verifier_modules__: Final[str]
+2 -1
View File
@@ -1,9 +1,10 @@
from _typeshed import Incomplete
from collections.abc import Callable
unicode = str
long = int
xrange = range
bytechr: Incomplete
bytechr: Callable[[float], bytes]
class CTypesType(type): ...
+88 -88
View File
@@ -1,92 +1,92 @@
from _typeshed import Incomplete
from typing import Final
class CffiOp:
op: Incomplete
arg: Incomplete
def __init__(self, op, arg) -> None: ...
def as_c_expr(self): ...
def as_python_bytes(self): ...
op: int | None
arg: str | None
def __init__(self, op: int | None, arg: str | None) -> None: ...
def as_c_expr(self) -> str: ...
def as_python_bytes(self) -> str: ...
def format_four_bytes(num): ...
def format_four_bytes(num: int) -> str: ...
OP_PRIMITIVE: int
OP_POINTER: int
OP_ARRAY: int
OP_OPEN_ARRAY: int
OP_STRUCT_UNION: int
OP_ENUM: int
OP_FUNCTION: int
OP_FUNCTION_END: int
OP_NOOP: int
OP_BITFIELD: int
OP_TYPENAME: int
OP_CPYTHON_BLTN_V: int
OP_CPYTHON_BLTN_N: int
OP_CPYTHON_BLTN_O: int
OP_CONSTANT: int
OP_CONSTANT_INT: int
OP_GLOBAL_VAR: int
OP_DLOPEN_FUNC: int
OP_DLOPEN_CONST: int
OP_GLOBAL_VAR_F: int
OP_EXTERN_PYTHON: int
PRIM_VOID: int
PRIM_BOOL: int
PRIM_CHAR: int
PRIM_SCHAR: int
PRIM_UCHAR: int
PRIM_SHORT: int
PRIM_USHORT: int
PRIM_INT: int
PRIM_UINT: int
PRIM_LONG: int
PRIM_ULONG: int
PRIM_LONGLONG: int
PRIM_ULONGLONG: int
PRIM_FLOAT: int
PRIM_DOUBLE: int
PRIM_LONGDOUBLE: int
PRIM_WCHAR: int
PRIM_INT8: int
PRIM_UINT8: int
PRIM_INT16: int
PRIM_UINT16: int
PRIM_INT32: int
PRIM_UINT32: int
PRIM_INT64: int
PRIM_UINT64: int
PRIM_INTPTR: int
PRIM_UINTPTR: int
PRIM_PTRDIFF: int
PRIM_SIZE: int
PRIM_SSIZE: int
PRIM_INT_LEAST8: int
PRIM_UINT_LEAST8: int
PRIM_INT_LEAST16: int
PRIM_UINT_LEAST16: int
PRIM_INT_LEAST32: int
PRIM_UINT_LEAST32: int
PRIM_INT_LEAST64: int
PRIM_UINT_LEAST64: int
PRIM_INT_FAST8: int
PRIM_UINT_FAST8: int
PRIM_INT_FAST16: int
PRIM_UINT_FAST16: int
PRIM_INT_FAST32: int
PRIM_UINT_FAST32: int
PRIM_INT_FAST64: int
PRIM_UINT_FAST64: int
PRIM_INTMAX: int
PRIM_UINTMAX: int
PRIM_FLOATCOMPLEX: int
PRIM_DOUBLECOMPLEX: int
PRIM_CHAR16: int
PRIM_CHAR32: int
PRIMITIVE_TO_INDEX: Incomplete
F_UNION: int
F_CHECK_FIELDS: int
F_PACKED: int
F_EXTERNAL: int
F_OPAQUE: int
G_FLAGS: Incomplete
CLASS_NAME: Incomplete
OP_PRIMITIVE: Final = 1
OP_POINTER: Final = 3
OP_ARRAY: Final = 5
OP_OPEN_ARRAY: Final = 7
OP_STRUCT_UNION: Final = 9
OP_ENUM: Final = 11
OP_FUNCTION: Final = 13
OP_FUNCTION_END: Final = 15
OP_NOOP: Final = 17
OP_BITFIELD: Final = 19
OP_TYPENAME: Final = 21
OP_CPYTHON_BLTN_V: Final = 23
OP_CPYTHON_BLTN_N: Final = 25
OP_CPYTHON_BLTN_O: Final = 27
OP_CONSTANT: Final = 29
OP_CONSTANT_INT: Final = 31
OP_GLOBAL_VAR: Final = 33
OP_DLOPEN_FUNC: Final = 35
OP_DLOPEN_CONST: Final = 37
OP_GLOBAL_VAR_F: Final = 39
OP_EXTERN_PYTHON: Final = 41
PRIM_VOID: Final = 0
PRIM_BOOL: Final = 1
PRIM_CHAR: Final = 2
PRIM_SCHAR: Final = 3
PRIM_UCHAR: Final = 4
PRIM_SHORT: Final = 5
PRIM_USHORT: Final = 6
PRIM_INT: Final = 7
PRIM_UINT: Final = 8
PRIM_LONG: Final = 9
PRIM_ULONG: Final = 10
PRIM_LONGLONG: Final = 11
PRIM_ULONGLONG: Final = 12
PRIM_FLOAT: Final = 13
PRIM_DOUBLE: Final = 14
PRIM_LONGDOUBLE: Final = 15
PRIM_WCHAR: Final = 16
PRIM_INT8: Final = 17
PRIM_UINT8: Final = 18
PRIM_INT16: Final = 19
PRIM_UINT16: Final = 20
PRIM_INT32: Final = 21
PRIM_UINT32: Final = 22
PRIM_INT64: Final = 23
PRIM_UINT64: Final = 24
PRIM_INTPTR: Final = 25
PRIM_UINTPTR: Final = 26
PRIM_PTRDIFF: Final = 27
PRIM_SIZE: Final = 28
PRIM_SSIZE: Final = 29
PRIM_INT_LEAST8: Final = 30
PRIM_UINT_LEAST8: Final = 31
PRIM_INT_LEAST16: Final = 32
PRIM_UINT_LEAST16: Final = 33
PRIM_INT_LEAST32: Final = 34
PRIM_UINT_LEAST32: Final = 35
PRIM_INT_LEAST64: Final = 36
PRIM_UINT_LEAST64: Final = 37
PRIM_INT_FAST8: Final = 38
PRIM_UINT_FAST8: Final = 39
PRIM_INT_FAST16: Final = 40
PRIM_UINT_FAST16: Final = 41
PRIM_INT_FAST32: Final = 42
PRIM_UINT_FAST32: Final = 43
PRIM_INT_FAST64: Final = 44
PRIM_UINT_FAST64: Final = 45
PRIM_INTMAX: Final = 46
PRIM_UINTMAX: Final = 47
PRIM_FLOATCOMPLEX: Final = 48
PRIM_DOUBLECOMPLEX: Final = 49
PRIM_CHAR16: Final = 50
PRIM_CHAR32: Final = 51
PRIMITIVE_TO_INDEX: Final[dict[str, int]]
F_UNION: Final = 1
F_CHECK_FIELDS: Final = 2
F_PACKED: Final = 4
F_EXTERNAL: Final = 8
F_OPAQUE: Final = 16
G_FLAGS: Final[dict[bytes, bytes]]
CLASS_NAME: Final[dict[int, str]]
+5 -4
View File
@@ -1,11 +1,12 @@
from _typeshed import Incomplete
from _typeshed import Incomplete, StrOrBytesPath
from typing import Any, Final
LIST_OF_FILE_NAMES: Incomplete
LIST_OF_FILE_NAMES: Final[list[str]]
def get_extension(srcfilename, modname, sources=(), **kwds): ...
def compile(tmpdir, ext, compiler_verbose: int = 0, debug: Incomplete | None = None): ...
def maybe_relative_path(path): ...
def maybe_relative_path(path: StrOrBytesPath) -> StrOrBytesPath | str: ...
int_or_long = int
def flatten(x): ...
def flatten(x: int | str | list[Any] | tuple[Any] | dict[Any, Any]) -> str: ...
+58 -56
View File
@@ -1,26 +1,28 @@
from _thread import LockType
from _typeshed import Incomplete
from collections.abc import Generator
from typing import Final
from .error import CDefError as CDefError, VerificationError as VerificationError, VerificationMissing as VerificationMissing
from .lock import allocate_lock as allocate_lock
Q_CONST: int
Q_RESTRICT: int
Q_VOLATILE: int
Q_CONST: Final = 1
Q_RESTRICT: Final = 2
Q_VOLATILE: Final = 4
def qualify(quals, replace_with): ...
def qualify(quals: int, replace_with: str) -> str: ...
class BaseTypeByIdentity:
is_array_type: bool
is_raw_function: bool
def get_c_name(self, replace_with: str = "", context: str = "a C file", quals: int = 0): ...
def has_c_name(self): ...
def is_integer_type(self): ...
def get_c_name(self, replace_with: str = "", context: str = "a C file", quals: int = 0) -> str: ...
def has_c_name(self) -> bool: ...
def is_integer_type(self) -> bool: ...
def get_cached_btype(self, ffi, finishlist, can_delay: bool = False): ...
class BaseType(BaseTypeByIdentity):
def __eq__(self, other): ...
def __ne__(self, other): ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...
class VoidType(BaseType):
@@ -28,33 +30,33 @@ class VoidType(BaseType):
def __init__(self) -> None: ...
def build_backend_type(self, ffi, finishlist): ...
void_type: Incomplete
void_type: VoidType
class BasePrimitiveType(BaseType):
def is_complex_type(self): ...
def is_complex_type(self) -> bool: ...
class PrimitiveType(BasePrimitiveType):
ALL_PRIMITIVE_TYPES: Incomplete
name: Incomplete
c_name_with_marker: Incomplete
def __init__(self, name) -> None: ...
def is_char_type(self): ...
def is_integer_type(self): ...
def is_float_type(self): ...
def is_complex_type(self): ...
ALL_PRIMITIVE_TYPES: dict[str, str]
name: str
c_name_with_marker: str
def __init__(self, name: str) -> None: ...
def is_char_type(self) -> bool: ...
def is_integer_type(self) -> bool: ...
def is_float_type(self) -> bool: ...
def is_complex_type(self) -> bool: ...
def build_backend_type(self, ffi, finishlist): ...
class UnknownIntegerType(BasePrimitiveType):
name: Incomplete
c_name_with_marker: Incomplete
def __init__(self, name) -> None: ...
def is_integer_type(self): ...
name: str
c_name_with_marker: str
def __init__(self, name: str) -> None: ...
def is_integer_type(self) -> bool: ...
def build_backend_type(self, ffi, finishlist) -> None: ...
class UnknownFloatType(BasePrimitiveType):
name: Incomplete
c_name_with_marker: Incomplete
def __init__(self, name) -> None: ...
name: str
c_name_with_marker: str
def __init__(self, name: str) -> None: ...
def build_backend_type(self, ffi, finishlist) -> None: ...
class BaseFunctionType(BaseType):
@@ -62,54 +64,54 @@ class BaseFunctionType(BaseType):
result: Incomplete
ellipsis: Incomplete
abi: Incomplete
c_name_with_marker: Incomplete
c_name_with_marker: str
def __init__(self, args, result, ellipsis, abi: Incomplete | None = None) -> None: ...
class RawFunctionType(BaseFunctionType):
is_raw_function: bool
def build_backend_type(self, ffi, finishlist) -> None: ...
def as_function_pointer(self): ...
def as_function_pointer(self) -> FunctionPtrType: ...
class FunctionPtrType(BaseFunctionType):
def build_backend_type(self, ffi, finishlist): ...
def as_raw_function(self): ...
def as_raw_function(self) -> RawFunctionType: ...
class PointerType(BaseType):
totype: Incomplete
quals: Incomplete
c_name_with_marker: Incomplete
def __init__(self, totype, quals: int = 0) -> None: ...
totype: BaseTypeByIdentity
quals: int
c_name_with_marker: str
def __init__(self, totype: BaseTypeByIdentity, quals: int = 0) -> None: ...
def build_backend_type(self, ffi, finishlist): ...
voidp_type: Incomplete
voidp_type: PointerType
def ConstPointerType(totype): ...
def ConstPointerType(totype: BaseTypeByIdentity) -> PointerType: ...
const_voidp_type: Incomplete
const_voidp_type: PointerType
class NamedPointerType(PointerType):
name: Incomplete
c_name_with_marker: Incomplete
def __init__(self, totype, name, quals: int = 0) -> None: ...
name: str
c_name_with_marker: str
def __init__(self, totype: BaseTypeByIdentity, name: str, quals: int = 0) -> None: ...
class ArrayType(BaseType):
is_array_type: bool
item: Incomplete
length: Incomplete
c_name_with_marker: Incomplete
def __init__(self, item, length) -> None: ...
def length_is_unknown(self): ...
def resolve_length(self, newlength): ...
length: str | None
c_name_with_marker: str
def __init__(self, item, length: str | None) -> None: ...
def length_is_unknown(self) -> bool: ...
def resolve_length(self, newlength: str | None) -> ArrayType: ...
def build_backend_type(self, ffi, finishlist): ...
char_array_type: Incomplete
char_array_type: ArrayType
class StructOrUnionOrEnum(BaseTypeByIdentity):
forcename: Incomplete
c_name_with_marker: Incomplete
forcename: str | None
c_name_with_marker: str
def build_c_name_with_marker(self) -> None: ...
def force_the_name(self, forcename) -> None: ...
def get_official_name(self): ...
def force_the_name(self, forcename: str | None) -> None: ...
def get_official_name(self) -> str: ...
class StructOrUnion(StructOrUnionOrEnum):
fixedlayout: Incomplete
@@ -122,7 +124,7 @@ class StructOrUnion(StructOrUnionOrEnum):
fldbitsize: Incomplete
fldquals: Incomplete
def __init__(self, name, fldnames, fldtypes, fldbitsize, fldquals: Incomplete | None = None) -> None: ...
def anonymous_struct_fields(self) -> Generator[Incomplete, None, None]: ...
def anonymous_struct_fields(self) -> Generator[StructOrUnion, None, None]: ...
def enumfields(self, expand_anonymous_struct_union: bool = True) -> Generator[Incomplete, None, None]: ...
def force_flatten(self) -> None: ...
def get_cached_btype(self, ffi, finishlist, can_delay: bool = False): ...
@@ -145,18 +147,18 @@ class EnumType(StructOrUnionOrEnum):
enumvalues: Incomplete
baseinttype: Incomplete
def __init__(self, name, enumerators, enumvalues, baseinttype: Incomplete | None = None) -> None: ...
forcename: Incomplete
def force_the_name(self, forcename) -> None: ...
forcename: str | None
def force_the_name(self, forcename: str | None) -> None: ...
def check_not_partial(self) -> None: ...
def build_backend_type(self, ffi, finishlist): ...
def build_baseinttype(self, ffi, finishlist): ...
def unknown_type(name, structname: Incomplete | None = None): ...
def unknown_ptr_type(name, structname: Incomplete | None = None): ...
def unknown_type(name: str, structname: str | None = None) -> StructType: ...
def unknown_ptr_type(name: str, structname: str | None = None) -> NamedPointerType: ...
global_lock: Incomplete
global_lock: LockType
def get_typecache(backend): ...
def global_cache(srctype, ffi, funcname, *args, **kwds): ...
def pointer_cache(ffi, BType): ...
def attach_exception_info(e, name) -> None: ...
def attach_exception_info(e, name: str) -> None: ...
+5 -3
View File
@@ -1,3 +1,5 @@
def merge_flags(cfg1, cfg2): ...
def call(libname, flag, encoding="utf-8"): ...
def flags_from_pkgconfig(libs): ...
from collections.abc import Sequence
def merge_flags(cfg1: dict[str, list[str]], cfg2: dict[str, list[str]]) -> dict[str, list[str]]: ...
def call(libname: str, flag: str, encoding: str = ...) -> str: ...
def flags_from_pkgconfig(libs: Sequence[str]) -> dict[str, list[str]]: ...
+34 -32
View File
@@ -1,13 +1,15 @@
import io
from _typeshed import Incomplete
from _typeshed import Incomplete, StrPath
from typing import Final
from typing_extensions import TypeAlias
from .cffi_opcode import *
from .error import VerificationError as VerificationError
VERSION_BASE: int
VERSION_EMBEDDED: int
VERSION_CHAR16CHAR32: int
USE_LIMITED_API: Incomplete
VERSION_BASE: Final = 9729
VERSION_EMBEDDED: Final = 9985
VERSION_CHAR16CHAR32: Final = 10241
USE_LIMITED_API: Final = True
class GlobalExpr:
name: Incomplete
@@ -16,8 +18,8 @@ class GlobalExpr:
size: Incomplete
check_value: Incomplete
def __init__(self, name, address, type_op, size: int = 0, check_value: int = 0) -> None: ...
def as_c_expr(self): ...
def as_python_expr(self): ...
def as_c_expr(self) -> str: ...
def as_python_expr(self) -> str: ...
class FieldExpr:
name: Incomplete
@@ -26,9 +28,9 @@ class FieldExpr:
fbitsize: Incomplete
field_type_op: Incomplete
def __init__(self, name, field_offset, field_size, fbitsize, field_type_op) -> None: ...
def as_c_expr(self): ...
def as_c_expr(self) -> str: ...
def as_python_expr(self) -> None: ...
def as_field_python_expr(self): ...
def as_field_python_expr(self) -> str: ...
class StructUnionExpr:
name: Incomplete
@@ -40,8 +42,8 @@ class StructUnionExpr:
first_field_index: Incomplete
c_fields: Incomplete
def __init__(self, name, type_index, flags, size, alignment, comment, first_field_index, c_fields) -> None: ...
def as_c_expr(self): ...
def as_python_expr(self): ...
def as_c_expr(self) -> str: ...
def as_python_expr(self) -> str: ...
class EnumExpr:
name: Incomplete
@@ -50,46 +52,46 @@ class EnumExpr:
signed: Incomplete
allenums: Incomplete
def __init__(self, name, type_index, size, signed, allenums) -> None: ...
def as_c_expr(self): ...
def as_python_expr(self): ...
def as_c_expr(self) -> str: ...
def as_python_expr(self) -> str: ...
class TypenameExpr:
name: Incomplete
type_index: Incomplete
def __init__(self, name, type_index) -> None: ...
def as_c_expr(self): ...
def as_python_expr(self): ...
def as_c_expr(self) -> str: ...
def as_python_expr(self) -> str: ...
class Recompiler:
ffi: Incomplete
module_name: Incomplete
target_is_python: Incomplete
def __init__(self, ffi, module_name, target_is_python: bool = False) -> None: ...
def needs_version(self, ver) -> None: ...
cffi_types: Incomplete
def collect_type_table(self): ...
ALL_STEPS: Incomplete
def collect_step_tables(self): ...
def write_source_to_f(self, f, preamble) -> None: ...
def write_c_source_to_f(self, f, preamble) -> None: ...
module_name: str
target_is_python: bool
def __init__(self, ffi, module_name: str, target_is_python: bool = False) -> None: ...
def needs_version(self, ver: int) -> None: ...
cffi_types: list[Incomplete]
def collect_type_table(self) -> None: ...
ALL_STEPS: list[str]
def collect_step_tables(self) -> None: ...
def write_source_to_f(self, f, preamble: str) -> None: ...
def write_c_source_to_f(self, f, preamble: str) -> None: ...
def write_py_source_to_f(self, f) -> None: ...
NativeIO: TypeAlias = io.StringIO
def make_c_source(ffi, module_name, preamble, target_c_file, verbose: bool = False): ...
def make_py_source(ffi, module_name, target_py_file, verbose: bool = False): ...
def make_c_source(ffi, module_name: str, preamble: str, target_c_file, verbose: bool = False): ...
def make_py_source(ffi, module_name: str, target_py_file, verbose: bool = False): ...
def recompile(
ffi,
module_name,
preamble,
module_name: str | bytes,
preamble: str | None,
tmpdir: str = ".",
call_c_compiler: bool = True,
c_file: Incomplete | None = None,
source_extension: str = ".c",
extradir: Incomplete | None = None,
extradir: StrPath | None = None,
compiler_verbose: int = 1,
target: Incomplete | None = None,
debug: Incomplete | None = None,
target: str | None = None,
debug: int | None = None,
uses_ffiplatform: bool = True,
**kwds,
): ...
+22 -18
View File
@@ -1,5 +1,7 @@
import io
from _typeshed import Incomplete
import os
from _typeshed import Incomplete, StrPath
from typing import AnyStr
from typing_extensions import TypeAlias
NativeIO: TypeAlias = io.StringIO
@@ -7,33 +9,35 @@ NativeIO: TypeAlias = io.StringIO
class Verifier:
ffi: Incomplete
preamble: Incomplete
flags: Incomplete
kwds: Incomplete
tmpdir: Incomplete
sourcefilename: Incomplete
modulefilename: Incomplete
ext_package: Incomplete
flags: int | None
kwds: dict[str, list[str] | tuple[str]]
tmpdir: StrPath
sourcefilename: str
modulefilename: str
ext_package: str | None
def __init__(
self,
ffi,
preamble,
tmpdir: Incomplete | None = None,
modulename: Incomplete | None = None,
ext_package: Incomplete | None = None,
tmpdir: StrPath | None = None,
modulename: str | None = None,
ext_package: str | None = None,
tag: str = "",
force_generic_engine: bool = False,
source_extension: str = ".c",
flags: Incomplete | None = None,
relative_to: Incomplete | None = None,
**kwds,
flags: int | None = None,
relative_to: os.PathLike[AnyStr] | None = None,
**kwds: list[str] | tuple[str],
) -> None: ...
def write_source(self, file: Incomplete | None = None) -> None: ...
def compile_module(self) -> None: ...
def load_library(self): ...
def get_module_name(self): ...
def get_module_name(self) -> str: ...
def get_extension(self): ...
def generates_python_module(self): ...
def make_relative_to(self, kwds, relative_to): ...
def generates_python_module(self) -> bool: ...
def make_relative_to(
self, kwds: dict[str, list[str] | tuple[str]], relative_to: os.PathLike[AnyStr] | None
) -> dict[str, list[str] | tuple[str]]: ...
def set_tmpdir(dirname) -> None: ...
def cleanup_tmpdir(tmpdir: Incomplete | None = None, keep_so: bool = False) -> None: ...
def set_tmpdir(dirname: StrPath) -> None: ...
def cleanup_tmpdir(tmpdir: StrPath | None = None, keep_so: bool = False) -> None: ...