Converting from PyUnicodeObject to char * without calling C API

skip at pobox.com skip at pobox.com
Tue Jan 13 19:39:47 CET 2009


    MRAB> Should you be using "char *" when they aren't char? Is there a
    MRAB> wide char type of some sort?

No, I shouldn't.  The storage is wchar_t *, what you get with my first
printed expression:

   (gdb) set $__f = (PyUnicodeObject *)(co->co_filename)
   (gdb) p *$__f->str@$__f->length
   $14 = {47, 85, 115, 101, 114, 115, 47, 115, 107, 105, 112, 47, 115, 114, 99, 47, 112, 121, 116, 104, 111, 110, 47, 112, 121, 51, 107, 45, 116, 47, 76, 105, 98, 47, 95, 119, 101, 97, 107, 114, 101, 102, 115, 101, 116, 46, 112, 121}

That's not too readable.  I'm not sure I can do much with that without
having a process to use.  Ideally:

    print "".join([ chr(x) for x in *$__f->str@$__f->length])

The question is, how do you do that in gdb-speak???

Skip



More information about the Python-list mailing list