From 804204db7cf1e8a28defd359d17fa72949e13eff Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 31 Aug 2026 23:05:16 +0200 Subject: Implement with ptrCast to make it more transparent. --- src/Dict.zig | 66 ------------------------------------------------------------ 1 file changed, 66 deletions(-) delete mode 100644 src/Dict.zig (limited to 'src/Dict.zig') diff --git a/src/Dict.zig b/src/Dict.zig deleted file mode 100644 index 89964cf..0000000 --- a/src/Dict.zig +++ /dev/null @@ -1,66 +0,0 @@ -const std = @import("std"); -const c = @import("c"); - -const zpy = @import("root.zig"); - -const Self = @This(); - -object: zpy.Object, - -pub const Key = union(enum) { - string: [*c]const u8, - object: zpy.Object, -}; - -pub fn new() zpy.Error!Self { - if (c.PyDict_New()) |object| { - return .{ .object = .fromPtr(object) }; - } - - return error.Exception; -} - -pub fn clear(self: *Self) void { - c.PyDict_Clear(self.object.ptr); -} - -pub fn contains(self: *const Self, key: Key) bool { - return switch (key) { - .string => |str| c.PyDict_ContainsString(self.object.ptr, str), - .object => |obj| c.PyDict_Contains(self.object.ptr, obj.ptr), - } == 1; -} - -pub fn copy(self: *const Self) Self { - return .{ .object = .fromPtr(c.PyDict_Copy(self.object.ptr)) }; -} - -pub fn set(self: *Self, key: Key, value: zpy.Object) !void { - const ret = switch (key) { - .string => |str| c.PyDict_SetItemString(self.object.ptr, str, value.ptr), - .object => |obj| c.PyDict_SetItem(self.object.ptr, obj.ptr, value.ptr), - }; - - if (ret == -1) return error.Exception; -} - -pub fn get(self: *const Self, key: Key) ?zpy.Object { - return .fromC(switch (key) { - .string => |str| c.PyDict_GetItemString(self.object.ptr, str), - .object => |obj| c.PyDict_GetItem(self.object.ptr, obj.ptr), - }); -} - -pub fn delete(self: *Self, key: Key) !void { - const ret = switch (key) { - .string => |str| c.PyDict_DelItemString(self.object.ptr, str), - .object => |obj| c.PyDict_DelItem(self.object.ptr, obj.ptr), - }; - - if (ret == -1) return error.Exception; -} - -pub fn deinit(self: *Self) void { - self.object.decref(); - self.* = undefined; -} -- cgit v1.2.3-70-g09d2