From patchwork Mon Feb 18 15:03:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 31499 Received: (qmail 20418 invoked by alias); 18 Feb 2019 15:03:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 20360 invoked by uid 89); 18 Feb 2019 15:03:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*M:lan X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 18 Feb 2019 15:03:24 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8126C10FAE for ; Mon, 18 Feb 2019 15:03:23 +0000 (UTC) Received: from f29-4.lan (ovpn-117-11.phx2.redhat.com [10.3.117.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 590E61001944 for ; Mon, 18 Feb 2019 15:03:23 +0000 (UTC) Date: Mon, 18 Feb 2019 08:03:22 -0700 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH 1/4] Define unique_ptr specialization for Py_buffer Message-ID: <20190218080322.252e36d7@f29-4.lan> In-Reply-To: <20190218075816.6f67f3d9@f29-4.lan> References: <20190218075816.6f67f3d9@f29-4.lan> MIME-Version: 1.0 X-IsSubscribed: yes 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_up; + #endif /* PYTHON_PYTHON_INTERNAL_H */