[Python-Dev] Re: [Python-checkins] python/dist/src/Objects unicodeobject.c, 2.197, 2.198 (original) (raw)

Tim Peters tim.one at comcast.net
Tue Sep 16 17:39:58 EDT 2003


[M.-A. Lemburg]

Note that the implementation will bomb in several places if PyUNICODE is a signed type.

PyUNICODE was never intended to be a signed type, so the proper fix would be to add logic so that PyUNICODE gets forced to be an unsigned type.

Jeremy believed Py_UNICODE was already an unsigned type on his box, and that was the box with the segfaults. I don't know. Comparison with a signed int confused the issues to the point where we gave up and just fixed it .

The only case where PyUNICODE could become signed is via a compiler that defines wchart to be signed -- rather unlikely.

The C standard requires wchar_t to be an integer type, but doesn't constrain it further to an unsigned integer type. I don't like relying on non-standard assumptions in cases where there's little-to-no cost in not relying on them. For example, the cast I put in with this patch is probably a nop on most boxes, just forcing an unsigned comparison (which must have been the original intent, if Py_UNICODE was assumed to be an unsigned type).



More information about the Python-Dev mailing list