Skip to content

Commit dd1dcfb

Browse files
committed
helper: created Fds class and its test. Moved timespec test.
1 parent fdcf86c commit dd1dcfb

7 files changed

Lines changed: 83 additions & 20 deletions

File tree

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Liburing (Work in Process...) [![Python](https://img.shields.io/badge/python-3.10--3.14-blue)](https://www.python.org/) [![Zig](https://img.shields.io/badge/zig-0.15.2-orange)](https://ziglang.org/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/liburing)] [![Test status](https://github.com/YoSTEALTH/Liburing/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/YoSTEALTH/Liburing/actions/workflows/test.yml)
1+
# Liburing
2+
[![Python](https://img.shields.io/badge/python-3.10--3.14-blue)](https://www.python.org/)
3+
[![Zig](https://img.shields.io/badge/zig-0.15.2-orange)](https://ziglang.org/)
4+
![PyPI - Downloads](https://img.shields.io/pypi/dm/liburing)
5+
[![Test status](https://github.com/YoSTEALTH/Liburing/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/YoSTEALTH/Liburing/actions/workflows/test.yml)
26

37
Liburing is Python + Zig wrapper around [C Liburing](https://github.com/axboe/Liburing), which is a helper to setup and tear-down io_uring instances.
48

@@ -29,23 +33,17 @@ python3 -m pip uninstall liburing # uninstall
2933
## To compile & install directly from GitHub
3034

3135
```bash
32-
# Note:
33-
# - Make sure you have Zig 0.15.2 installed on your system.
34-
# - Change bellow code to your Python setup.
35-
36-
python3 -m pip install --upgrade pyoz
36+
# note: make sure you have Zig 0.15.2 installed on your system.
3737

3838
cd /tmp
39-
4039
git clone --recurse-submodules https://github.com/YoSTEALTH/Liburing
41-
4240
cd Liburing
4341

42+
python3 -m pip install pyoz
4443
python3 -m pyoz build
45-
4644
python3 -m pip install dist/*.whl
4745

48-
# To Uninstall
46+
# uninstall
4947
python3 -m pip uninstall liburing pyoz
5048
```
5149

@@ -156,8 +154,8 @@ if __name__ == '__main__':
156154
- This project has been moved to using Zig as back-end, thus leading to breaking changes from previous release.
157155
- Try using latest Linux if possible to enable all `io_uring` features.
158156

159-
## Other Project
160-
<!-- - [Shakti](https://github.com/YoSTEALTH/Shakti) -->
157+
## Other Projects
158+
- [Shakti](https://github.com/YoSTEALTH/Shakti)
161159
- [PyOZ](https://pyoz.dev/)
162160

163161
## License

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .liburing,
3-
.version = "2026.3.7",
3+
.version = "2026.3.8",
44
.fingerprint = 0x26de882ff0030dfe,
55
.dependencies = .{
66
.PyOZ = .{

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "pyoz.backend"
66
name = "liburing"
77
readme = "README.md"
88
license = "CC0-1.0"
9-
version = "2026.3.7"
9+
version = "2026.3.8"
1010
authors = [{name="Ritesh"}]
1111
keywords = ["python", "socket", "async", "cython", "file", "python3", "io", "syscall", "futex", "statx",
1212
"io-uring", "uring", "liburing"]
@@ -53,7 +53,7 @@ module-name = "liburing"
5353
py-packages = ["liburing"]
5454

5555
# Optimization level for release builds: "Debug", "ReleaseSafe", "ReleaseFast", "ReleaseSmall"
56-
optimize = "ReleaseSafe"
56+
optimize = "Debug"
5757

5858
# Strip debug symbols in release builds
5959
# strip = true

src/liburing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from .version import * # noqa
33

44

5-
__version__ = "2026.3.7"
5+
__version__ = "2026.3.8"

src/liburing/class.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,15 @@ pub const SQE = extern struct {
320320
/// >>> sqe[1].user_data = 2
321321
///
322322
/// # *** MUST DO ***
323-
/// >>> if io_uring_put_sqe(ring, sqe):
323+
/// >>> if put_sqe(ring, sqe):
324324
/// ... io_uring_submit(ring)
325325
///
326326
///Note
327327
/// - This class has dual usage:
328328
/// 1. It works as a base class for `io_uring_get_sqe()` return.
329329
/// 2. It can also be used as `sqe = Sqe(<int>)`, rather than "get" sqe(s)
330330
/// you are going to "put" pre-made sqe(s) into the ring later. Refer to
331-
/// `help(io_uring_put_sqe)` to see more detail.
331+
/// `help(put_sqe)` to see more detail.
332332
/// - `Sqe(no)` is limited to max `0-255` items.
333333
pub const Sqe = extern struct {
334334
_parent: SQE,

src/liburing/helper.zig

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,56 @@ const std = @import("std");
66

77
const Timespec = @import("class.zig").Timespec;
88

9+
/// File Descriptors Holder
10+
///
11+
///Example
12+
/// >>> fds = liburing.Fds([-1, -1, 3])
13+
/// >>> fds[1]
14+
/// -1
15+
/// >>> fds.update([4, 5, 6])
16+
/// >>> fds[1]
17+
/// 5
18+
///
19+
///Note
20+
/// - Makes copy of the list provided.
21+
pub const Fds = extern struct {
22+
_fds: [*]i32,
23+
_len: usize,
24+
25+
const Self = @This();
26+
27+
pub fn __new__(list: oz.ListView(i32)) !Self {
28+
const _len = list.len();
29+
var fds = try std.heap.c_allocator.alloc(i32, _len);
30+
for (0.._len) |i| {
31+
if (list.get(i)) |fd| {
32+
fds[i] = fd;
33+
} else return error.TypeError;
34+
}
35+
return .{ ._fds = @ptrCast(fds), ._len = _len };
36+
}
37+
38+
pub fn __getitem__(self: *const Self, index: usize) !i32 {
39+
if (index < self._len) return self._fds[index];
40+
return error.IndexError;
41+
}
42+
43+
pub fn update(self: *Self, list: oz.ListView(i32)) !void {
44+
const _len = list.len();
45+
if (self._len != _len) return error.ValueError;
46+
47+
for (0.._len) |i| {
48+
if (list.get(i)) |fd| {
49+
self._fds[i] = fd;
50+
} else return error.ValueError;
51+
}
52+
}
53+
54+
pub fn __del__(self: *Self) void {
55+
std.heap.c_allocator.free(self._fds[0..self._len]);
56+
}
57+
};
58+
959
///Probe your system to find out which `io_uring` operations are available.
1060
///
1161
///Example
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
from pytest import raises
1+
import pytest
22
import liburing
33

44

5+
def test_fds():
6+
fds = liburing.Fds([-1, -1, 3])
7+
assert fds[1] == -1
8+
fds.update([4, 5, 6])
9+
assert fds[1] == 5
10+
11+
# error
12+
pytest.skip("PyOZ bug.")
13+
with pytest.raises(ValueError):
14+
fds.update([4, 5, 6, 7, 8, 9]) # PyOZ raises `RuntimeError: ValueError`
15+
16+
with pytest.raises(TypeError): # PyOZ raises `RuntimeError: TypeError`
17+
fds.update([4, 5, "s"])
18+
19+
520
def test_timespec():
621
ts = liburing.timespec(1)
722
assert ts.sec == 1
@@ -23,6 +38,6 @@ def test_timespec():
2338
assert ts.sec == 1
2439
assert ts.nsec == 500_000
2540

26-
with raises(MemoryError):
41+
with pytest.raises(MemoryError):
2742
ts = liburing.Timespec()
2843
assert ts.sec == 123

0 commit comments

Comments
 (0)