public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Keith Seitz <keiths@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Environment variable convenience function
Date: Mon, 24 Apr 2023 14:53:53 +0300	[thread overview]
Message-ID: <83fs8pxzqm.fsf@gnu.org> (raw)
In-Reply-To: <20230423170755.1103121-1-keiths@redhat.com> (message from Keith Seitz via Gdb-patches on Sun, 23 Apr 2023 10:07:55 -0700)

> Date: Sun, 23 Apr 2023 10:07:55 -0700
> From: Keith Seitz via Gdb-patches <gdb-patches@sourceware.org>
> 
> This patch adds a new Python convenience function which simply
> returns the value of the given environment variable (or a default value)
> or throws a KeyError.
> 
> (gdb) p $_env("HOME")
> $1 = "/home/keiths"
> (gdb) p $_env("IS_THIS_USEFUL")
> Python Exception <class 'KeyError'>: 'IS_THIS_USEFUL'
> Error occurred in Python: 'IS_THIS_USEFUL'
> (gdb) p $_env("IS_THIS_USEFUL", "yes")
> $2 = "yes"
> ---
>  gdb/NEWS                            |  3 +++
>  gdb/data-directory/Makefile.in      |  1 +
>  gdb/doc/gdb.texinfo                 |  7 ++++++
>  gdb/python/lib/gdb/function/env.py  | 38 +++++++++++++++++++++++++++++
>  gdb/testsuite/gdb.base/default.exp  |  1 +
>  gdb/testsuite/gdb.python/py-env.c   | 22 +++++++++++++++++
>  gdb/testsuite/gdb.python/py-env.exp | 38 +++++++++++++++++++++++++++++
>  7 files changed, 110 insertions(+)
>  create mode 100644 gdb/python/lib/gdb/function/env.py
>  create mode 100644 gdb/testsuite/gdb.python/py-env.c
>  create mode 100644 gdb/testsuite/gdb.python/py-env.exp

Thanks.

> diff --git a/gdb/NEWS b/gdb/NEWS
> index 54b5da21245..4897b1e618b 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -156,6 +156,9 @@ info main
>       (program-counter) values, and can be used as the frame-id when
>       calling gdb.PendingFrame.create_unwind_info.
>  
> +  ** New Python-based convenience function $_env(name[, default]), which
> +     returns the string value of the environment variable of the given name.

This part is OK.

> +@findex $_env@r{, convenience function}
> +@item $_env(@var{name}@r{[}, @var{default}@r{]})
> +Return the value of the environment variable named @var{name}.
> +
> +If the variable is not defined in the environment, the optional default value
> +is returned, if specified, or a Python exception is thrown.

The last sentence abuses the passive voice, so I suggest to rephrase:

  If the variable @var{name} is not defined in the environment, the
  function returns the vale of the optional argument @var{default},
  and if that was not specified, it throws a Python exception.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>

  parent reply	other threads:[~2023-04-24 11:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-23 17:07 Keith Seitz
2023-04-23 20:20 ` Simon Marchi
2023-04-25 15:59   ` Keith Seitz
2023-04-25 18:56     ` Simon Marchi
2023-04-24 11:53 ` Eli Zaretskii [this message]
2023-04-25 16:02   ` Keith Seitz

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=83fs8pxzqm.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).