Skip to content

Commit

Permalink
cross/pendulum: synchronize between #6403 and #6409
Browse files Browse the repository at this point in the history
  • Loading branch information
hgy59 committed Jan 21, 2025
1 parent 58dbd08 commit 1f55c7d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
4 changes: 3 additions & 1 deletion cross/pendulum/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ PKG_DIR = $(PKG_NAME)-$(PKG_VERS)
DEPENDS =

HOMEPAGE = https://pendulum.eustace.io
COMMENT = Python datetimes made easy
COMMENT = Python datetimes made easy.
LICENSE = MIT

# toolchains lacking atomic support
UNSUPPORTED_ARCHS = $(OLD_PPC_ARCHS) $(ARMv5_ARCHS) $(ARMv7L_ARCHS)

PATCHES_LEVEL = 1

include ../../mk/spksrc.common.mk

ifeq ($(call version_le, $(TC_GCC), 5),1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
--- rust/src/helpers-orig.rs 2023-12-16 17:04:29
+++ rust/src/helpers.rs 2025-01-19 08:51:27
@@ -49,57 +49,57 @@
https://sources.debian.org/patches/pendulum/3.0.0-2/rust-Use-i64-for-internal-unix-timestamps.patch

From: Benjamin Drung <[email protected]>
Date: Thu, 5 Sep 2024 14:03:44 +0200
Subject: rust: Use i64 for internal unix timestamps

pendulum 3.0.0 fails to build on 32-bit armhf:

```
error: this arithmetic operation will overflow
--> src/helpers.rs:59:20
|
59 | seconds += ((146_097 - 10957) * SECS_PER_DAY as usize) as isize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `135140_usize * 86400_usize`, which would overflow
|
= note: `#[deny(arithmetic_overflow)]` on by default
```

`(146_097 - 10957) * SECS_PER_DAY` equals 11,676,096,000 which does not
fit into 32 bit integers.

Use i64 for the seconds variable while handling with the timestamp. Only
convert in to `usize` once the timestamp is split into its components.

Fixes https://github.com/sdispater/pendulum/issues/784
Ubuntu-Bug: https://bugs.launchpad.net/ubuntu/+source/pendulum/+bug/2079029
Forwarded: https://github.com/sdispater/pendulum/pull/842
---
rust/src/helpers.rs | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/rust/src/helpers.rs b/rust/src/helpers.rs
index 364075a..7927413 100644
--- a/rust/src/helpers.rs
+++ b/rust/src/helpers.rs
@@ -49,57 +49,57 @@ pub fn local_time(
microsecond: usize,
) -> (usize, usize, usize, usize, usize, usize, usize) {
let mut year: usize = EPOCH_YEAR as usize;
Expand Down Expand Up @@ -45,23 +78,23 @@
}

- let mut sec_per_4years = SECS_PER_4_YEARS[leap_year] as isize;
+ let mut sec_per_4years = SECS_PER_4_YEARS[leap_year].into();
+ let mut sec_per_4years = SECS_PER_4_YEARS[leap_year].try_into().unwrap();
while seconds >= sec_per_4years {
seconds -= sec_per_4years;
year += 4;
leap_year = 1; // 4-year, non century aligned
- sec_per_4years = SECS_PER_4_YEARS[leap_year] as isize;
+ sec_per_4years = SECS_PER_4_YEARS[leap_year].into();
+ sec_per_4years = SECS_PER_4_YEARS[leap_year].try_into().unwrap();
}

- let mut sec_per_year = SECS_PER_YEAR[leap_year] as isize;
+ let mut sec_per_year = SECS_PER_YEAR[leap_year].into();
+ let mut sec_per_year = SECS_PER_YEAR[leap_year].try_into().unwrap();
while seconds >= sec_per_year {
seconds -= sec_per_year;
year += 1;
leap_year = 0; // non 4-year aligned
- sec_per_year = SECS_PER_YEAR[leap_year] as isize;
+ sec_per_year = SECS_PER_YEAR[leap_year].into();
+ sec_per_year = SECS_PER_YEAR[leap_year].try_into().unwrap();
}

// Handle months and days
Expand All @@ -73,7 +106,7 @@

let mut month_offset: usize;
while month != (TM_JANUARY + 1) {
@@ -113,10 +113,10 @@
@@ -113,10 +113,10 @@ pub fn local_time(
}

// Handle hours, minutes and seconds
Expand Down

0 comments on commit 1f55c7d

Please sign in to comment.