From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 1/4] Define unique_ptr specialization for Py_buffer
Date: Tue, 19 Feb 2019 21:39:00 -0000 [thread overview]
Message-ID: <20190219143917.5a1694b3@f29-4.lan> (raw)
In-Reply-To: <20190219143356.1576e67f@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 */
next prev parent reply other threads:[~2019-02-19 21:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-19 21:34 [PATCH v2 0/4] Define gdb.Value(val, type) constructor Kevin Buettner
2019-02-19 21:39 ` Kevin Buettner [this message]
2019-02-19 21:42 ` [PATCH v2 2/4] Define gdb.Value(bufobj, " Kevin Buettner
2019-02-20 3:43 ` Simon Marchi
2019-02-20 18:03 ` Tom Tromey
2019-02-26 17:34 ` Kevin Buettner
2019-02-19 21:43 ` [PATCH v2 3/4] Add tests for " Kevin Buettner
2019-02-19 21:46 ` [PATCH v2 4/4] Document two argument form of gdb.Value constructor Kevin Buettner
2019-02-20 3:35 ` Eli Zaretskii
2019-02-26 17:35 ` [PATCH v2 0/4] Define gdb.Value(val, type) constructor Kevin Buettner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190219143917.5a1694b3@f29-4.lan \
--to=kevinb@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).