[Python-Dev] [Python-checkins] r41972 - python/branches/ssize_t/Objects/funcobject.c (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Mon Jan 9 23:11:03 CET 2006


Neal Norwitz wrote:

I often chose to use Pyssizet rather than int if it was capturing the result of a sequence length. But often this is larger than what will be allowed (like in this case). The problem then comes that we have cases everywhere if we leave things as ints.

This is also the strategy I have been following. The alternative would be to add error handling at the places where truncation occurs (unless you can really determine statically that there never ever will be truncation). This is too painful, so it is IMO better to carry the wide values throughout, until the place where the range check is carried out.

Stuff like this: len = (int) PyTupleSize(coconsts);

How do we know that is safe or not?

Well, you know that LOAD_CONST only supports 231 constants, so truncation to int is currently safe (I hope that the compiler detects cases where somebody tries to create more than 216 constants).

Still, this is only the current state. Going further, it might be that some of the restrictions are lifted someday, so we would have to review all casts then to see whether they are still safe.

Therefore, I think having fewer casts is better.

Regards, Martin



More information about the Python-Dev mailing list