from typing import Generic, TypeVar

def malloc(size: int) -> 'void_p': ...
def free(ptr: 'void_p') -> None: ...
def memset(ptr: 'void_p', value: int, size: int) -> None: ...
def memcpy(dst: 'void_p', src: 'void_p', size: int) -> None: ...

T = TypeVar('T')
Tp = TypeVar('Tp', bound='void_p')

def p_cast(ptr: 'void_p', cls: type[T]) -> T:
    """Cast a pointer to a specific type."""
def p_value(ptr: 'void_p') -> int:
    """Get the value of a pointer."""
def pp_deref(ptr: Tp) -> Tp:
    """Dereference a double pointer."""

class void_p:
    def __init__(self, addr: int): ...
    def __eq__(self, other: 'void_p') -> bool: ...
    def __ne__(self, other: 'void_p') -> bool: ...
    def __lt__(self, other: 'void_p') -> bool: ...
    def __le__(self, other: 'void_p') -> bool: ...
    def __gt__(self, other: 'void_p') -> bool: ...
    def __ge__(self, other: 'void_p') -> bool: ...
    def __hash__(self) -> int: ...
    def __repr__(self) -> str: ...

class Pointer(Generic[T], void_p):
    def read(self) -> T: ...
    def write(self, value: T) -> None: ...
    def __getitem__(self, index: int) -> T: ...
    def __setitem__(self, index: int, value: T) -> None: ...

class char_p(Pointer[int]):
    def read_string(self) -> str: ...
    def write_string(self, value: str) -> None: ...

class uchar_p(Pointer[int]): pass
class short_p(Pointer[int]): pass
class ushort_p(Pointer[int]): pass
class int_p(Pointer[int]): pass
class uint_p(Pointer[int]): pass
class long_p(Pointer[int]): pass
class ulong_p(Pointer[int]): pass
class longlong_p(Pointer[int]): pass
class ulonglong_p(Pointer[int]): pass
class float_p(Pointer[float]): pass
class double_p(Pointer[float]): pass
class bool_p(Pointer[bool]): pass

class struct:
    def __init__(self, size: int): ...
    def addr(self) -> 'void_p': ...
    def copy(self) -> 'struct': ...
    def sizeof(self) -> int: ...
    def __eq__(self, other: 'struct') -> bool: ...
    def __ne__(self, other: 'struct') -> bool: ...

    def hex(self) -> str: ...
    @staticmethod
    def fromhex(s: str) -> 'struct': ...

    def read_char(self, offset=0) -> int: ...
    def read_uchar(self, offset=0) -> int: ...
    def read_short(self, offset=0) -> int: ...
    def read_ushort(self, offset=0) -> int: ...
    def read_int(self, offset=0) -> int: ...
    def read_uint(self, offset=0) -> int: ...
    def read_long(self, offset=0) -> int: ...
    def read_ulong(self, offset=0) -> int: ...
    def read_longlong(self, offset=0) -> int: ...
    def read_ulonglong(self, offset=0) -> int: ...
    def read_float(self, offset=0) -> float: ...
    def read_double(self, offset=0) -> float: ...
    def read_bool(self, offset=0) -> bool: ...
    def read_void_p(self, offset=0) -> 'void_p': ...
    def write_char(self, value: int, offset=0) -> None: ...
    def write_uchar(self, value: int, offset=0) -> None: ...
    def write_short(self, value: int, offset=0) -> None: ...
    def write_ushort(self, value: int, offset=0) -> None: ...
    def write_int(self, value: int, offset=0) -> None: ...
    def write_uint(self, value: int, offset=0) -> None: ...
    def write_long(self, value: int, offset=0) -> None: ...
    def write_ulong(self, value: int, offset=0) -> None: ...
    def write_longlong(self, value: int, offset=0) -> None: ...
    def write_ulonglong(self, value: int, offset=0) -> None: ...
    def write_float(self, value: float, offset=0) -> None: ...
    def write_double(self, value: float, offset=0) -> None: ...
    def write_bool(self, value: bool, offset=0) -> None: ...
    def write_void_p(self, value: 'void_p', offset=0) -> None: ...

def char_(val: int) -> struct: ...
def uchar_(val: int) -> struct: ...
def short_(val: int) -> struct: ...
def ushort_(val: int) -> struct: ...
def int_(val: int) -> struct: ...
def uint_(val: int) -> struct: ...
def long_(val: int) -> struct: ...
def ulong_(val: int) -> struct: ...
def longlong_(val: int) -> struct: ...
def ulonglong_(val: int) -> struct: ...
def float_(val: float) -> struct: ...
def double_(val: float) -> struct: ...
def bool_(val: bool) -> struct: ...

class _StructLike(Generic[T]):
    def to_struct(self) -> struct: ...
    @classmethod
    def from_struct(cls, s: struct) -> T: ...

    def addr(self) -> 'Pointer[T]': ...
    def copy(self) -> T: ...
    def sizeof(self) -> int: ...
    def __eq__(self, other: T) -> bool: ...
    def __ne__(self, other: T) -> bool: ...

