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 }
TEST_SUBMODULE
TEST_SUBMODULE(custom_type_setup, m)
Definition: test_custom_type_setup.cpp:23
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
arg
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE ArgReturnType arg() const
Definition: ArrayCwiseUnaryOps.h:66
pybind11.h
pybind11_tests.h
pybind11
Definition: wrap/pybind11/pybind11/__init__.py:1
test_callbacks.value
value
Definition: test_callbacks.py:158


gtsam
Author(s):
autogenerated on Tue Jun 25 2024 03:05:28