Define unique_ptr specialization for Py_buffer.
authorKevin Buettner <kevinb@redhat.com>
Sun, 17 Feb 2019 00:33:47 +0000 (17:33 -0700)
committerKevin Buettner <kevinb@redhat.com>
Tue, 26 Feb 2019 17:21:22 +0000 (10:21 -0700)
commit26c897821b37af894088ec5731f93dc82e79b6d4
treeb183358632ec4c6816525b0da8473c2f505f0f6c
parentc31307f9c5022205aaf2dff591457ac8b5c1342d
Define unique_ptr specialization for Py_buffer.

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/ChangeLog
gdb/python/python-internal.h