Skip to content

Commit dd42dff

Browse files
committed
Make py.clear accept **Object
1 parent b6d1010 commit dd42dff

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

py.zig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,17 @@ pub inline fn memoryError() ?*Object {
104104
return @ptrCast(c.PyErr_NoMemory());
105105
}
106106

107-
// Clear a reference *?*Object
107+
// Clear a reference to **Object or *?*Object
108+
// If pointer is to **Object it is set to undefined
108109
pub inline fn clear(obj: anytype) void {
109110
const T = @TypeOf(obj);
110-
comptime if (!canCastToOptionalObjectPtr(T)) {
111-
@compileError(std.fmt.comptimePrint("py.clear argument must be castable to *?*Object, got: {s}", .{@typeName(T)}));
112-
};
113-
xsetref(@ptrCast(obj), null);
111+
if (comptime canCastToOptionalObjectPtr(T)) {
112+
xsetref(@ptrCast(obj), null);
113+
} else if (comptime canCastToObjectPtr(T)) {
114+
setref(@ptrCast(obj), undefined);
115+
} else {
116+
@compileError(std.fmt.comptimePrint("py.clear argument must be castable to **Object or *?*Object, got: {s}", .{T}));
117+
}
114118
}
115119

116120
// Clear all

0 commit comments

Comments
 (0)