Skip to content
This repository was archived by the owner on Apr 3, 2026. It is now read-only.

Commit 97b6247

Browse files
committed
Fix hasAttrString and set PY_VECTORCALL_ARGUMENTS_OFFSET when doing vector calls
1 parent 0837052 commit 97b6247

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

py.zig

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,18 +418,22 @@ pub inline fn ObjectProtocol(comptime T: type) type {
418418
}
419419

420420
pub inline fn hasAttrString(self: *Object, attr: [:0]const u8) bool {
421-
return c.PyObject_HasAttr(@ptrCast(self), @ptrCast(attr)) == 0;
421+
return c.PyObject_HasAttrString(@ptrCast(self), @ptrCast(attr)) == 0;
422422
}
423423

424424
pub inline fn hasAttrWithError(self: *Object, attr: *Str) !bool {
425425
const r = c.PyObject_HasAttrWithError(@ptrCast(self), @ptrCast(attr));
426-
if (r < 0) return error.PyError;
426+
if (r < 0) {
427+
return error.PyError;
428+
}
427429
return r == 1;
428430
}
429431

430432
pub inline fn hasAttrStringWithError(self: *Object, attr: [:0]const u8) !bool {
431-
const r = c.PyObject_HasAttrWithError(@ptrCast(self), @ptrCast(attr));
432-
if (r < 0) return error.PyError;
433+
const r = c.PyObject_HasAttrStringWithError(@ptrCast(self), @ptrCast(attr));
434+
if (r < 0) {
435+
return error.PyError;
436+
}
433437
return r == 1;
434438
}
435439

@@ -637,7 +641,8 @@ pub inline fn ObjectProtocol(comptime T: type) type {
637641
return r != 0;
638642
}
639643

640-
// Calls PyObject_IsTrue on self. Same as isTrue but without error checking
644+
// Calls PyObject_IsTrue on self.
645+
// Same as evalsTrue but without error checking.
641646
// On failure, return -1.
642647
pub inline fn evalsTrueUnchecked(self: *T) c_int {
643648
return c.PyObject_IsTrue(@ptrCast(self));
@@ -653,7 +658,7 @@ pub inline fn ObjectProtocol(comptime T: type) type {
653658
return r != 0;
654659
}
655660

656-
// Calls PyObject_Not on self. Same as isNot but without error checking
661+
// Calls PyObject_Not on self. Same as evalsFalse but without error checking
657662
// On failure, return -1.
658663
pub inline fn evalsFalseUnchecked(self: *T) c_int {
659664
return c.PyObject_Not(@ptrCast(self));
@@ -784,7 +789,8 @@ pub inline fn CallProtocol(comptime T: type) type {
784789
inline for (args, 0..) |arg, i| {
785790
objs[i] = @ptrCast(arg);
786791
}
787-
break :blk c.PyObject_Vectorcall(@ptrCast(self), @ptrCast(&objs), objs.len, null);
792+
const nargsf = objs.len | c.PY_VECTORCALL_ARGUMENTS_OFFSET;
793+
break :blk c.PyObject_Vectorcall(@ptrCast(self), @ptrCast(&objs), nargsf, null);
788794
},
789795
});
790796
}
@@ -827,7 +833,8 @@ pub inline fn CallProtocol(comptime T: type) type {
827833
inline for (args, 1..) |arg, i| {
828834
objs[i] = @ptrCast(arg);
829835
}
830-
break :blk c.PyObject_VectorcallMethod(@ptrCast(name), @ptrCast(&objs), objs.len, null);
836+
const nargsf = objs.len | c.PY_VECTORCALL_ARGUMENTS_OFFSET;
837+
break :blk c.PyObject_VectorcallMethod(@ptrCast(name), @ptrCast(&objs), nargsf, null);
831838
},
832839
});
833840
}

0 commit comments

Comments
 (0)