Hello Nicolas,
Continuing discussion from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114065
but on the mailing list.
After more testing, we've observed a regression on one simple test:
8<----8<----8<----8<----8<----8<----
with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C.Extensions;
with GNAT.Calendar; use GNAT.Calendar;
procedure Test is
D, D2 : Duration;
Tv : aliased timeval;
procedure P_Dur (D : Duration) is
begin
Tv := To_Timeval (D);
D2 := To_Duration (Tv'Access);
Put_Line ("Duration IN:" & D'Image);
Put_Line (" To_Timeval -> timeval:" & Tv'Image);
Put_Line (" To_Duration OUT:" & D2'Image);
New_Line;
end P_Dur;
begin
Put_Line ("Test timeval conv");
P_Dur (1122334455.77777799999);
P_Dur (0.0);
P_Dur (0.9);
P_Dur (0.999_999_999);
P_Dur (Duration'Last);
end Test;
8<----8<----8<----8<----8<----8<----
And here are the results using an unmodified vs a modified compiler:
8<----8<----8<----8<----8<----8<----
Test timeval conv
Duration IN: 1122334455.777777999
To_Timeval -> timeval:
[ 1122334455, 777777, 0]
To_Duration OUT: 1122334455.777777000
Duration IN: 0.000000000
To_Timeval -> timeval:
[ 0, 0, 140725911838016]
To_Duration OUT: 0.000000000
Duration IN: 0.900000000
To_Timeval -> timeval:
[ 0, 900000, 140725911838016]
To_Duration OUT: 0.900000000
Duration IN: 0.999999999
To_Timeval -> timeval:
[ 0, 999999, 140725911838016]
To_Duration OUT: 0.999999000
Duration IN: 9223372036.854775807
To_Timeval -> timeval:
[ 9223372036, 854775, 140725911838016]
To_Duration OUT: 9223372036.854775000
8<----8<----8<----8<----8<----8<----
8<----8<----8<----8<----8<----8<----
Test timeval conv
Duration IN: 1122334455.777777999
To_Timeval -> timeval:
(TV_SEC => 1122334455,
TV_USEC => 777778)
To_Duration OUT: 1122334455.777778000
Duration IN: 0.000000000
To_Timeval -> timeval:
(TV_SEC => 0,
TV_USEC => 0)
To_Duration OUT: 0.000000000
Duration IN: 0.900000000
To_Timeval -> timeval:
(TV_SEC => 0,
TV_USEC => 900000)
To_Duration OUT: 0.900000000
Duration IN: 0.999999999
To_Timeval -> timeval:
(TV_SEC => 1,
TV_USEC => 0)
To_Duration OUT: 1.000000000
raised CONSTRAINT_ERROR : s-c_time.adb:129 overflow check failed
8<----8<----8<----8<----8<----8<----
We can see 2 differences here.
First, the modified version of To_Timeval is rounding values whereas it is
currently truncating values. Is this change intentional?
Then, To_Timeval(Duration'Last) throws an exception, which is probably
unexpected given that Duration'Last is a valid value. Do you think this can be
fixed? I see that you have a In_Duration function to check the inverse
conversion won't throw. In the case of To_Timeval, I think it should never throw
on valid input.
Regards,
Marc