* [libgpiod][PATCH] bindings: cxx: fix event timestamp calculation for 32bit
@ 2020-09-09 1:40 Kent Gibson
2020-09-14 7:43 ` Bartosz Golaszewski
0 siblings, 1 reply; 2+ messages in thread
From: Kent Gibson @ 2020-09-09 1:40 UTC (permalink / raw)
To: linux-gpio, bgolaszewski, florian-evers; +Cc: Kent Gibson
Use appropriate C++ chrono library functions to convert the event
timestamp from a struct timespec to ::std::chrono::nanoseconds to
ensure correct conversion independent of platform.
Reported-by: Florian Evers <florian-evers@gmx.de>
Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
Florian suggests a C cast before the multiply, but using the C++ library
to do all the work, which removes the 1000000000 as well, seems the more
correct way to go to me.
I don't have a 32bit setup handy to test this, so perhaps Florian could
check if it works for him?
Cheers,
Kent.
bindings/cxx/line.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp
index 11deae6..b71b6db 100644
--- a/bindings/cxx/line.cpp
+++ b/bindings/cxx/line.cpp
@@ -215,8 +215,9 @@ line_event line::make_line_event(const ::gpiod_line_event& event) const noexcept
else if (event.event_type == GPIOD_LINE_EVENT_FALLING_EDGE)
ret.event_type = line_event::FALLING_EDGE;
- ret.timestamp = ::std::chrono::nanoseconds(
- event.ts.tv_nsec + (event.ts.tv_sec * 1000000000));
+ ret.timestamp = ::std::chrono::duration_cast<::std::chrono::nanoseconds>(
+ ::std::chrono::seconds(event.ts.tv_sec))
+ + ::std::chrono::nanoseconds(event.ts.tv_nsec);
ret.source = *this;
--
2.28.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [libgpiod][PATCH] bindings: cxx: fix event timestamp calculation for 32bit
2020-09-09 1:40 [libgpiod][PATCH] bindings: cxx: fix event timestamp calculation for 32bit Kent Gibson
@ 2020-09-14 7:43 ` Bartosz Golaszewski
0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2020-09-14 7:43 UTC (permalink / raw)
To: Kent Gibson; +Cc: linux-gpio, florian-evers
On Wed, Sep 9, 2020 at 3:40 AM Kent Gibson <warthog618@gmail.com> wrote:
>
> Use appropriate C++ chrono library functions to convert the event
> timestamp from a struct timespec to ::std::chrono::nanoseconds to
> ensure correct conversion independent of platform.
>
> Reported-by: Florian Evers <florian-evers@gmx.de>
> Signed-off-by: Kent Gibson <warthog618@gmail.com>
> ---
>
> Florian suggests a C cast before the multiply, but using the C++ library
> to do all the work, which removes the 1000000000 as well, seems the more
> correct way to go to me.
>
> I don't have a 32bit setup handy to test this, so perhaps Florian could
> check if it works for him?
>
> Cheers,
> Kent.
>
> bindings/cxx/line.cpp | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp
> index 11deae6..b71b6db 100644
> --- a/bindings/cxx/line.cpp
> +++ b/bindings/cxx/line.cpp
> @@ -215,8 +215,9 @@ line_event line::make_line_event(const ::gpiod_line_event& event) const noexcept
> else if (event.event_type == GPIOD_LINE_EVENT_FALLING_EDGE)
> ret.event_type = line_event::FALLING_EDGE;
>
> - ret.timestamp = ::std::chrono::nanoseconds(
> - event.ts.tv_nsec + (event.ts.tv_sec * 1000000000));
> + ret.timestamp = ::std::chrono::duration_cast<::std::chrono::nanoseconds>(
> + ::std::chrono::seconds(event.ts.tv_sec))
> + + ::std::chrono::nanoseconds(event.ts.tv_nsec);
>
> ret.source = *this;
>
> --
> 2.28.0
>
Patch applied, thanks!
Bartosz
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-09-14 7:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-09 1:40 [libgpiod][PATCH] bindings: cxx: fix event timestamp calculation for 32bit Kent Gibson
2020-09-14 7:43 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).