public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simark@simark.ca>
Cc: gdb-patches@sourceware.org, Jan Vrany <jan.vrany@labware.com>
Subject: Re: [PATCHv5] gdb/python/mi: create MI commands using python
Date: Fri, 18 Mar 2022 16:12:43 +0000	[thread overview]
Message-ID: <20220318161243.GQ1212730@redhat.com> (raw)
In-Reply-To: <c423356e-96e4-a6dd-5329-5f3be27d7271@simark.ca>

* Simon Marchi <simark@simark.ca> [2022-03-18 11:06:43 -0400]:

> > +  /* Lookup the gdb.MICommand object in the dictionary of all Python MI
> > +     commands, this is gdb._mi_command, and remove it.  */
> > +  PyObject *curr = PyDict_GetItemWithError (mi_cmd_dict.get (),
> > +					    name_obj.get ());
> 
> This doesn't build with Python 2:
> 
> /home/simark/src/binutils-gdb/gdb/python/py-micmd.c: In function ‘int micmdpy_uninstall_command(micmdpy_object*)’:
> /home/simark/src/binutils-gdb/gdb/python/py-micmd.c:430:20: error: ‘PyDict_GetItemWithError’ was not declared in this scope; did you mean ‘PyDict_GetItemString’?
>   430 |   PyObject *curr = PyDict_GetItemWithError (mi_cmd_dict.get (),
>       |                    ^~~~~~~~~~~~~~~~~~~~~~~
>       |                    PyDict_GetItemString
> 

Simon,

After discussion on IRC, I believe you are working on a patch that
switches this code to make use of a C++ map (or some other
container).  If/when that patch is ready then that has my +1 as a
better solution.

However, just in case you don't have time for that, below is a work
around which I believe should be acceptable. I believe this patch is
OK only because I know that in a couple of weeks Py2 support is going
to be removed from master, so this work around would only live on in
the GDB 12 branch.

Comments welcome,

Thanks,
Andrew

---

commit 5ec0444e8312c17e628739ebd7b8f0e29df3c9e9
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Fri Mar 18 15:55:34 2022 +0000

    gdb: supply PyDict_GetItemWithError when compiling with Python2
    
    Commit
    
      commit 740b42ceb7c7ae7b5343183782973576a93bc7b3
      Date:   Tue Jun 23 14:45:38 2020 +0100
    
          gdb/python/mi: create MI commands using python
    
    Introduced a use of PyDict_GetItemWithError, which is not available in
    Python2, and so the Python2 build was broken.
    
    This commit provides a work around for this:
    
      #define PyDict_GetItemWithError PyDict_GetItem
    
    The arguments passed to these calls are identical, the difference is
    that the WithError version will return with an exception raised in
    some error cases, while the PyDict_GetItem suppresses some errors, and
    just returns nullptr.
    
    Given that we are almost at the GDB 12 branch point, this commit is
    the easiest change to get the Python2 build working again.  After GDB
    12 branches the plan is to remove Python2 support, so this #define
    will be removed anyway.
    
    As far as functionality I think this #define will be fine.  In the
    "normal" no error case, then obviously, everything will be fine.  The
    only difference is what happens when an error occurs.
    
    The only errors I think could happen if Python runs into problems
    hashing the string, or comparing the strings for equality.  Given the
    limited strings we're working with I don't expect that this should
    occur during normal operation.  So, my expectation is that this should
    only happen if they user has gone and messed around with this hash in
    some way - in which case I think it's OK if weird things happen.
    
    This issue was discussed on IRC, and I think Simon might be working on
    an alternative patch to remove the _mi_commands dictionary from the
    gdb module, in which case the use of PyDict_GetItemWithError will be
    removed completely.  I'm posting this just in case people want to
    consider a minimal work around for the breakage in the short term.

diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 083c4dbdbc3..e9f786ca61c 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -102,6 +102,9 @@
 #define PyString_Decode PyUnicode_Decode
 #define PyString_FromFormat PyUnicode_FromFormat
 #define PyString_Check PyUnicode_Check
+#else
+/* Until Python2 support is removed.  */
+#define PyDict_GetItemWithError PyDict_GetItem
 #endif
 
 /* If Python.h does not define WITH_THREAD, then the various


  reply	other threads:[~2022-03-18 16:12 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 12:44 [PATCH 0/5] create GDB/MI " Jan Vrany
2022-01-17 12:44 ` [PATCH 1/5] gdb/mi: introduce new class mi_command_builtin Jan Vrany
2022-01-17 12:44 ` [PATCH 2/5] gdb/python: create GDB/MI commands using python Jan Vrany
2022-02-06 16:52   ` Lancelot SIX
2022-01-17 12:44 ` [PATCH 3/5] gdb/python: allow redefinition of python GDB/MI commands Jan Vrany
2022-02-06 17:13   ` Lancelot SIX
2022-02-06 20:33     ` Simon Marchi
2022-02-06 20:44       ` Jan Vrany
2022-02-06 20:46         ` Simon Marchi
2022-02-07  9:46         ` Lancelot SIX
2022-01-17 12:44 ` [PATCH 4/5] gdb/testsuite: add tests for python-defined MI commands Jan Vrany
2022-01-17 12:44 ` [PATCH 5/5] gdb/python: document GDB/MI commands in Python Jan Vrany
2022-01-17 13:15   ` Eli Zaretskii
2022-01-17 13:20   ` Eli Zaretskii
2022-01-18 12:34     ` Jan Vrany
2022-01-18 15:09       ` Eli Zaretskii
2022-01-18 13:55 ` [PATCH 0/5] create GDB/MI commands using python Andrew Burgess
2022-01-18 15:13   ` Jan Vrany
2022-01-21 15:22     ` Andrew Burgess
2022-01-24 12:59       ` Jan Vrany
2022-02-02 16:57         ` Andrew Burgess
2022-02-06 21:16       ` Simon Marchi
2022-02-07 15:56         ` [PATCHv2] gdb/python/mi: create MI " Andrew Burgess
2022-02-08 15:16           ` Simon Marchi
2022-02-09 12:25             ` [PATCHv3] " Andrew Burgess
2022-02-09 14:08               ` Simon Marchi
2022-02-10 18:26                 ` Andrew Burgess
2022-02-13 14:27                   ` Joel Brobecker
2022-02-13 21:46                     ` Jan Vrany
2022-02-24 10:37               ` [PATCHv4] " Andrew Burgess
2022-02-25 19:22                 ` Tom Tromey
2022-02-25 19:31                   ` Jan Vrany
2022-02-28 16:48                 ` [PATCHv5] " Andrew Burgess
2022-02-28 18:40                   ` Tom Tromey
2022-03-13  4:47                   ` Joel Brobecker
2022-03-14 14:13                     ` Andrew Burgess
2022-03-16  8:10                       ` Joel Brobecker
2022-03-16 12:29                       ` Simon Marchi
2022-03-18 15:06                   ` Simon Marchi
2022-03-18 16:12                     ` Andrew Burgess [this message]
2022-03-18 19:57                       ` Simon Marchi

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=20220318161243.GQ1212730@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.vrany@labware.com \
    --cc=simark@simark.ca \
    /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).