Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame^] | 1 | From b7a1a4d3259557f2587f7d5d47502691d94c21c2 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Fri, 16 Sep 2022 20:00:30 -0700 |
| 4 | Subject: [PATCH 1/2] typecast time_t and suseconds_t from std::chrono |
| 5 | |
| 6 | This fixes build on some architectures like mips |
| 7 | progress.cc:125:31: error: non-constant-expression cannot be narrowed from type 'std::chrono::duration<long long>::rep' (aka 'long long') to '__time_t' (aka 'long') in initializer list [-Wc++11-narrowing] |
| 8 | struct timeval NowTime = { Now_sec.count(), Now_usec.count() }; |
| 9 | |
| 10 | Upstream-Status: Submitted [https://salsa.debian.org/apt-team/apt/-/merge_requests/259] |
| 11 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 12 | --- |
| 13 | apt-pkg/acquire.cc | 4 ++-- |
| 14 | apt-pkg/contrib/progress.cc | 2 +- |
| 15 | ftparchive/apt-ftparchive.cc | 2 +- |
| 16 | 3 files changed, 4 insertions(+), 4 deletions(-) |
| 17 | |
| 18 | diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc |
| 19 | index 100ccde..dd0624a 100644 |
| 20 | --- a/apt-pkg/acquire.cc |
| 21 | +++ b/apt-pkg/acquire.cc |
| 22 | @@ -53,11 +53,11 @@ |
| 23 | using namespace std; |
| 24 | |
| 25 | // helper to convert time_point to a timeval |
| 26 | -static struct timeval SteadyDurationToTimeVal(std::chrono::steady_clock::duration Time) |
| 27 | +constexpr struct timeval SteadyDurationToTimeVal(std::chrono::steady_clock::duration Time) |
| 28 | { |
| 29 | auto const Time_sec = std::chrono::duration_cast<std::chrono::seconds>(Time); |
| 30 | auto const Time_usec = std::chrono::duration_cast<std::chrono::microseconds>(Time - Time_sec); |
| 31 | - return {Time_sec.count(), Time_usec.count()}; |
| 32 | + return timeval{static_cast<time_t>(Time_sec.count()), static_cast<suseconds_t>(Time_usec.count())}; |
| 33 | } |
| 34 | |
| 35 | std::string pkgAcquire::URIEncode(std::string const &part) /*{{{*/ |
| 36 | diff --git a/apt-pkg/contrib/progress.cc b/apt-pkg/contrib/progress.cc |
| 37 | index 03f88d4..eb688b9 100644 |
| 38 | --- a/apt-pkg/contrib/progress.cc |
| 39 | +++ b/apt-pkg/contrib/progress.cc |
| 40 | @@ -122,7 +122,7 @@ bool OpProgress::CheckChange(float Interval) |
| 41 | auto const Now = std::chrono::steady_clock::now().time_since_epoch(); |
| 42 | auto const Now_sec = std::chrono::duration_cast<std::chrono::seconds>(Now); |
| 43 | auto const Now_usec = std::chrono::duration_cast<std::chrono::microseconds>(Now - Now_sec); |
| 44 | - struct timeval NowTime = { Now_sec.count(), Now_usec.count() }; |
| 45 | + struct timeval NowTime = { static_cast<time_t>(Now_sec.count()), static_cast<suseconds_t>(Now_usec.count()) }; |
| 46 | |
| 47 | std::chrono::duration<decltype(Interval)> Delta = |
| 48 | std::chrono::seconds(NowTime.tv_sec - LastTime.tv_sec) + |
| 49 | diff --git a/ftparchive/apt-ftparchive.cc b/ftparchive/apt-ftparchive.cc |
| 50 | index 56fdc22..0a253b1 100644 |
| 51 | --- a/ftparchive/apt-ftparchive.cc |
| 52 | +++ b/ftparchive/apt-ftparchive.cc |
| 53 | @@ -58,7 +58,7 @@ static struct timeval GetTimevalFromSteadyClock() /*{{{*/ |
| 54 | auto const Time = std::chrono::steady_clock::now().time_since_epoch(); |
| 55 | auto const Time_sec = std::chrono::duration_cast<std::chrono::seconds>(Time); |
| 56 | auto const Time_usec = std::chrono::duration_cast<std::chrono::microseconds>(Time - Time_sec); |
| 57 | - return { Time_sec.count(), Time_usec.count() }; |
| 58 | + return { static_cast<time_t>(Time_sec.count()), static_cast<suseconds_t>(Time_usec.count()) }; |
| 59 | } |
| 60 | /*}}}*/ |
| 61 | static auto GetTimeDeltaSince(struct timeval StartTime) /*{{{*/ |
| 62 | -- |
| 63 | 2.37.3 |
| 64 | |