Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Wiederhake, Tim" <tim.wiederhake@intel.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: "Jose E. Marchesi" <jose.marchesi@oracle.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: MemoryView missing from Python 2.4 and 2.6
Date: Tue, 28 Feb 2017 10:53:00 -0000	[thread overview]
Message-ID: <9676A094AF46E14E8265E7A3F4CCE9AF941DE1@irsmsx105.ger.corp.intel.com> (raw)
In-Reply-To: <86h93j7evn.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1027 bytes --]

Hi,

thank you for your patience.
I revisited option (2) and found that I could actually do without big code refactoring. See attached patch how this could look like. "memoryview" offers some functions and data members that "buffer" does not have, like information about the stride size, the number of dimensions and explicit conversion functions to "bytes" and "list". Since we always return a one-dimensional array of bytes, this information is not too useful and is probably bearable to miss in Python 2. Besides these differences, the behavior is the same in regard to indexing and iterating over the object.

Jose, can you confirm that this patch un-breaks GDB linked with Python 2.6?

Regards,
Tim
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

[-- Attachment #2: 0001-Fix-break-on-Python-2.patch --]
[-- Type: application/octet-stream, Size: 1707 bytes --]

From 1e3c5400b84af756f6bc596b626d773be7bebdeb Mon Sep 17 00:00:00 2001
From: Tim Wiederhake <tim.wiederhake@intel.com>
Date: Tue, 28 Feb 2017 09:10:58 +0100
Subject: [PATCH] Fix break on Python 2

This changes the return type of "gdb.BtraceInstruction.data ()" from
"memoryview" to "buffer" on Python 2.7 and below, similar to what
"gdb.Inferior.read_memory ()" does.

gdb/ChangeLog:

	* python/py-record-btrace.c (btpy_insn_data): Change return type
	for Python 2.

gdb/doc/ChangeLog:

	* python.texi (Recordings In Python): Document return type of
	gdb.BtraceInstruction.data.

---
 gdb/doc/python.texi           | 3 ++-
 gdb/python/py-record-btrace.c | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index c3ea203..b4a52bd 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3181,7 +3181,8 @@ if the instruction is a gap or the debug symbols could not be read.
 
 @defvar BtraceInstruction.data
 A buffer with the raw instruction data.  May be @code{None} if the
-instruction is a gap.
+instruction is a gap.  In Python 3, the return value is a @code{memoryview}
+object.
 @end defvar
 
 @defvar BtraceInstruction.decoded
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 6158f31..c816332 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -330,7 +330,12 @@ btpy_insn_data (PyObject *self, void *closure)
   if (object == NULL)
     return NULL;
 
+#ifdef IS_PY3K
   return PyMemoryView_FromObject (object);
+#else
+  return PyBuffer_FromObject (object, 0, Py_END_OF_BUFFER);
+#endif
+
 }
 
 /* Implementation of BtraceInstruction.decode [str].  Returns
-- 
2.7.4


  parent reply	other threads:[~2017-02-28 10:53 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-23 16:48 Jose E. Marchesi
2017-02-23 17:06 ` Jose E. Marchesi
2017-02-23 22:59 ` Yao Qi
2017-02-24 10:37   ` Wiederhake, Tim
2017-02-24 16:06     ` Yao Qi
2017-02-24 16:14       ` Paul.Koning
2017-02-28 10:53       ` Wiederhake, Tim [this message]
2017-02-28 12:51         ` Jose E. Marchesi
2017-03-07  0:21           ` Joel Brobecker
2017-03-07 13:38             ` Wiederhake, Tim
2017-03-07 15:27               ` Joel Brobecker
2017-03-03 10:21         ` Yao Qi
2017-03-06  8:56           ` Wiederhake, Tim
2017-03-07 10:32             ` Yao Qi
2017-03-07 17:18               ` Wiederhake, Tim
2017-03-17 15:59                 ` Yao Qi
2017-03-17 16:39                   ` Jose E. Marchesi
2017-03-20  9:04             ` Yao Qi
2017-03-20 22:44               ` Yao Qi

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=9676A094AF46E14E8265E7A3F4CCE9AF941DE1@irsmsx105.ger.corp.intel.com \
    --to=tim.wiederhake@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jose.marchesi@oracle.com \
    --cc=qiyaoltc@gmail.com \
    /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