[issue3098] sys.sizeof test fails with wide unicode

Antoine Pitrou report at bugs.python.org
Sun Jun 15 15:39:10 CEST 2008


Antoine Pitrou <pitrou at free.fr> added the comment:

Le dimanche 15 juin 2008 à 13:18 +0000, Robert Schuppenies a écrit :
> If I understand configure correctly, PY_UNICODE_TYPE is only set when
> a type matching the size of $unicode_size is found. And this is set to
> either 2 or 4.

Buf if PY_UNICODE_TYPE is not set in configure, unicodeobject.h tries to
settle on a default value. Which turns out to be Py_UCS4 in UCS4 builds:
http://hg.pitrou.net/public/py3k/py3k/file/da93fc81b086/Include/unicodeobject.h#l86

And Py_UCS4 itself will be larger than 4 bytes if the platform's int
size is larger than that:
http://hg.pitrou.net/public/py3k/py3k/file/da93fc81b086/Include/unicodeobject.h#l119

So if you want to be 100% correct, you should use
sizeof(PY_UNICODE_TYPE) (or sizeof(Py_UNICODE), which is the same). If
you don't want to, sys.maxunicode is sufficient :-)

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3098>
_______________________________________


More information about the Python-bugs-list mailing list