Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Matthieu Longo <matthieu.longo@arm.com>
Cc: <gdb-patches@sourceware.org>,  Tom Tromey <tom@tromey.com>
Subject: Re: [PATCH v2 4/6] gdb: new setters and getters for __dict__, and attributes
Date: Wed, 28 Jan 2026 11:00:11 -0700	[thread overview]
Message-ID: <87qzr98vo4.fsf@tromey.com> (raw)
In-Reply-To: <20260128120239.1959325-1-matthieu.longo@arm.com> (Matthieu Longo's message of "Wed, 28 Jan 2026 12:02:39 +0000")

>>>>> "Matthieu" == Matthieu Longo <matthieu.longo@arm.com> writes:

Matthieu> GDB is currently using the Python unlimited API. Migrating the codebase
Matthieu> to the Python limited API would have for benefit to make a GDB build
Matthieu> artifacts compatible with older and newer versions of Python that they
Matthieu> were built with.

Thanks again.

Matthieu> +  value = PyDict_GetItemWithError (dict.get (), attr);
Matthieu> +  if (value != nullptr)
Matthieu> +    return Py_NewRef (value);
Matthieu> +
Matthieu> +  /* PyDict_GetItemWithError() has a misleading name that lets one believe that
Matthieu> +     the function sets PyExc_AttributeError when the key is not found, whereas
Matthieu> +     it actually does not and only returns NULL.
Matthieu> +     Not setting the exception for an unfound key causes the raising of another
Matthieu> +     exception:
Matthieu> +       <class 'SystemError'>: error return without exception set
Matthieu> +     Hence this surprising manual setting of an exception to makes everything
Matthieu> +     fit into place.  */
Matthieu> +  PyErr_Format (PyExc_AttributeError,
Matthieu> +		"'%s' object has no attribute '%s'",
Matthieu> +		Py_TYPE (self)->tp_name,
Matthieu> +		PyUnicode_AsUTF8AndSize (attr, nullptr));


It seems to me that there should be an additional check between the call
to PyDict_GetItemWithError and PyErr_Format, like:

    if (PyErr_Occurred () != nullptr)
      return nullptr;

Since according to the PyDict_GetItemWithError docs, this function can
return null with the error set.

With that change the comment could probably be shortened a bit since
it's no longer surprising to have to set the exception.

Tom

  reply	other threads:[~2026-01-28 18:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-28 12:02 Matthieu Longo
2026-01-28 18:00 ` Tom Tromey [this message]
2026-01-29 10:42   ` Matthieu Longo
2026-01-29 14:45     ` Tom Tromey
  -- strict thread matches above, loose matches on Subject: below --
2026-01-27 17:02 [PATCH v2 0/6] gdb: minor fixes for Python limited C API support Matthieu Longo
2026-01-27 17:02 ` [PATCH v2 4/6] gdb: new setters and getters for __dict__, and attributes Matthieu Longo
2026-01-27 19:06   ` Tom Tromey
2026-01-28 11:57     ` Matthieu Longo
2026-01-28 17:43     ` Matthieu Longo
2026-01-28 17:51       ` Tom Tromey

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=87qzr98vo4.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=matthieu.longo@arm.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