Update copyright year range in all GDB files.
[deliverable/binutils-gdb.git] / gdb / python / py-ref.h
CommitLineData
a68ff33e
TT
1/* Python reference-holding class
2
b811d2c2 3 Copyright (C) 2016-2020 Free Software Foundation, Inc.
a68ff33e
TT
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
1a5c2598
TT
20#ifndef PYTHON_PY_REF_H
21#define PYTHON_PY_REF_H
a68ff33e 22
268a13a5 23#include "gdbsupport/gdb_ref_ptr.h"
a68ff33e 24
50315b21 25/* A policy class for gdb::ref_ptr for Python reference counting. */
7780f186 26template<typename T>
50315b21 27struct gdbpy_ref_policy
a68ff33e 28{
7780f186 29 static void incref (T *ptr)
a68ff33e 30 {
50315b21 31 Py_INCREF (ptr);
a68ff33e
TT
32 }
33
7780f186 34 static void decref (T *ptr)
a68ff33e 35 {
50315b21 36 Py_DECREF (ptr);
a68ff33e 37 }
a68ff33e
TT
38};
39
7780f186
TT
40/* A gdb::ref_ptr that has been specialized for Python objects or
41 their "subclasses". */
42template<typename T = PyObject> using gdbpy_ref
43 = gdb::ref_ptr<T, gdbpy_ref_policy<T>>;
a68ff33e 44
1a5c2598 45#endif /* PYTHON_PY_REF_H */
This page took 0.333408 seconds and 4 git commands to generate.