This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Python pretty-printers and non-ASCII strings do not play well together :-(


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]