18 static const char *
report_status() {
return enabled ?
"guarded" :
"unguarded"; }
28 static const char *
report_status() {
return enabled ?
"guarded" :
"unguarded"; }
38 Child() {
py::print(
"Allocating child."); }
39 Child(
const Child &) =
default;
40 Child(Child &&) =
default;
41 ~Child() {
py::print(
"Releasing child."); }
43 py::class_<Child>(
m,
"Child").def(py::init<>());
47 Parent() {
py::print(
"Allocating parent."); }
48 Parent(
const Parent &parent) =
default;
49 ~Parent() {
py::print(
"Releasing parent."); }
50 void addChild(Child *) {}
51 Child *returnChild() {
return new Child(); }
52 Child *returnNullChild() {
return nullptr; }
53 static Child *staticFunction(Parent *) {
return new Child(); }
55 py::class_<Parent>(
m,
"Parent")
57 .def(
py::init([](Child *) {
return new Parent(); }), py::keep_alive<1, 2>())
58 .def(
"addChild", &Parent::addChild)
59 .def(
"addChildKeepAlive", &Parent::addChild, py::keep_alive<1, 2>())
60 .def(
"returnChild", &Parent::returnChild)
61 .def(
"returnChildKeepAlive", &Parent::returnChild, py::keep_alive<1, 0>())
62 .def(
"returnNullChildKeepAliveChild", &Parent::returnNullChild, py::keep_alive<1, 0>())
63 .def(
"returnNullChildKeepAliveParent", &Parent::returnNullChild, py::keep_alive<0, 1>())
64 .def_static(
"staticFunction", &Parent::staticFunction, py::keep_alive<1, 0>());
67 "free_function", [](Parent *, Child *) {}, py::keep_alive<1, 2>());
69 "invalid_arg_index", [] {}, py::keep_alive<0, 1>());
71 #if !defined(PYPY_VERSION) 73 class ParentGC :
public Parent {
77 py::class_<ParentGC, Parent>(
m,
"ParentGC", py::dynamic_attr()).def(py::init<>());
85 "multiple_guards_correct_order",
90 py::call_guard<CustomGuard, DependentGuard>());
93 "multiple_guards_wrong_order",
98 py::call_guard<DependentGuard, CustomGuard>());
100 #if defined(WITH_THREAD) && !defined(PYPY_VERSION) 103 auto report_gil_status = []() {
104 auto is_gil_held =
false;
106 is_gil_held = (tstate == PyGILState_GetThisThreadState());
109 return is_gil_held ?
"GIL held" :
"GIL released";
112 m.def(
"with_gil", report_gil_status);
113 m.def(
"without_gil", report_gil_status, py::call_guard<py::gil_scoped_release>());
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
TEST_SUBMODULE(call_policies, m)
static const char * report_status()
static const char * report_status()
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
PyThreadState * get_thread_state_unchecked()