This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Python pretty-printers and non-ASCII strings do not play well together :-(
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: archer at sourceware dot org
- Cc: ppluzhnikov at google dot com
- Date: Tue, 4 Nov 2008 11:28:34 -0800 (PST)
- Subject: Python pretty-printers and non-ASCII strings do not play well together :-(
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta;t=1225826918; bh=aM9mKVhYhPdzJ3keP3Jb2dU/To8=;h=DomainKey-Signature:To:CC:Subject:MIME-version:Content-type: Content-Transfer-Encoding:Message-Id:Date:From; b=oNa7tunqIqoYBJ6AdswCDo3OdLDkuPG5fW3DZ5gwhGGBbbCKE2NJYaPovexOk7Mxiv/z+aCdsY6Ys9RKuyNEdA==
- Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns;h=to:cc:subject:mime-version:content-type:content-transfer-encoding:message-id:date:from;b=cbteHNedbxj5/4A8xuDn5NfowYsrBzqRiL5OnpJlp1PSJMAGMyKJMmRxzhK8qzU07zh9DeS9Xf/OpcR+pfRf2A==
Greetings,
Consider this source:
--- simple.c ---
#include <string.h>
int main()
{
union U {
char s[sizeof(int)];
int x;
} u, v;
strcpy(u.s, "abc");
v.x = 0xABCDEF;
return 0; // break here
}
--- simple.c ---
--- simple.py ---
def pp_u(val):
return "<" + str(val['s']) + ">"
gdb.cli_pretty_printers['^union U$'] = pp_u
--- simple.py ---
(gdb) b 11
Breakpoint 1 at 0x40032e: file simple.c, line 11.
(gdb) r
Breakpoint 1, main () at simple.c:11
11 return 0; // break here
(gdb) python execfile('simple.py')
(gdb) print u
$1 = <"abc">
Good so far...
But:
(gdb) print v
$2 = Traceback (most recent call last):
File "simple.py", line 2, in pp_u
return "<" + str(val['s']) + ">"
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-3: ordinal not in range(128)
Traceback (most recent call last):
File "simple.py", line 2, in pp_u
return "<" + str(val['s']) + ">"
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-3: ordinal not in range(128)
{s = "ïÍ«", x = 11259375}
Not so good :(
I've attempted to fix this, but my Python-Fu is not yet up to the
task, and I couldn't find any good referencese on Python/Unicode/C-API.
What are some of the good Python references?
Thanks,
--
Paul Pluzhnikov