public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Simon Marchi <simon.marchi@ericsson.com>
Cc: gdb-patches@sourceware.org, simon.marchi@polymtl.ca
Subject: Re: [PATCH 1/3] python extended prompt: Use os.getcwd() instead of os.getcwdu()
Date: Thu, 27 Nov 2014 09:00:00 -0000	[thread overview]
Message-ID: <20141127090037.GG5042@adacore.com> (raw)
In-Reply-To: <1416976561-1927-1-git-send-email-simon.marchi@ericsson.com>

> It seems like using os.getcwdu() here is wrong both for Python 2 and Python 3.
> 
> For Python 2, this returns a 'unicode' object, which tries to get concatenated
> to a 'str' object in substitute_prompt. The implicit conversion works when the
> unicode string contains no accent. When it does contain an accent though,
> displaying the prompt results in the following error:
> 
> (gdb) set extended-prompt \w
> ...
>   File "/home/simark/build/binutils-gdb-python2/gdb/data-directory/python/gdb/prompt.py", line 138, in substitute_prompt
>     result += str(cmd(arg))
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 49: ordinal not in range(128)
> 
> When using os.getcwd() instead, it works correctly. I suppose that Python does
> the necessary decoding internally.
> 
> For Python 3, this method simply does not exist. It works fine with os.getcwd().
> 
> gdb/ChangeLog:
> 
> 	* python/lib/gdb/prompt.py (_prompt_pwd): Use os.getcwd() instead of
> 	os.getcwdu().

I'd like to have other people's opinion on this, as I am not sure.

I _think_ that the patch is not making things worse for us,
while making things a little better in situations as the above.
So, based on that, I'd be inclined to apply it.

However, I think the long term fix would be, I believe, to switch
the entire thing to unicode. With Python3, it's automatic, but
with Python2, we might have to add 'u'-s on every piece of string
in the module, and also add some conversions here and there.
That's why I am thinking that the long term fix should be a blocker
for this patch.

Thoughts?

> ---
>  gdb/python/lib/gdb/prompt.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gdb/python/lib/gdb/prompt.py b/gdb/python/lib/gdb/prompt.py
> index d99f2ea..04adbfb 100644
> --- a/gdb/python/lib/gdb/prompt.py
> +++ b/gdb/python/lib/gdb/prompt.py
> @@ -21,7 +21,7 @@ import os
>  
>  def _prompt_pwd(ignore):
>      "The current working directory."
> -    return os.getcwdu()
> +    return os.getcwd()
>  
>  def _prompt_object_attr(func, what, attr, nattr):
>      """Internal worker for fetching GDB attributes."""
> -- 
> 2.1.3

-- 
Joel

  parent reply	other threads:[~2014-11-27  9:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26  4:36 Simon Marchi
2014-11-26  4:36 ` [PATCH 2/3] Fix Python help() test for Python 3 Simon Marchi
2014-11-27  8:47   ` Joel Brobecker
2014-11-28 15:57     ` Simon Marchi
2014-11-29 11:42       ` Joel Brobecker
2014-12-01 13:08         ` Simon Marchi
2014-11-26  4:36 ` [PATCH 3/3] Fix prints in tests " Simon Marchi
2014-11-27  8:40   ` Joel Brobecker
2014-11-28 16:40     ` Simon Marchi
2014-11-27  9:00 ` Joel Brobecker [this message]
2014-11-28 15:49   ` [PATCH 1/3] python extended prompt: Use os.getcwd() instead of os.getcwdu() Simon Marchi
2014-11-29 11:42     ` Joel Brobecker
2014-12-05 20:36       ` Simon Marchi
2014-12-15 16:41         ` 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=20141127090037.GG5042@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@ericsson.com \
    --cc=simon.marchi@polymtl.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).