[New-bugs-announce] [issue9034] datetime module should use int32_t for date/time components

Alexander Belopolsky report at bugs.python.org
Sun Jun 20 03:44:18 CEST 2010

New submission from Alexander Belopolsky <belopolsky at users.sourceforge.net>:

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).                                                                              
#if SIZEOF_INT < 4
#       error "datetime.c requires that C int have at least 32 bits"

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.

assignee: belopolsky
components: Extension Modules
messages: 108222
nosy: belopolsky, mark.dickinson
priority: low
severity: normal
stage: needs patch
status: open
title: datetime module should use int32_t for date/time components
type: feature request
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list