This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 1/4] Define unique_ptr specialization for Py_buffer
- From: Kevin Buettner <kevinb at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 18 Feb 2019 08:03:22 -0700
- Subject: [PATCH 1/4] Define unique_ptr specialization for Py_buffer
- References: <20190218075816.6f67f3d9@f29-4.lan>
This patch causes PyBuffer_Release() to be called when the associated
buffer goes out of scope. I've been using it as follows:
...
Py_buffer_up buffer_up;
Py_buffer py_buf;
if (PyObject_CheckBuffer (obj)
&& PyObject_GetBuffer (obj, &py_buf, PyBUF_SIMPLE) == 0)
{
/* Got a buffer, py_buf, out of obj. Cause it to released
when it goes out of scope. */
buffer_up.reset (&py_buf);
}
...
This snippet of code was taken directly from an upcoming patch to
python-value.c.
gdb/ChangeLog:
* python/python-internal.h (Py_buffer_deleter): New struct.
(Py_buffer_up): New typedef.
---
gdb/python/python-internal.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 3cb9ebc1ee..d11af83c8e 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -801,4 +801,17 @@ struct varobj;
struct varobj_iter *py_varobj_get_iterator (struct varobj *var,
PyObject *printer);
+/* Deleter for Py_buffer unique_ptr specialization. */
+
+struct Py_buffer_deleter
+{
+ void operator() (Py_buffer *b) const
+ {
+ PyBuffer_Release (b);
+ }
+};
+
+/* A unique_ptr specialization for Py_buffer. */
+typedef std::unique_ptr<Py_buffer, Py_buffer_deleter> Py_buffer_up;
+
#endif /* PYTHON_PYTHON_INTERNAL_H */