test_custom_type_setup.cpp
Go to the documentation of this file.
1 /*
2  tests/test_custom_type_setup.cpp -- Tests `pybind11::custom_type_setup`
3 
4  Copyright (c) Google LLC
5 
6  All rights reserved. Use of this source code is governed by a
7  BSD-style license that can be found in the LICENSE file.
8 */
9 
10 #include <pybind11/pybind11.h>
11 
12 #include "pybind11_tests.h"
13 
14 namespace py = pybind11;
15 
16 namespace {
17 
18 struct OwnsPythonObjects {
19  py::object value = py::none();
20 };
21 } // namespace
22 
23 TEST_SUBMODULE(custom_type_setup, m) {
24  py::class_<OwnsPythonObjects> cls(
25  m, "OwnsPythonObjects", py::custom_type_setup([](PyHeapTypeObject *heap_type) {
26  auto *type = &heap_type->ht_type;
27  type->tp_flags |= Py_TPFLAGS_HAVE_GC;
28  type->tp_traverse = [](PyObject *self_base, visitproc visit, void *arg) {
29  auto &self = py::cast<OwnsPythonObjects &>(py::handle(self_base));
30  Py_VISIT(self.value.ptr());
31  return 0;
32  };
33  type->tp_clear = [](PyObject *self_base) {
34  auto &self = py::cast<OwnsPythonObjects &>(py::handle(self_base));
35  self.value = py::none();
36  return 0;
37  };
38  }));
39  cls.def(py::init<>());
40  cls.def_readwrite("value", &OwnsPythonObjects::value);
41 }
Matrix3f m
TEST_SUBMODULE(custom_type_setup, m)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:37:45