File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff 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
108109pub 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
You can’t perform that action at this time.
0 commit comments