diff --git a/clif/python/stltypes.h b/clif/python/stltypes.h index a0398782..13b0f333 100644 --- a/clif/python/stltypes.h +++ b/clif/python/stltypes.h @@ -338,6 +338,11 @@ inline Py_ssize_t ArgIn(PyObject**, Py_ssize_t idx, const py::PostConv&) { return idx; } +// NOTE: This forward declaration is CRITICAL (see b/282776731#comment6). +template +Py_ssize_t ArgIn(PyObject** a, Py_ssize_t idx, const py::PostConv& pc, + PyObject* c1, T&&... c); + template Py_ssize_t ArgIn(PyObject** a, Py_ssize_t idx, const py::PostConv& pc, T1&& c1, T&&... c) { diff --git a/clif/testing/python/pyobject_ptr_test.py b/clif/testing/python/pyobject_ptr_test.py index 8922c8be..09c91910 100644 --- a/clif/testing/python/pyobject_ptr_test.py +++ b/clif/testing/python/pyobject_ptr_test.py @@ -93,7 +93,7 @@ def cb(pvh): self.assertEqual(cc(cb_guarded, PyValueHolder(3.0)).value, -123) self.assertIn("ValueError: Unknown pvh.value: 3.0", sio.getvalue()) - def test_call_callback_with_pyobject_ptr_int_args(self): + def test_call_callback_with_pyobject_ptr_int_args_temporary_arg(self): def cb(pvh, num): return tst.CppValueHolder(pvh.value * 10 + num) @@ -101,7 +101,16 @@ def cb(pvh, num): for _ in range(1000): self.assertEqual(cc(cb, PyValueHolder(30)).value, 340) - def test_call_callback_with_int_pyobject_ptr_args(self): + def test_call_callback_with_pyobject_ptr_int_args_named_arg(self): + def cb(pvh, num): + return tst.CppValueHolder(pvh.value * 10 + num) + + cc = tst.call_callback_with_pyobject_ptr_int_args + value_holder = PyValueHolder(30) + for _ in range(1000): + self.assertEqual(cc(cb, value_holder).value, 340) + + def test_call_callback_with_int_pyobject_ptr_args_temporary_arg(self): def cb(num, pvh): return tst.CppValueHolder(num * 20 + pvh.value) @@ -109,6 +118,15 @@ def cb(num, pvh): for _ in range(1000): self.assertEqual(cc(cb, PyValueHolder(60)).value, 1060) + def test_call_callback_with_int_pyobject_ptr_args_named_arg(self): + def cb(num, pvh): + return tst.CppValueHolder(num * 20 + pvh.value) + + cc = tst.call_callback_with_int_pyobject_ptr_args + value_holder = PyValueHolder(60) + for _ in range(1000): + self.assertEqual(cc(cb, value_holder).value, 1060) + if __name__ == "__main__": absltest.main()