You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
datetime module should use int32_t for date/time components #53280
bpo-17884: Try to reuse stdint.h types like int32_t
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2010-06-20.01:44:15.435>labels= ['extension-modules', 'type-feature']
title='datetime module should use int32_t for date/time components'updated_at=<Date2014-10-15.13:46:18.024>user='https://github.com/abalkin'
"""
As an aside, I dislike the fact that the datetime module uses a C 'int' for date ordinals, and clearly assumes that it'll be at least 32 bits. int could be as small as 16 bits on some systems (small embedded systems?). But that's another issue.
""" -- Mark Dickinson
A comment and an assertion at the top of the module suggest that this was deliberate.
/* We require that C int be at least 32 bits, and use int virtually * everywhere. In just a few cases we use a temp long, where a Python * API returns a C long. In such cases, we have to ensure that the * final result fits in a C int (this can be an issue on 64-bit boxes). */#ifSIZEOF_INT<4# error "datetime.c requires that C int have at least 32 bits"
#endif
However, since ranges of all integers are well defined in this module, there is little to be gained from the uncertainty about sizes of int and long. (For example, the allowed range of dates will not magically increase on a platform with 64 bit ints.)
I propose using explicitly sized C99 types int32_t and int64_t or rather their blessed for use in python equivalents PY_INTXX_T) throughout the module.
I vote to close as this is necessary as the current error is enough and I cannot find any example of anyone annoyed it's not used (as they are using an archaic machine) reporting this.
Activity
abalkin commentedon Jun 20, 2010
"""
As an aside, I dislike the fact that the datetime module uses a C 'int' for date ordinals, and clearly assumes that it'll be at least 32 bits. int could be as small as 16 bits on some systems (small embedded systems?). But that's another issue.
""" -- Mark Dickinson
A comment and an assertion at the top of the module suggest that this was deliberate.
However, since ranges of all integers are well defined in this module, there is little to be gained from the uncertainty about sizes of int and long. (For example, the allowed range of dates will not magically increase on a platform with 64 bit ints.)
I propose using explicitly sized C99 types int32_t and int64_t or rather their blessed for use in python equivalents PY_INTXX_T) throughout the module.
abalkin commentedon Oct 15, 2014
See also bpo-17884.
StanFromIreland commentedon Feb 16, 2025
I vote to close as this is necessary as the current error is enough and I cannot find any example of anyone annoyed it's not used (as they are using an archaic machine) reporting this.
encukou commentedon Feb 17, 2025
Right. We don't test with 16-bit ints, so this assumption might be silently made elsewhere. The datetime module is nice enough to assert it.
I'll close so issue to remove it from the project's "TODO list". If anyone wants to fix this, re-open or make a new issue.