This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author p-ganssle
Recipients ammar2, p-ganssle, serhiy.storchaka
Date 2020-12-16.18:47:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1608144438.91.0.0268464921844.issue42660@roundup.psfhosted.org>
In-reply-to
Content
There are at least two issues with this:

1. This is a constructor for a struct, and the struct would really unnecessarily balloon in size if we switched everything over to be 32-bit integers (which I think is your suggestion?). This is not a major concern because in typical operation there are not likely to be more than 500 of these structs in existence at any one time (due to the cache), but it's still a minor annoyance.

I would guess that accepting `int` in the constructor function and converting it to uint8_t as part of building the struct would be maybe neutral to negative, since it involves casting a large signed type to a small unsigned one. This could cause more problems with overflow, not less.

2. In the current implementation `day` is unsigned by its nature — it represents a value indexed at 0 for which negative indices have no meaning. If we leave `day` as a uint8_t, then that tells the compiler at least something about the valid range of the value. By turning `day` (and presumably the other elements of this struct) into a less-suitable type, we're depriving ourselves of possibly *useful* compiler warnings.

Barring a solution where we have a simple and robust way to suppress warnings, I think the next-best solution is to add a static assertion about the signedness of the type for this particular case. I'd be happy to write it in a relatively general way so that it can be re-used elsewhere in CPython for the same purpose.
History
Date User Action Args
2020-12-16 18:47:18p-gansslesetrecipients: + p-ganssle, serhiy.storchaka, ammar2
2020-12-16 18:47:18p-gansslesetmessageid: <1608144438.91.0.0268464921844.issue42660@roundup.psfhosted.org>
2020-12-16 18:47:18p-gansslelinkissue42660 messages
2020-12-16 18:47:18p-gansslecreate