[binutils-gdb] Don't use template for gdbpy_ref_policy
Tom Tromey
tromey@sourceware.org
Wed Mar 4 18:44:03 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0d9faae86e6fadd0cae08fc29424551de458fefc
commit 0d9faae86e6fadd0cae08fc29424551de458fefc
Author: Tom Tromey <tom@tromey.com>
Date: Sat Feb 21 10:05:24 2026 -0700
Don't use template for gdbpy_ref_policy
Now that gdb's Python types derive from PyObject, there's no need to
use a template for gdbpy_ref_policy. This simplifies the code a tiny
bit.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Diff:
---
gdb/python/py-ref.h | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/gdb/python/py-ref.h b/gdb/python/py-ref.h
index 4ce7e29357d..0a56436634d 100644
--- a/gdb/python/py-ref.h
+++ b/gdb/python/py-ref.h
@@ -23,27 +23,23 @@
#include "gdbsupport/gdb_ref_ptr.h"
/* A policy class for gdb::ref_ptr for Python reference counting. */
-template<typename T>
struct gdbpy_ref_policy
{
- static_assert(std::is_base_of<PyObject, T>::value,
- "T must be a subclass of PyObject");
-
- static void incref (T *ptr)
+ static void incref (PyObject *ptr)
{
- Py_INCREF (static_cast<PyObject *> (ptr));
+ Py_INCREF (ptr);
}
- static void decref (T *ptr)
+ static void decref (PyObject *ptr)
{
- Py_DECREF (static_cast<PyObject *> (ptr));
+ Py_DECREF (ptr);
}
};
/* A gdb::ref_ptr that has been specialized for Python objects or
their "subclasses". */
template<typename T = PyObject> using gdbpy_ref
- = gdb::ref_ptr<T, gdbpy_ref_policy<T>>;
+ = gdb::ref_ptr<T, gdbpy_ref_policy>;
/* A wrapper class for Python extension objects that have a __dict__ attribute.
More information about the Gdb-cvs
mailing list