]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Fix inconsistencies in conversion functions from Duration
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 14 Jul 2025 22:37:19 +0000 (00:37 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 25 Jul 2025 08:09:35 +0000 (10:09 +0200)
commit93aa395bc32d0e0c7254eb9ab1eee546809d4338
tree81d84d737f38cab5eb7f76aea9c22cd9b0eaedf2
parent1603eeb6c8ea9cf68762a7755307077c7fb143d3
ada: Fix inconsistencies in conversion functions from Duration

The 3 units Ada.Calendar, GNAT.Calendar and GNAT.Sockets contain conversion
functions from the Duration fixed-point type that implement the same idiom
but with some inconsistencies:

  * GNAT.Sockets only handles Timeval_Duration, i.e. positive Duration, and
    is satisfactory, although a simpler implementation can be written,

  * GNAT.Calendar mishandles negative Duration values, as well as integral
    Duration values,

  * Ada.Calendar mishandles negative Duration values, and rounds nanoseconds
    instead of truncating them.

gcc/ada/ChangeLog:

* libgnat/a-calend.adb (To_Struct_Timespec_64): Deal with negative
Duration values and truncate the nanoseconds too.
* libgnat/g-calend.adb (timeval_to_duration): Unsuppress overflow
checks.
(duration_to_timeval): Likewise.  Deal with negative Duration values
as well as integral Duration values.
* libgnat/g-socket.adb (To_Timeval): Simplify the implementation.
gcc/ada/libgnat/a-calend.adb
gcc/ada/libgnat/g-calend.adb
gcc/ada/libgnat/g-socket.adb