From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24915 invoked by alias); 27 Nov 2014 09:00:45 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 24904 invoked by uid 89); 27 Nov 2014 09:00:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 27 Nov 2014 09:00:43 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id CF61E116730; Thu, 27 Nov 2014 04:00:41 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 5ZDkIpwCS19x; Thu, 27 Nov 2014 04:00:41 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 6AC681166A8; Thu, 27 Nov 2014 04:00:41 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 781DB40F79; Thu, 27 Nov 2014 13:00:37 +0400 (RET) Date: Thu, 27 Nov 2014 09:00:00 -0000 From: Joel Brobecker To: Simon Marchi Cc: gdb-patches@sourceware.org, simon.marchi@polymtl.ca Subject: Re: [PATCH 1/3] python extended prompt: Use os.getcwd() instead of os.getcwdu() Message-ID: <20141127090037.GG5042@adacore.com> References: <1416976561-1927-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1416976561-1927-1-git-send-email-simon.marchi@ericsson.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2014-11/txt/msg00684.txt.bz2 > 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