Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ caller imports it with no ignores.
snake_case without their type's name (`moq.TrackProducer.append_group`), and two types
whose names would match kept apart as Kotlin's are (`TokioConnect_Error`), as are
top-level names that clash. A keyword, a member Python gives every such class, or a
method named as a field takes a trailing `_`.
method named as a field takes a trailing `_`. A member or top-level name may be a
builtin's (`bytes`, `int`): the module reads each builtin through an alias (`_bytes`).
Constructors such as `new` stay static methods: `Counter.new(1)`.
- **Objects** are classes owning their handle, freed once their last reference goes,
which a call holds until it returns, so there is no `close()`. A `self` method, or
Expand Down
2 changes: 1 addition & 1 deletion ffi/fixtures/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl Clash {
}

/// Its bytes, its text's or its own.
pub fn raw(&self) -> Vec<u8> {
pub fn bytes(&self) -> Vec<u8> {
match self {
Clash::Bytes(b) => b.clone(),
Clash::String(s) => s.as_bytes().to_vec(),
Expand Down
12 changes: 6 additions & 6 deletions ffi/runtime/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class _n:
PENDING: object
PENDING: _object

class Object:
__slots__ = ()
Expand All @@ -15,23 +15,23 @@ class Value:
class Future:
__slots__ = ()

def poll(self, queue: _n.Queue, /) -> object: ...
def poll(self, queue: _n.Queue, /) -> _object: ...

def claim(self) -> int: ...
def claim(self) -> _int: ...

def close(self) -> None: ...

class Queue:
def __init__(self, loop: _asyncio.AbstractEventLoop, /) -> None: ...

def fileno(self) -> int: ...
def fileno(self) -> _int: ...

def take(self, read: bool, /) -> list[int]: ...
def take(self, read: _bool, /) -> _list[_int]: ...

class Node:
def __init__(self, queue: _n.Queue, /) -> None: ...

def token(self) -> int: ...
def token(self) -> _int: ...

def wake(self) -> None: ...

Expand Down
28 changes: 14 additions & 14 deletions ffi/runtime/rt.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class _Wakeup:
def __init__(self, loop: _asyncio.AbstractEventLoop) -> None:
self.queue = _n.Queue(loop)
# The future each parked poll waits on, and each `Waker`'s callback, by token.
self.parked: dict[int, _asyncio.Future[None]] = {}
self.wakers: dict[int, _typing.Callable[[], object]] = {}
self.parked: _dict[_int, _asyncio.Future[None]] = {}
self.wakers: _dict[_int, _typing.Callable[[], _object]] = {}
self.pump: _asyncio.Task[None] | None = None
fd = self.queue.fileno()
try:
loop.add_reader(fd, self.dispatch, True)
except NotImplementedError:
except _NotImplementedError:
# A proactor loop, Windows' default, reads only through its own calls.
sock = _socket.fromfd(fd, _socket.AF_INET if _sys.platform == "win32" else _socket.AF_UNIX, _socket.SOCK_STREAM)
sock.setblocking(False)
Expand All @@ -56,7 +56,7 @@ async def _pump(self, loop: _asyncio.AbstractEventLoop, sock: _socket.socket) ->
await loop.sock_recv(sock, 64)
self.dispatch(True)

def dispatch(self, read: bool) -> None:
def dispatch(self, read: _bool) -> None:
loop: _asyncio.AbstractEventLoop | None = None
for token in self.queue.take(read):
if token < 0:
Expand Down Expand Up @@ -103,7 +103,7 @@ class Waker:

_node: _n.Node | _n.Returned

def __init__(self, wake: _typing.Callable[[], object], loop: _asyncio.AbstractEventLoop | None = None) -> None:
def __init__(self, wake: _typing.Callable[[], _object], loop: _asyncio.AbstractEventLoop | None = None) -> None:
w = _wakeup(_get_running_loop() if loop is None else loop)
self._node = _n.Node(w.queue)
w.wakers[self._node.token()] = wake
Expand All @@ -126,22 +126,22 @@ def __init__(self, awaitable: _typing.Awaitable[None]) -> None:
self._loop = _get_running_loop()
# Refused at the call, before Rust takes it, rather than stranding Rust once started.
if not _inspect.isawaitable(awaitable):
raise TypeError(f"{type(awaitable).__name__} is not awaitable")
raise _TypeError(f"{_type(awaitable).__name__} is not awaitable")
if _asyncio.isfuture(awaitable) and awaitable.get_loop() is not self._loop:
raise ValueError("a future of another event loop")
raise _ValueError("a future of another event loop")
self._awaitable = awaitable
self._task: _asyncio.Future[None] | None = None
self._closed = False

def start(self, ended: _typing.Callable[[_asyncio.Future[None]], object]) -> None:
def start(self, ended: _typing.Callable[[_asyncio.Future[None]], _object]) -> None:
self._loop.call_soon_threadsafe(self._run, ended)

def _run(self, ended: _typing.Callable[[_asyncio.Future[None]], object]) -> None:
def _run(self, ended: _typing.Callable[[_asyncio.Future[None]], _object]) -> None:
if self._closed:
return
try:
self._task = _asyncio.ensure_future(self._awaitable, loop=self._loop)
except BaseException as e:
except _BaseException as e:
# `ended` aborts on it, as on a task that raised.
failed = self._loop.create_future()
failed.set_exception(e)
Expand Down Expand Up @@ -181,18 +181,18 @@ class ForeignReader(_typing.Protocol):
`SEEK_CUR`, or `SEEK_END` and returns the position from the start. An `OSError` either
raises fails Rust's read or seek with its message; any other exception aborts."""

def readinto(self, buffer: memoryview, /) -> int | None: ...
def readinto(self, buffer: _memoryview, /) -> _int | None: ...

def seek(self, offset: int, whence: int = 0, /) -> int: ...
def seek(self, offset: _int, whence: _int = 0, /) -> _int: ...


class _Const:
"""A constant a class names, made anew each time it is read, as Rust makes it."""

__slots__ = ("get",)

def __init__(self, get: _typing.Callable[[], object]) -> None:
def __init__(self, get: _typing.Callable[[], _object]) -> None:
self.get = get

def __get__(self, obj: object, cls: object = None) -> object:
def __get__(self, obj: _object, cls: _object = None) -> _object:
return self.get()
Loading