From: Thiago Jung Bauermann <bauerman@br.ibm.com>
To: tromey@redhat.com
Cc: gdb ml <gdb@sourceware.org>
Subject: Re: [RFC] string handling in python
Date: Tue, 08 Jul 2008 05:31:00 -0000 [thread overview]
Message-ID: <1215495013.1795.79.camel@localhost.localdomain> (raw)
In-Reply-To: <m3prpp9srd.fsf@fleche.redhat.com>
On Mon, 2008-07-07 at 17:30 -0600, Tom Tromey wrote:
> >>>>> "Thiago" == Thiago Jung Bauermann <bauerman@br.ibm.com> writes:
>
> Thiago> So, in my opinion for GDB's Python bindings we should always
> Thiago> use Unicode strings, and convert to/from desired encodings as
> Thiago> necessary. Strings provided by the user would be assumed to
> Thiago> have host_charset () encoding, and strings coming from/going
> Thiago> to the inferior would be assumed to have target_charset ()
> Thiago> encoding.
>
> Sounds reasonable to me.
>
> I thought we already did some of this... search for host_charset in
> the python directory.
It doesn't really work. PyString_Decode transforms the string from
host_charset to unicode, and then from unicode to Python's default
charset (almost always ASCII). So if you have any non-ASCII character in
the string, Python won't even be able to print the string on screen. I
just made the test, by making valpy_str use PyString_Decode instead of
PyString_String:
(gdb) p s
$2 = 0x80484f0 "acentuação"
(gdb) py a = gdb.get_value_from_history (1)
(gdb) py print a
Traceback (most recent call last):
File "<string>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 17: ordinal not in range(128)
Oddly enough, if I use PyString_String then the example works. I'm not
sure why, though. Probably PyString_String doesn't try to convert back
and forth between charsets, and just prints the stream of bytes to the
screen hoping for the best...
> Thiago> So for example, to create a value object of char * type using
> Thiago> a string provided by the user or coming from Python code, GDB
> Thiago> would first convert the Python string object (assumed to be in
> Thiago> the host charset) to a unicode object (this process is called
> Thiago> "decoding", in python parlance), and then convert it from
> Thiago> unicode to a string in the target charset.
>
> This sounds like a good candidate for convenience functions, one for
> each direction.
Right, I'll add them.
--
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center
next prev parent reply other threads:[~2008-07-08 5:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-07 5:25 Thiago Jung Bauermann
2008-07-07 23:31 ` Tom Tromey
2008-07-08 5:31 ` Thiago Jung Bauermann [this message]
2008-07-08 5:35 ` Thiago Jung Bauermann
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=1215495013.1795.79.camel@localhost.localdomain \
--to=bauerman@br.ibm.com \
--cc=gdb@sourceware.org \
--cc=tromey@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