Daniel Stutzbach <dan...@stutzbachenterprises.com> added the comment:

Usually you wouldn't want to cast a char directly to a Py_UNICODE, because you 
need to take into account the encoding of the char and map it to the 
appropriate Unicode character.  The exception is when you're certain the char 
is 7-bit ASCII, which is a subset of Unicode; that's safe since 7-bit ASCII 
never uses the sign bit.

However, again, I'm not an expert on the internals of Python's Unicode 
implementation and it's possible that I'm missing something.  ;) You also raise 
a good point about third-party code.

Your other suggestion is quite workable.  ./configure could define 
HAVE_USABLE_WCHAR_T (which is used to enable the optimizations) when 
sizeof(wchar_t) == sizeof(Py_UNICODE), yet still define Py_UNICODE as unsigned. 
 Using Google Code I could not find any instances of HAVE_USABLE_WCHAR_T being 
used outside of CPython itself.

Another option would be to test Py_UNICODE_SIZE == SIZEOF_WCHAR_T to enable the 
optimizations, instead of defined(HAVE_USABLE_WCHAR_T).  The plus side is that 
we wouldn't be changing the semantics of anything.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8781>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to