Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Matthieu Longo <matthieu.longo@arm.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v1 3/4] gdb/python: migrate Python initialization to use the new config API (PEP 741)
Date: Fri, 24 Apr 2026 10:41:06 +0100	[thread overview]
Message-ID: <04df72d5-14aa-40f4-ac17-79df1b1e8421@arm.com> (raw)
In-Reply-To: <87v7dpshv2.fsf@tromey.com>

On 17/04/2026 16:53, Tom Tromey wrote:
>>>>>> "Matthieu" == Matthieu Longo <matthieu.longo@arm.com> writes:
> 
> Matthieu> +  PyInitConfig *m_config;
> Matthieu> +  bool m_err;
> Matthieu> +  bool m_py_initialized;
> 
> These last two can just say '= false'
> 

Fixed.

> Matthieu> +};
> Matthieu> +
> Matthieu> +gdb_PyInitializer::gdb_PyInitializer ()
> Matthieu> +  : m_config (PyInitConfig_Create ()),
> Matthieu> +    m_err (false),
> Matthieu> +    m_py_initialized (false)
> 
> ... then they don't have to be initialized here.
> 
> Matthieu> +{
> Matthieu> +  if (m_config == nullptr)
> Matthieu> +  {
> Matthieu> +    throw_error (GENERIC_ERROR,
> Matthieu> +		 _("Python initialization failed: memory allocation failed"));
> 
> No need for the braces.  Also this can just be error (...), throw_error
> is normally only for special things.
> 

How is it supposed to work with error() ?
error() calls exit(EXIT_FAILURE).

It seems to me that throw_error is needed here, otherwise the code in ...

> Matthieu> +  const char *err_msg;
> Matthieu> +  if (PyInitConfig_GetError (m_config, &err_msg) == 1)
> Matthieu> +    throw_error (GENERIC_ERROR,
> Matthieu> +		 _("Python initialization failed: %s"),
> Matthieu> +		 err_msg);
> Matthieu> +
> Matthieu> +  int exit_code;
> Matthieu> +  gdb_assert (PyInitConfig_GetExitCode (m_config, &exit_code) != 0);
> 
> Can't combine a side effect with an assert here.
> 

Fixed.

> Matthieu> +  throw_error (GENERIC_ERROR,
> Matthieu> +	       _("Python initialization failed with exit status: %d"),
> Matthieu> +	       exit_code);
> 
> Also same here about error; and does this code need to clear the Python
> error or anything like that?
> 

In my understanding, the error should not be cleared.
The doc (https://docs.python.org/3/c-api/init_config.html#c.PyInitConfig_GetError) says:
   The error message remains valid until another PyInitConfig function is
   called with config. The caller doesn’t have to free the error message.

> Matthieu> +  catch (const gdb_exception_error &exc)
> Matthieu> +  {
> Matthieu> +    gdb_printf ("%s\n", exc.what ());
> 
> Use exception_print instead, probably with gdb_stderr.
> 

... here is irrelevant.

Am I misunderstanding something ?

> thanks,
> Tom

Matthieu

  reply	other threads:[~2026-04-24  9:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-09 10:51 [PATCH v1 0/4] gdb/python: more fixes again for Python limited C API support Matthieu Longo
2026-04-09 10:51 ` [PATCH v1 1/4] gdb/python: add gdbpy_borrowed_ref Matthieu Longo
2026-04-17 15:40   ` Tom Tromey
2026-04-23 17:31     ` Matthieu Longo
2026-04-09 10:51 ` [PATCH v1 2/4] gdb/python: eval_python_command returns both exit code and result Matthieu Longo
2026-04-17 17:22   ` Tom Tromey
2026-04-23 19:11     ` Matthieu Longo
2026-04-09 10:51 ` [PATCH v1 3/4] gdb/python: migrate Python initialization to use the new config API (PEP 741) Matthieu Longo
2026-04-17 15:53   ` Tom Tromey
2026-04-24  9:41     ` Matthieu Longo [this message]
2026-04-24 14:56       ` Tom Tromey
2026-04-27 15:12         ` Matthieu Longo
2026-04-28 14:44           ` Tom Tromey
2026-04-09 10:51 ` [PATCH v1 4/4] gdb/python: work around missing symbols not yet part of Python limited API Matthieu Longo
2026-04-17 17:26   ` Tom Tromey
2026-04-24 10:14     ` Matthieu Longo
2026-04-15  9:18 ` [PATCH v1 0/4] gdb/python: more fixes again for Python limited C API support Matthieu Longo

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=04df72d5-14aa-40f4-ac17-79df1b1e8421@arm.com \
    --to=matthieu.longo@arm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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