Skip to content

Commit

Permalink
libs.ioctl: expand accepted types for structure
Browse files Browse the repository at this point in the history
  • Loading branch information
benmoran56 committed May 2, 2024
1 parent b45d9d7 commit c226c60
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pyglet/libs/ioctl.py
Expand Up @@ -39,8 +39,9 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Callable
from ctypes import Structure
from ctypes import Structure, c_int, c_uint
from typing import Callable, Union
c_data = Union[type[Structure], c_int, c_uint]


_IOC_NRBITS = 8
Expand All @@ -67,7 +68,7 @@ def _IOC(io_dir: _IOC_NONE | _IOC_READ | _IOC_WRITE, code: int, nr: int, size: i
return (io_dir << _IOC_DIRSHIFT) | (code << _IOC_TYPESHIFT) | (nr << _IOC_NRSHIFT) | (size << _IOC_SIZESHIFT)


def _IOR(code: str, nr: int, struct: type[Structure]) -> Callable:
def _IOR(code: str, nr: int, struct: c_data) -> Callable:
request = _IOC(_IOC_READ, ord(code), nr, _sizeof(struct))

def f(fileno, *args):
Expand Down Expand Up @@ -97,7 +98,7 @@ def f(fileno, length=256):
return f


def _IOW(code: str, nr: int, struct: type[Structure]) -> Callable:
def _IOW(code: str, nr: int, struct: c_data) -> Callable:
request = _IOC(_IOC_WRITE, ord(code), nr, _sizeof(struct))

def f(fileno, buffer):
Expand All @@ -108,7 +109,7 @@ def f(fileno, buffer):
return f


def _IOWR(code: str, nr: int, struct: type[Structure]) -> Callable:
def _IOWR(code: str, nr: int, struct: c_data) -> Callable:
request = _IOC(_IOC_READ | _IOC_WRITE, ord(code), nr, _sizeof(struct))

def f(fileno, buffer):
Expand Down

0 comments on commit c226c60

Please sign in to comment.