Compare commits

...

4 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve
f3ada134b4
Merge 89771bbc05 into 83b92ceb35 2024-11-20 21:39:27 +08:00
Michael Šimáček
83b92ceb35
Try to fix reentrant write transient failures in tests (#5447)
* Disable print_destroyed in tests on GraalPy

* Reenable test_iostream on GraalPy
2024-11-18 14:39:59 -08:00
pre-commit-ci[bot]
89771bbc05 style: pre-commit fixes 2024-10-12 19:10:20 +00:00
Ralf W. Grosse-Kunstleve
f40ffc0262
type_caster_incomplete_type sketch 2024-10-12 12:06:16 -07:00
5 changed files with 67 additions and 6 deletions

View File

@ -149,6 +149,7 @@ set(PYBIND11_TEST_FILES
test_stl_binders test_stl_binders
test_tagbased_polymorphic test_tagbased_polymorphic
test_thread test_thread
test_type_caster_incomplete_type
test_type_caster_pyobject_ptr test_type_caster_pyobject_ptr
test_type_caster_std_function_specializations test_type_caster_std_function_specializations
test_union test_union

View File

@ -312,8 +312,16 @@ void print_created(T *inst, Values &&...values) {
} }
template <class T, typename... Values> template <class T, typename... Values>
void print_destroyed(T *inst, Values &&...values) { // Prints but doesn't store given values void print_destroyed(T *inst, Values &&...values) { // Prints but doesn't store given values
/*
* On GraalPy, destructors can trigger anywhere and this can cause random
* failures in unrelated tests.
*/
#if !defined(GRAALVM_PYTHON)
print_constr_details(inst, "destroyed", values...); print_constr_details(inst, "destroyed", values...);
track_destroyed(inst); track_destroyed(inst);
#else
py::detail::silence_unused_warnings(inst, values...);
#endif
} }
template <class T, typename... Values> template <class T, typename... Values>
void print_values(T *inst, Values &&...values) { void print_values(T *inst, Values &&...values) {

View File

@ -6,14 +6,8 @@ from io import StringIO
import pytest import pytest
import env # noqa: F401
from pybind11_tests import iostream as m from pybind11_tests import iostream as m
pytestmark = pytest.mark.skipif(
"env.GRAALPY",
reason="Delayed prints from finalizers from other tests can end up in the output",
)
def test_captured(capsys): def test_captured(capsys):
msg = "I've been redirected to Python, I hope!" msg = "I've been redirected to Python, I hope!"

View File

@ -0,0 +1,47 @@
#include "pybind11_tests.h"
namespace test_type_caster_incomplete_type {
struct ForwardDeclaredType {};
} // namespace test_type_caster_incomplete_type
using ForwardDeclaredType = test_type_caster_incomplete_type::ForwardDeclaredType;
// TODO: Move to pybind11/type_caster_incomplete_type.h, wrap in a macro.
namespace pybind11 {
namespace detail {
template <>
class type_caster<ForwardDeclaredType> {
public:
static constexpr auto name = const_name("object");
static handle
cast(ForwardDeclaredType * /*src*/, return_value_policy /*policy*/, handle /*parent*/) {
return py::none().release(); // TODO: Build and return capsule with src pointer;
}
bool load(handle /*src*/, bool /*convert*/) {
// TODO: Assign pointer_capsule = src after inspecting src.
return true;
}
template <typename T>
using cast_op_type = ForwardDeclaredType *;
explicit operator ForwardDeclaredType *() {
return nullptr; // TODO: Retrieve C++ pointer from pointer_capsule.
}
private:
capsule pointer_capsule;
};
} // namespace detail
} // namespace pybind11
TEST_SUBMODULE(type_caster_incomplete_type, m) {
m.def("rtrn_fwd_decl_type_ptr", []() { return reinterpret_cast<ForwardDeclaredType *>(0); });
m.def("pass_fwd_decl_type_ptr", [](ForwardDeclaredType *) {});
}

View File

@ -0,0 +1,11 @@
from __future__ import annotations
from pybind11_tests import type_caster_incomplete_type as m
def test_rtrn_fwd_decl_type_ptr():
assert m.rtrn_fwd_decl_type_ptr() is None
def test_pass_fwd_decl_type_ptr():
assert m.pass_fwd_decl_type_ptr(None) is None