Awkward Array: include/awkward/python/util.h Source File

Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1// BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
2
3#ifndef AWKWARDPY_UTIL_H_
4#define AWKWARDPY_UTIL_H_
5
6#include <pybind11/pybind11.h>
7#include <pybind11/numpy.h>
8
27template<typename T>
28 class pyobject_deleter {
29public:
31 pyobject_deleter(PyObject *pyobj): pyobj_(pyobj) {
32 // std::cout << "pyobject INCREF of " << pyobj_ << std::endl;
33 Py_INCREF(pyobj_);
34 }
37 void operator()(T const *p) {
38 // std::cout << "pyobject DECREF of " << pyobj_ << std::endl;
39 Py_DECREF(pyobj_);
40 }
41private:
43 PyObject* pyobj_;
44};
45
46#endif // AWKWARDPY_UTIL_H_
pyobject_deleter
Used as a std::shared_ptr deleter (second argument) to overload delete ptr with Py_DECREF(ptr).
Definition: util.h:28
pyobject_deleter::pyobject_deleter
pyobject_deleter(PyObject *pyobj)
Creates a pyobject_deleter and calls Py_INCREF(ptr).
Definition: util.h:31
pyobject_deleter::operator()
void operator()(T const *p)
Called by std::shared_ptr when its reference count reaches zero.
Definition: util.h:37