[capi-sig] set default encoding in C program

Adam Olsen rhamph at gmail.com
Fri Jun 4 11:02:21 CEST 2010

On Thu, Jun 3, 2010 at 19:15, Shaun Savage <savages at mozapps.org> wrote:
> I have to have Unicode strings in my program. Trying to set the default
> encoding to utf-8 is a pain. (another *RANT*).
> the way i was thinking about doing it is create a sitecustomization.py  in
> the directory that the executable is in.  That does not work. I can not
> change site.py or sitecustomization.py.
> How do you set the default encoding to 'utf-8'?

You don't change it.  You wish it didn't exist and explicitly decode
when data enters or leaves your program.

What I suspect you're doing is creating unicode constants from C, so
you're working from a UTF-8 encoded source file.  I believe
PyUnicode_DecodeUTF8() is your best bet there, even if you do have to
explicitly pass the size.  If you're not dealing with constants then
it's not a big deal, and in fact you want an explicit size (as NUL
does NOT indicate end of string.)

More information about the capi-sig mailing list