Skip to content

Commit

Permalink
fix: delete all non-test uses of usingnamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
robbielyman committed Sep 22, 2024
1 parent dbe2291 commit f5977bd
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 197 deletions.
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

_ = b.addModule("xev", .{ .root_source_file = b.path("src/main.zig") });
_ = b.addModule("xev", .{ .root_source_file = b.path("src/lib.zig") });

const man_pages = b.option(
bool,
Expand Down Expand Up @@ -60,7 +60,7 @@ pub fn build(b: *std.Build) !void {
// we can easily run it manually without digging through the cache.
const test_exe = b.addTest(.{
.name = "xev-test",
.root_source_file = b.path("src/main.zig"),
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
});
Expand Down
2 changes: 1 addition & 1 deletion src/backend/epoll.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const posix = std.posix;
const queue = @import("../queue.zig");
const queue_mpsc = @import("../queue_mpsc.zig");
const heap = @import("../heap.zig");
const main = @import("../main.zig");
const main = @import("../lib.zig");
const xev = main.Epoll;
const ThreadPool = main.ThreadPool;

Expand Down
2 changes: 1 addition & 1 deletion src/backend/io_uring.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const assert = std.debug.assert;
const linux = std.os.linux;
const posix = std.posix;
const queue = @import("../queue.zig");
const xev = @import("../main.zig").IO_Uring;
const xev = @import("../lib.zig").IO_Uring;

pub const Loop = struct {
ring: linux.IoUring,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/iocp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = std.debug.assert;
const windows = @import("../windows.zig");
const queue = @import("../queue.zig");
const heap = @import("../heap.zig");
const xev = @import("../main.zig").IOCP;
const xev = @import("../lib.zig").IOCP;
const posix = std.posix;

const log = std.log.scoped(.libxev_iocp);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/kqueue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const posix = std.posix;
const queue = @import("../queue.zig");
const queue_mpsc = @import("../queue_mpsc.zig");
const heap = @import("../heap.zig");
const main = @import("../main.zig");
const main = @import("../lib.zig");
const xev = main.Kqueue;
const ThreadPool = main.ThreadPool;

Expand Down
2 changes: 1 addition & 1 deletion src/backend/wasi_poll.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const wasi = std.os.wasi;
const posix = std.posix;
const queue = @import("../queue.zig");
const heap = @import("../heap.zig");
const xev = @import("../main.zig").WasiPoll;
const xev = @import("../lib.zig").WasiPoll;

pub const Loop = struct {
pub const threaded = std.Target.wasm.featureSetHas(builtin.cpu.features, .atomics);
Expand Down
2 changes: 1 addition & 1 deletion src/c_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const xev = @import("main.zig");
const xev = @import("lib.zig");

export fn xev_loop_init(loop: *xev.Loop) c_int {
// TODO: overflow
Expand Down
2 changes: 1 addition & 1 deletion src/loop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const std = @import("std");
const assert = std.debug.assert;
const xev = @import("main.zig");
const xev = @import("lib.zig");

/// Common options across backends. Not all options apply to all backends.
/// Read the doc comment for individual fields to learn what backends they
Expand Down
174 changes: 0 additions & 174 deletions src/main.zig

This file was deleted.

16 changes: 14 additions & 2 deletions src/watcher/file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const builtin = @import("builtin");
const common = @import("common.zig");
const assert = std.debug.assert;
const posix = std.posix;
const main = @import("../main.zig");
const main = @import("../lib.zig");
const stream = @import("stream.zig");

/// File operations.
Expand Down Expand Up @@ -32,13 +32,25 @@ pub fn File(comptime xev: type) type {
/// The underlying file
fd: FdType,

pub usingnamespace stream.Stream(xev, Self, .{
const S = stream.Stream(xev, Self, .{
.close = true,
.read = .read,
.write = .write,
.threadpool = true,
});

pub const CloseError = S.CloseError;
pub const close = S.close;

pub const ReadError = S.ReadError;
pub const read = S.read;

pub const WriteError = S.WriteError;
pub const WriteQueue = S.WriteQueue;
pub const WriteRequest = S.WriteRequest;
pub const queueWrite = S.queueWrite;
pub const write = S.write;

/// Initialize a File from a std.fs.File.
pub fn init(file: std.fs.File) !Self {
return .{
Expand Down
40 changes: 32 additions & 8 deletions src/watcher/stream.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub const Options = struct {
};

/// Creates a stream type that is meant to be embedded within other
/// types using "usingnamespace". A stream is something that supports read,
/// types using "usingnamespace" (or by using its decls directly).
/// A stream is something that supports read,
/// write, close, etc. The exact operations supported are defined by the
/// "options" struct.
///
Expand All @@ -28,10 +29,21 @@ pub const Options = struct {
/// - decl named "initFd" to initialize a new T from a fd
///
pub fn Stream(comptime xev: type, comptime T: type, comptime options: Options) type {
const C = if (options.close) Closeable(xev, T, options);
const R = if (options.read != .none) Readable(xev, T, options);
const W = if (options.write != .none) Writeable(xev, T, options);
return struct {
pub usingnamespace if (options.close) Closeable(xev, T, options) else struct {};
pub usingnamespace if (options.read != .none) Readable(xev, T, options) else struct {};
pub usingnamespace if (options.write != .none) Writeable(xev, T, options) else struct {};
pub const CloseError = if (options.close) C.CloseError;
pub const close = if (options.close) C.close;

pub const ReadError = if (options.read != .none) R.ReadError;
pub const read = if (options.read != .none) R.read;

pub const WriteError = if (options.write != .none) W.WriteError;
pub const WriteQueue = if (options.write != .none) W.WriteQueue;
pub const WriteRequest = if (options.write != .none) W.WriteRequest;
pub const queueWrite = if (options.write != .none) W.queueWrite;
pub const write = if (options.write != .none) W.write;
};
}

Expand Down Expand Up @@ -258,7 +270,7 @@ pub fn Writeable(comptime xev: type, comptime T: type, comptime options: Options
// Initialize our completion
req.* = .{ .full_write_buffer = buf };
// Must be kept in sync with partial write logic inside the callback
self.write_init(&req.completion, buf);
write_init(self, &req.completion, buf);
req.completion.userdata = q;
req.completion.callback = (struct {
fn callback(
Expand Down Expand Up @@ -289,7 +301,7 @@ pub fn Writeable(comptime xev: type, comptime T: type, comptime options: Options
if (written_len < queued_len) {
// Write remainder of the buffer, reusing the same completion
const rem_buf = writeBufferRemainder(cb_res.buf, written_len);
cb_res.writer.write_init(&req_inner.completion, rem_buf);
write_init(cb_res.writer, &req_inner.completion, rem_buf);
req_inner.completion.userdata = q_inner;
req_inner.completion.callback = callback;
l_inner.add(&req_inner.completion);
Expand Down Expand Up @@ -364,7 +376,7 @@ pub fn Writeable(comptime xev: type, comptime T: type, comptime options: Options
r: WriteError!usize,
) xev.CallbackAction,
) void {
self.write_init(c, buf);
write_init(self, c, buf);
c.userdata = userdata;
c.callback = (struct {
fn callback(
Expand Down Expand Up @@ -508,12 +520,24 @@ pub fn GenericStream(comptime xev: type) type {
/// The underlying file
fd: std.posix.fd_t,

pub usingnamespace Stream(xev, Self, .{
const S = Stream(xev, Self, .{
.close = true,
.read = .read,
.write = .write,
});

pub const CloseError = S.CloseError;
pub const close = S.close;

pub const ReadError = S.ReadError;
pub const read = S.read;

pub const WriteError = S.WriteError;
pub const WriteQueue = S.WriteQueue;
pub const WriteRequest = S.WriteRequest;
pub const queueWrite = S.queueWrite;
pub const write = S.write;

/// Initialize a generic stream from a file descriptor.
pub fn initFd(fd: std.posix.fd_t) Self {
return .{
Expand Down
Loading

0 comments on commit f5977bd

Please sign in to comment.