Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fbd0e54
Move data type check to wrapper functions
JukkaL Oct 21, 2025
934c091
Update stubs
JukkaL Oct 21, 2025
2283ef9
Split Buffer into WriteBuffer and ReadBuffer
JukkaL Oct 21, 2025
94e116b
Update test case
JukkaL Oct 21, 2025
20e7df4
Update more tests
JukkaL Oct 21, 2025
a5069a8
Fix stubs
JukkaL Oct 21, 2025
0eb8639
Simlify
JukkaL Oct 21, 2025
3118407
Fix growing the buffer
JukkaL Oct 21, 2025
31773bf
WIP benchmark
JukkaL Oct 21, 2025
ad02c93
Optimize API calls
JukkaL Oct 21, 2025
4c3f219
Run 10x more iterations
JukkaL Oct 21, 2025
7695140
Update benchmark
JukkaL Oct 21, 2025
1297eb3
Update API len
JukkaL Nov 3, 2025
45695d9
Fix after rebase
JukkaL Nov 3, 2025
f97cc7c
Fix test case to use ReadBuffer
JukkaL Nov 3, 2025
3eaa989
Fix irbuild test case to use WriteBuffer_internal
JukkaL Nov 3, 2025
4fb6b1f
Fix run test to use WriteBuffer/ReadBuffer consistently
JukkaL Nov 3, 2025
e1311be
Fix WriteBuffer writes in C lib
JukkaL Nov 3, 2025
e4d0c03
Bump ABI version
JukkaL Nov 6, 2025
84b6a70
Provide access to the type objects via API
JukkaL Nov 6, 2025
c74f01d
Perform runtime type checks
JukkaL Nov 6, 2025
2492712
Revert benchmark related changes
JukkaL Nov 6, 2025
906bd71
Test arg checking when calling via wrapper functions
JukkaL Nov 6, 2025
b1b1d9b
Fix stub
JukkaL Nov 6, 2025
a568b9c
Hacky support in stub for both the old and new APIs
JukkaL Nov 6, 2025
2e33147
Minor fixes
JukkaL Nov 6, 2025
b9ffa18
Minor optimization
JukkaL Nov 6, 2025
f7469dd
Actually run the tests
JukkaL Nov 10, 2025
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
32 changes: 20 additions & 12 deletions mypy/typeshed/stubs/librt/librt/internal.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
from mypy_extensions import u8

# TODO: Remove Buffer -- right now we have hacky support for BOTH the old and new APIs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will we be able to remove it? Right after the new version of librt is published, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.


class Buffer:
def __init__(self, source: bytes = ...) -> None: ...
def getvalue(self) -> bytes: ...

def write_bool(data: Buffer, value: bool) -> None: ...
def read_bool(data: Buffer) -> bool: ...
def write_str(data: Buffer, value: str) -> None: ...
def read_str(data: Buffer) -> str: ...
def write_bytes(data: Buffer, value: bytes) -> None: ...
def read_bytes(data: Buffer) -> bytes: ...
def write_float(data: Buffer, value: float) -> None: ...
def read_float(data: Buffer) -> float: ...
def write_int(data: Buffer, value: int) -> None: ...
def read_int(data: Buffer) -> int: ...
def write_tag(data: Buffer, value: u8) -> None: ...
def read_tag(data: Buffer) -> u8: ...
class ReadBuffer:
def __init__(self, source: bytes) -> None: ...

class WriteBuffer:
def getvalue(self) -> bytes: ...

def write_bool(data: WriteBuffer | Buffer, value: bool) -> None: ...
def read_bool(data: ReadBuffer | Buffer) -> bool: ...
def write_str(data: WriteBuffer | Buffer, value: str) -> None: ...
def read_str(data: ReadBuffer | Buffer) -> str: ...
def write_bytes(data: WriteBuffer | Buffer, value: bytes) -> None: ...
def read_bytes(data: ReadBuffer | Buffer) -> bytes: ...
def write_float(data: WriteBuffer | Buffer, value: float) -> None: ...
def read_float(data: ReadBuffer | Buffer) -> float: ...
def write_int(data: WriteBuffer | Buffer, value: int) -> None: ...
def read_int(data: ReadBuffer | Buffer) -> int: ...
def write_tag(data: WriteBuffer | Buffer, value: u8) -> None: ...
def read_tag(data: ReadBuffer | Buffer) -> u8: ...
def cache_version() -> u8: ...
14 changes: 13 additions & 1 deletion mypyc/codegen/emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,25 @@ def emit_cast(
self.emit_lines(f" {dest} = {src};", "else {")
self.emit_cast_error_handler(error, src, dest, typ, raise_exception)
self.emit_line("}")
elif is_object_rprimitive(typ) or is_native_rprimitive(typ):
elif is_object_rprimitive(typ):
if declare_dest:
self.emit_line(f"PyObject *{dest};")
self.emit_arg_check(src, dest, typ, "", optional)
self.emit_line(f"{dest} = {src};")
if optional:
self.emit_line("}")
elif is_native_rprimitive(typ):
# Native primitive types have type check functions of form "CPy<Name>_Check(...)".
if declare_dest:
self.emit_line(f"PyObject *{dest};")
short_name = typ.name.rsplit(".", 1)[-1]
check = f"(CPy{short_name}_Check({src}))"
if likely:
check = f"(likely{check})"
self.emit_arg_check(src, dest, typ, check, optional)
self.emit_lines(f" {dest} = {src};", "else {")
self.emit_cast_error_handler(error, src, dest, typ, raise_exception)
self.emit_line("}")
elif isinstance(typ, RUnion):
self.emit_union_cast(
src, dest, typ, declare_dest, error, optional, src_type, raise_exception
Expand Down
2 changes: 1 addition & 1 deletion mypyc/ir/rtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def __hash__(self) -> int:

KNOWN_NATIVE_TYPES: Final = {
name: RPrimitive(name, is_unboxed=False, is_refcounted=True)
for name in ["librt.internal.Buffer"]
for name in ["librt.internal.WriteBuffer", "librt.internal.ReadBuffer"]
}


Expand Down
Loading
Loading