Skip to content

Commit 0d95846

Browse files
committed
tests: one more int cast
Signed-off-by: Henry Schreiner <[email protected]>
1 parent f74d23a commit 0d95846

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

tests/test_kwargs_and_defaults.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
152152
// PyPy needs a garbage collection to get the reference count values to match CPython's behaviour
153153
#ifdef PYPY_VERSION
154154
# define GC_IF_NEEDED ConstructorStats::gc()
155+
# define REFCNT(x) (int) Py_REFCNT(x)
155156
#else
156157
# define GC_IF_NEEDED
158+
# define REFCNT(x) Py_REFCNT(x)
157159
#endif
158160
m.def("arg_refcount_h", [](py::handle h) {
159161
GC_IF_NEEDED;
@@ -172,7 +174,7 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
172174
py::tuple t(a.size());
173175
for (size_t i = 0; i < a.size(); i++) {
174176
// Use raw Python API here to avoid an extra, intermediate incref on the tuple item:
175-
t[i] = (int) Py_REFCNT(PyTuple_GET_ITEM(a.ptr(), static_cast<py::ssize_t>(i)));
177+
t[i] = REFCNT(PyTuple_GET_ITEM(a.ptr(), static_cast<py::ssize_t>(i)));
176178
}
177179
return t;
178180
});
@@ -182,7 +184,7 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
182184
t[0] = o.ref_count();
183185
for (size_t i = 0; i < a.size(); i++) {
184186
// Use raw Python API here to avoid an extra, intermediate incref on the tuple item:
185-
t[i + 1] = (int) Py_REFCNT(PyTuple_GET_ITEM(a.ptr(), static_cast<py::ssize_t>(i)));
187+
t[i + 1] = REFCNT(PyTuple_GET_ITEM(a.ptr(), static_cast<py::ssize_t>(i)));
186188
}
187189
return t;
188190
});

tests/test_kwargs_and_defaults.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ def test_args_refcount():
420420
# for the `py::args`; in the previous case, we could simply inc_ref and pass on Python's input
421421
# tuple without having to inc_ref the individual elements, but here we can't, hence the extra
422422
# refs.
423-
assert m.mixed_args_refcount(myval, myval, myval) == (exp3 + 3, exp3 + 3, exp3 + 3)
423+
exp3_3 = 2**32 - 1 if exp3 == 2**32 - 1 else exp3 + 3
424+
assert m.mixed_args_refcount(myval, myval, myval) == (exp3_3, exp3_3, exp3_3)
424425

425426
assert m.class_default_argument() == "<class 'decimal.Decimal'>"

0 commit comments

Comments
 (0)