Skip to content

Commit 655db8a

Browse files
committed
Fix unit test, the code now holds more references
It cannot re-use the incoming tuple as before, because it is no longer a tuple at all. So a new tuple must be created, which then holds references for each member.
1 parent 893df5d commit 655db8a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

include/pybind11/pybind11.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ class cpp_function : public function {
13011301
* CPython itself implements the search this way, first comparing all pointers ... which is
13021302
* cheap and will work if the strings are interned. If it fails, then it falls back to a
13031303
* second lexicographic check. This is wildly expensive for huge argument lists, but those
1304-
* are incredably rare so we optimize for the vastly common case of just a couple of args.
1304+
* are incredibly rare so we optimize for the vastly common case of just a couple of args.
13051305
*/
13061306
auto n = PyTuple_GET_SIZE(haystack);
13071307
auto s = reinterpret_steal<pybind11::str>(PyUnicode_InternFromString(needle));

tests/test_kwargs_and_defaults.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ def test_args_refcount():
458458
assert refcount(myval) == expected
459459

460460
exp3 = refcount(myval, myval, myval)
461-
assert m.args_refcount(myval, myval, myval) == (exp3, exp3, exp3)
461+
# if we have to create a new tuple internally, then it will hold an extra reference for each item in it.
462+
assert m.args_refcount(myval, myval, myval) == (exp3 + 3, exp3 + 3, exp3 + 3)
462463
assert refcount(myval) == expected
463464

464465
# This function takes the first arg as a `py::object` and the rest as a `py::args`. Unlike the

0 commit comments

Comments
 (0)