[Python-Dev] int vs ssize_t in unicode

"Martin v. Löwis" martin at v.loewis.de
Thu Apr 13 08:37:49 CEST 2006


Neal Norwitz wrote:
> In Include/ucnhash.h I notice some integers and wonder if those should
> be Py_ssize_t.  It looks like they are just names so they should be
> pretty short.

Right: int size is below 100; the name length of a Unicode character
is below 40 (I believe). OTOH, changing them to Py_ssize_t wouldn't
hurt, either.

> 235:
>         assert(length<INT_MAX);
>     unicode->length = (int)length;

Right: I just changed it. It may date back to a version of the patch
where I only changed the signatures of the functions, but not the
object layout.

> 376, 404:
>   int i;

Right, changed.

> 1366: (seems like this could be a 64-bit value)
>   int nneeded;

Right; also, the safe downcast can go away.

> (i stopped at this point, there are probably more)

I looked through the entire file, and fixed all I could find.

> Modules/unicodedata.c (lots of ints, not sure if they are a problem)

Most of them are not, since most functions deal only with Unicode
characters, character names, and character numbers (which are below 2**21).

> 494:
>     isize = PyUnicode_GET_SIZE(input);

This is a problem, though; I fixed it.

Regards,
Martin


More information about the Python-Dev mailing list