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")
48 Parent() {
py::print(
"Allocating parent."); }
49 Parent(
const Parent& parent) =
default;
50 ~Parent() {
py::print(
"Releasing parent."); }
51 void addChild(Child *) { }
52 Child *returnChild() {
return new Child(); }
53 Child *returnNullChild() {
return nullptr; }
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>());
65 #if !defined(PYPY_VERSION) 67 class ParentGC :
public Parent {
71 py::class_<ParentGC, Parent>(
m,
"ParentGC", py::dynamic_attr())
79 m.def(
"multiple_guards_correct_order", []() {
81 }, py::call_guard<CustomGuard, DependentGuard>());
83 m.def(
"multiple_guards_wrong_order", []() {
85 }, py::call_guard<DependentGuard, CustomGuard>());
87 #if defined(WITH_THREAD) && !defined(PYPY_VERSION) 90 auto report_gil_status = []() {
91 auto is_gil_held =
false;
93 is_gil_held = (tstate == PyGILState_GetThisThreadState());
95 return is_gil_held ?
"GIL held" :
"GIL released";
98 m.def(
"with_gil", report_gil_status);
99 m.def(
"without_gil", report_gil_status, py::call_guard<py::gil_scoped_release>());
void print(const Matrix &A, const string &s, ostream &stream)
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()