Skip to content

Commit 433e8ba

Browse files
committed
Fix timestamp codec brokenness on 32-bit systems
1 parent dc5f6fc commit 433e8ba

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

asyncpg/protocol/codecs/datetime.pyx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,47 @@ date_from_ordinal = datetime.date.fromordinal
1212
timedelta = datetime.timedelta
1313

1414
pg_epoch_datetime = datetime.datetime(2000, 1, 1)
15-
cdef long pg_epoch_datetime_ts = \
15+
cdef int32_t pg_epoch_datetime_ts = \
1616
cpython.PyLong_AsLong(int(pg_epoch_datetime.timestamp()))
1717

1818
pg_epoch_datetime_utc = datetime.datetime(2000, 1, 1, tzinfo=utc)
19-
cdef long pg_epoch_datetime_utc_ts = \
19+
cdef int32_t pg_epoch_datetime_utc_ts = \
2020
cpython.PyLong_AsLong(pg_epoch_datetime_utc.timestamp())
2121

2222
pg_epoch_date = datetime.date(2000, 1, 1)
23-
cdef long pg_date_offset_ord = \
23+
cdef int32_t pg_date_offset_ord = \
2424
cpython.PyLong_AsLong(pg_epoch_date.toordinal())
2525

2626
# Binary representations of infinity for datetimes.
27-
cdef long long pg_time64_infinity = 0x7fffffffffffffff
28-
cdef long long pg_time64_negative_infinity = 0x8000000000000000
27+
cdef int64_t pg_time64_infinity = 0x7fffffffffffffff
28+
cdef int64_t pg_time64_negative_infinity = 0x8000000000000000
2929
cdef int32_t pg_date_infinity = 0x7fffffff
3030
cdef int32_t pg_date_negative_infinity = 0x80000000
3131

3232
infinity_datetime = datetime.datetime(
3333
datetime.MAXYEAR, 12, 31, 23, 59, 59, 999999)
3434

35-
cdef long infinity_datetime_ord = cpython.PyLong_AsLong(
35+
cdef int32_t infinity_datetime_ord = cpython.PyLong_AsLong(
3636
infinity_datetime.toordinal())
3737

3838
cdef int64_t infinity_datetime_ts = 252455615999999999
3939

4040
negative_infinity_datetime = datetime.datetime(
4141
datetime.MINYEAR, 1, 1, 0, 0, 0, 0)
4242

43-
cdef long negative_infinity_datetime_ord = cpython.PyLong_AsLong(
43+
cdef int32_t negative_infinity_datetime_ord = cpython.PyLong_AsLong(
4444
negative_infinity_datetime.toordinal())
4545

4646
cdef int64_t negative_infinity_datetime_ts = -63082281600000000
4747

4848
infinity_date = datetime.date(datetime.MAXYEAR, 12, 31)
4949

50-
cdef long infinity_date_ord = cpython.PyLong_AsLong(
50+
cdef int32_t infinity_date_ord = cpython.PyLong_AsLong(
5151
infinity_date.toordinal())
5252

5353
negative_infinity_date = datetime.date(datetime.MINYEAR, 1, 1)
5454

55-
cdef long negative_infinity_date_ord = cpython.PyLong_AsLong(
55+
cdef int32_t negative_infinity_date_ord = cpython.PyLong_AsLong(
5656
negative_infinity_date.toordinal())
5757

5858

@@ -117,7 +117,7 @@ cdef date_decode(ConnectionSettings settings, FastReadBuffer buf):
117117
cdef timestamp_encode(ConnectionSettings settings, WriteBuffer buf, obj):
118118
delta = obj - pg_epoch_datetime
119119
cdef:
120-
int64_t seconds = cpython.PyLong_AsLong(delta.days) * 86400 + \
120+
int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \
121121
cpython.PyLong_AsLong(delta.seconds)
122122
int32_t microseconds = cpython.PyLong_AsLong(delta.microseconds)
123123

@@ -154,7 +154,7 @@ cdef timestamptz_encode(ConnectionSettings settings, WriteBuffer buf, obj):
154154

155155
delta = obj.astimezone(utc) - pg_epoch_datetime_utc
156156
cdef:
157-
int64_t seconds = cpython.PyLong_AsLong(delta.days) * 86400 + \
157+
int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \
158158
cpython.PyLong_AsLong(delta.seconds)
159159
int32_t microseconds = cpython.PyLong_AsLong(delta.microseconds)
160160

0 commit comments

Comments
 (0)