[PATCH][Ada] remove timeval from s-osinte

Laurent GUERBY laurent@guerby.net
Mon Nov 23 14:37:00 GMT 2009


As discussed, not tested except by compiling locally.

Laurent

2009-11-23  Eric Botcazou  <ebotcazou@adacore.com>
            Laurent GUERBY  <laurent@guerby.net>

	* s-osinte-linux.ads (struct_timeval): Delete.
	* s-osinte-hpux.ads (struct_timeval, To_Duration, To_Timeval): 
	Delete.
	* s-osinte-kfreebsd-gnu.ads: Likewise.
	* s-osinte-rtems.ads: Likewise.
	* s-osinte-aix.ads: Likewise.
	* s-osinte-hpux-dce.ads: Likewise.
	* s-osinte-darwin.ads: Likewise.
	* s-osinte-solaris-posix.ads: Likewise.
	* s-osinte-irix.ads: Likewise.
	* s-osinte-solaris.ads: Likewise.
	* s-osinte-hpux-dce.adb (To_Duration, To_Timeval): Delete.
	* s-osinte-irix.adb: Likewise.
	* s-osinte-solaris.adb: Likewise.
	* s-osinte-rtems.adb: Likewise. Minor reformatting.
	* s-osinte-aix.adb (To_Duration, To_Timeval): Delete.
	(clock_gettime): Use cal.c timeval_to_duration.
        * s-osinte-darwin.adb: Likewise.

-------------- next part --------------
Index: s-osinte-linux.ads
===================================================================
--- s-osinte-linux.ads	(revision 154433)
+++ s-osinte-linux.ads	(working copy)
@@ -518,12 +518,6 @@
    end record;
    pragma Convention (C, timespec);
 
-   type struct_timeval is record
-      tv_sec  : time_t;
-      tv_usec : time_t;
-   end record;
-   pragma Convention (C, struct_timeval);
-
    type pthread_attr_t is record
       detachstate   : int;
       schedpolicy   : int;
Index: s-osinte-hpux.ads
===================================================================
--- s-osinte-hpux.ads	(revision 154433)
+++ s-osinte-hpux.ads	(working copy)
@@ -209,16 +209,6 @@
    pragma Convention (C, struct_timezone);
    type struct_timezone_ptr is access all struct_timezone;
 
-   type struct_timeval is private;
-   --  This is needed on systems that do not have clock_gettime()
-   --  but do have gettimeofday().
-
-   function To_Duration (TV : struct_timeval) return Duration;
-   pragma Inline (To_Duration);
-
-   function To_Timeval (D : Duration) return struct_timeval;
-   pragma Inline (To_Timeval);
-
    -------------------------
    -- Priority Scheduling --
    -------------------------
@@ -535,12 +525,6 @@
    type clockid_t is new int;
    CLOCK_REALTIME : constant clockid_t := 1;
 
-   type struct_timeval is record
-      tv_sec  : time_t;
-      tv_usec : time_t;
-   end record;
-   pragma Convention (C, struct_timeval);
-
    type pthread_attr_t is new int;
    type pthread_condattr_t is new int;
    type pthread_mutexattr_t is new int;
Index: s-osinte-kfreebsd-gnu.ads
===================================================================
--- s-osinte-kfreebsd-gnu.ads	(revision 154433)
+++ s-osinte-kfreebsd-gnu.ads	(working copy)
@@ -208,19 +208,6 @@
    function To_Timespec (D : Duration) return timespec;
    pragma Inline (To_Timespec);
 
-   type struct_timeval is private;
-
-   function To_Duration (TV : struct_timeval) return Duration;
-   pragma Inline (To_Duration);
-
-   function To_Timeval (D : Duration) return struct_timeval;
-   pragma Inline (To_Timeval);
-
-   function gettimeofday
-     (tv : access struct_timeval;
-      tz : System.Address := System.Null_Address) return int;
-   pragma Import (C, gettimeofday, "gettimeofday");
-
    function sysconf (name : int) return long;
    pragma Import (C, sysconf);
 
@@ -511,12 +498,6 @@
    end record;
    pragma Convention (C, timespec);
 
-   type struct_timeval is record
-      tv_sec  : time_t;
-      tv_usec : time_t;
-   end record;
-   pragma Convention (C, struct_timeval);
-
    type pthread_attr_t is record
       detachstate   : int;
       schedpolicy   : int;
Index: s-osinte-rtems.adb
===================================================================
--- s-osinte-rtems.adb	(revision 154433)
+++ s-osinte-rtems.adb	(working copy)
@@ -89,35 +89,19 @@
                        tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
    end To_Timespec;
 
-   function To_Duration (TV : struct_timeval) return Duration is
-   begin
-      return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
-   end To_Duration;
+   ------------------
+   -- pthread_init --
+   ------------------
 
-   function To_Timeval (D : Duration) return struct_timeval is
-      S : int;
-      F : Duration;
-   begin
-      S := int (Long_Long_Integer (D));
-      F := D - Duration (S);
-
-      --  If F has negative value due to a round-up, adjust for positive F
-      --  value.
-      if F < 0.0 then
-         S := S - 1;
-         F := F + 1.0;
-      end if;
-      return
-        struct_timeval'
-          (tv_sec  => S,
-           tv_usec => int (Long_Long_Integer (F * 10#1#E6)));
-   end To_Timeval;
-
    procedure pthread_init is
    begin
       null;
    end pthread_init;
 
+   --------------------
+   -- Get_Stack_Base --
+   --------------------
+
    function Get_Stack_Base (thread : pthread_t) return Address is
       pragma Warnings (Off, thread);
 
@@ -125,6 +109,10 @@
       return Null_Address;
    end Get_Stack_Base;
 
+   -----------------
+   -- sigaltstack --
+   -----------------
+
    function sigaltstack
      (ss  : not null access stack_t;
       oss : access stack_t) return int is
Index: s-osinte-rtems.ads
===================================================================
--- s-osinte-rtems.ads	(revision 154433)
+++ s-osinte-rtems.ads	(working copy)
@@ -191,14 +191,6 @@
    function To_Timespec (D : Duration) return timespec;
    pragma Inline (To_Timespec);
 
-   type struct_timeval is private;
-
-   function To_Duration (TV : struct_timeval) return Duration;
-   pragma Inline (To_Duration);
-
-   function To_Timeval (D : Duration) return struct_timeval;
-   pragma Inline (To_Timeval);
-
    -------------------------
    -- Priority Scheduling --
    -------------------------
@@ -595,12 +587,6 @@
    type clockid_t is new rtems_id;
    CLOCK_REALTIME : constant clockid_t := 1;
 
-   type struct_timeval is record
-      tv_sec  : int;
-      tv_usec : int;
-   end record;
-   pragma Convention (C, struct_timeval);
-
    type pthread_attr_t is record
       is_initialized  : int;
       stackaddr       : System.Address;
Index: s-osinte-aix.adb
===================================================================
--- s-osinte-aix.adb	(revision 154433)
+++ s-osinte-aix.adb	(working copy)
@@ -48,11 +48,6 @@
       return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
    end To_Duration;
 
-   function To_Duration (TV : struct_timeval) return Duration is
-   begin
-      return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
-   end To_Duration;
-
    ------------------------
    -- To_Target_Priority --
    ------------------------
@@ -104,31 +99,6 @@
                        tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
    end To_Timespec;
 
-   ----------------
-   -- To_Timeval --
-   ----------------
-
-   function To_Timeval (D : Duration) return struct_timeval is
-      S : long;
-      F : Duration;
-
-   begin
-      S := long (Long_Long_Integer (D));
-      F := D - Duration (S);
-
-      --  If F is negative due to a round-up, adjust for positive F value
-
-      if F < 0.0 then
-         S := S - 1;
-         F := F + 1.0;
-      end if;
-
-      return
-        struct_timeval'
-          (tv_sec => S,
-           tv_usec => long (Long_Long_Integer (F * 10#1#E6)));
-   end To_Timeval;
-
    -------------------
    -- clock_gettime --
    -------------------
@@ -138,20 +108,37 @@
       tp       : access timespec)
       return     int
    is
-      pragma Warnings (Off, clock_id);
+      pragma Unreferenced (clock_id);
 
+      --  Darwin threads don't have clock_gettime, so use
+      --  gettimeofday() instead.
+
+      use Interfaces;
+
+      type timeval is array (1 .. 2) of C.long;
+
+      procedure timeval_to_duration
+        (T    : not null access timeval;
+         sec  : not null access C.long;
+         usec : not null access C.long);
+      pragma Import (C, timeval_to_duration, "__gnat_timeval_to_duration");
+
+      Micro  : constant := 10**6;
+      sec    : aliased C.long;
+      usec   : aliased C.long;
+      TV     : aliased timeval;
       Result : int;
-      tv     : aliased struct_timeval;
 
       function gettimeofday
-        (tv   : access struct_timeval;
-         tz   : System.Address := System.Null_Address)
-         return int;
+        (Tv : access timeval;
+         Tz : System.Address := System.Null_Address) return int;
       pragma Import (C, gettimeofday, "gettimeofday");
 
    begin
-      Result := gettimeofday (tv'Unchecked_Access);
-      tp.all := To_Timespec (To_Duration (tv));
+      Result := gettimeofday (TV'Access, System.Null_Address);
+      pragma Assert (Result = 0);
+      timeval_to_duration (TV'Access, sec'Access, usec'Access);
+      tp.all := To_Timespec (Duration (sec) + Duration (usec) / Micro);
       return Result;
    end clock_gettime;
 
Index: s-osinte-aix.ads
===================================================================
--- s-osinte-aix.ads	(revision 154433)
+++ s-osinte-aix.ads	(working copy)
@@ -206,7 +206,6 @@
    function clock_gettime
      (clock_id : clockid_t;
       tp       : access timespec) return int;
-   --  AIX threads don't have clock_gettime, so use gettimeofday() instead
 
    function To_Duration (TS : timespec) return Duration;
    pragma Inline (To_Duration);
@@ -221,16 +220,6 @@
    pragma Convention (C, struct_timezone);
    type struct_timezone_ptr is access all struct_timezone;
 
-   type struct_timeval is private;
-   --  This is needed on systems that do not have clock_gettime() but do have
-   --  gettimeofday().
-
-   function To_Duration (TV : struct_timeval) return Duration;
-   pragma Inline (To_Duration);
-
-   function To_Timeval (D : Duration) return struct_timeval;
-   pragma Inline (To_Timeval);
-
    -------------------------
    -- Priority Scheduling --
    -------------------------
@@ -554,12 +543,6 @@
    type clockid_t is new int;
    CLOCK_REALTIME : constant clockid_t := 0;
 
-   type struct_timeval is record
-      tv_sec  : long;
-      tv_usec : long;
-   end record;
-   pragma Convention (C, struct_timeval);
-
    type pthread_attr_t is new System.Address;
    pragma Convention (C, pthread_attr_t);
    --  typedef struct __pt_attr        *pthread_attr_t;
Index: s-osinte-hpux-dce.adb
===================================================================
--- s-osinte-hpux-dce.adb	(revision 154433)
+++ s-osinte-hpux-dce.adb	(working copy)
@@ -78,32 +78,6 @@
                        tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
    end To_Timespec;
 
-   function To_Duration (TV : struct_timeval) return Duration is
-   begin
-      return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
-   end To_Duration;
-
-   function To_Timeval (D : Duration) return struct_timeval is
-      S : time_t;
-      F : Duration;
-   begin
-      S := time_t (Long_Long_Integer (D));
-      F := D - Duration (S);
-
-      --  If F has negative value due to a round-up, adjust for positive F
-      --  value.
-
-      if F < 0.0 then
-         S := S - 1;
-         F := F + 1.0;
-      end if;
-
-      return
-        struct_timeval'
-          (tv_sec => S,
-           tv_usec => time_t (Long_Long_Integer (F * 10#1#E6)));
-   end To_Timeval;
-
    -------------------------
    -- POSIX.1c  Section 3 --
    -------------------------
Index: s-osinte-hpux-dce.ads
===================================================================
--- s-osinte-hpux-dce.ads	(revision 154433)
+++ s-osinte-hpux-dce.ads	(working copy)
@@ -207,14 +207,6 @@
    function To_Timespec (D : Duration) return timespec;
    pragma Inline (To_Timespec);
 
-   type struct_timeval is private;
-
-   function To_Duration (TV : struct_timeval) return Duration;
-   pragma Inline (To_Duration);
-
-   function To_Timeval (D : Duration) return struct_timeval;
-   pragma Inline (To_Timeval);
-
    -------------------------
    -- Priority Scheduling --
    -------------------------
@@ -459,12 +451,6 @@
    type clockid_t is new int;
    CLOCK_REALTIME : constant clockid_t := 1;
 
-   type struct_timeval is record
-      tv_sec  : time_t;
-      tv_usec : time_t;
-   end record;
-   pragma Convention (C, struct_timeval);
-
    type cma_t_address is new System.Address;
 
    type cma_t_handle is record
Index: s-osinte-darwin.adb
===================================================================
--- s-osinte-darwin.adb	(revision 154433)
+++ s-osinte-darwin.adb	(working copy)
@@ -48,11 +48,6 @@
       return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
    end To_Duration;
 
-   function To_Duration (TV : struct_timeval) return Duration is
-   begin
-      return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
-   end To_Duration;
-
    ------------------------
    -- To_Target_Priority --
    ------------------------
@@ -88,31 +83,6 @@
         tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
    end To_Timespec;
 
-   ----------------
-   -- To_Timeval --
-   ----------------
-
-   function To_Timeval (D : Duration) return struct_timeval is
-      S : time_t;
-      F : Duration;
-
-   begin
-      S := time_t (D);
-      F := D - Duration (S);
-
-      --  If F has negative value due to a round-up, adjust for positive F
-      --  value.
-
-      if F < 0.0 then
-         S := S - 1;
-         F := F + 1.0;
-      end if;
-
-      return struct_timeval'
-               (Tv_Sec  => S,
-                tv_usec => int32_t (Long_Long_Integer (F * 10#1#E6)));
-   end To_Timeval;
-
    -------------------
    -- clock_gettime --
    -------------------
@@ -122,17 +92,36 @@
       tp       : access timespec) return int
    is
       pragma Unreferenced (clock_id);
+
+      --  AIX threads don't have clock_gettime, so use
+      --  gettimeofday() instead.
+
+      use Interfaces;
+
+      type timeval is array (1 .. 2) of C.long;
+
+      procedure timeval_to_duration
+        (T    : not null access timeval;
+         sec  : not null access C.long;
+         usec : not null access C.long);
+      pragma Import (C, timeval_to_duration, "__gnat_timeval_to_duration");
+
+      Micro  : constant := 10**6;
+      sec    : aliased C.long;
+      usec   : aliased C.long;
+      TV     : aliased timeval;
       Result : int;
-      tv     : aliased struct_timeval;
 
       function gettimeofday
-        (tv : access struct_timeval;
-         tz : System.Address := System.Null_Address) return int;
+        (Tv : access timeval;
+         Tz : System.Address := System.Null_Address) return int;
       pragma Import (C, gettimeofday, "gettimeofday");
 
    begin
-      Result := gettimeofday (tv'Unchecked_Access);
-      tp.all := To_Timespec (To_Duration (tv));
+      Result := gettimeofday (TV'Access, System.Null_Address);
+      pragma Assert (Result = 0);
+      timeval_to_duration (TV'Access, sec'Access, usec'Access);
+      tp.all := To_Timespec (Duration (sec) + Duration (usec) / Micro);
       return Result;
    end clock_gettime;
 
Index: s-osinte-darwin.ads
===================================================================
--- s-osinte-darwin.ads	(revision 154433)
+++ s-osinte-darwin.ads	(working copy)
@@ -199,14 +199,6 @@
    function To_Timespec (D : Duration) return timespec;
    pragma Inline (To_Timespec);
 
-   type struct_timeval is private;
-
-   function To_Duration (TV : struct_timeval) return Duration;
-   pragma Inline (To_Duration);
-
-   function To_Timeval (D : Duration) return struct_timeval;
-   pragma Inline (To_Timeval);
-
    -------------------------
    -- Priority Scheduling --
    -------------------------
@@ -528,12 +520,6 @@
    type clockid_t is new int;
    CLOCK_REALTIME : constant clockid_t := 0;
 
-   type struct_timeval is record
-      tv_sec  : time_t;
-      tv_usec : int32_t;
-   end record;
-   pragma Convention (C, struct_timeval);
-
    --
    --  Darwin specific signal implementation
    --
Index: s-osinte-solaris-posix.ads
===================================================================
--- s-osinte-solaris-posix.ads	(revision 154433)
+++ s-osinte-solaris-posix.ads	(working copy)
@@ -204,14 +204,6 @@
    function To_Timespec (D : Duration) return timespec;
    pragma Inline (To_Timespec);
 
-   type struct_timeval is private;
-
-   function To_Duration (TV : struct_timeval) return Duration;
-   pragma Inline (To_Duration);
-
-   function To_Timeval (D : Duration) return struct_timeval;
-   pragma Inline (To_Timeval);
-
    -------------------------
    -- Priority Scheduling --
    -------------------------
@@ -524,12 +516,6 @@
    type clockid_t is new int;
    CLOCK_REALTIME : constant clockid_t := 0;
 
-   type struct_timeval is record
-      tv_sec  : time_t;
-      tv_usec : time_t;
-   end record;
-   pragma Convention (C, struct_timeval);
-
    type pthread_attr_t is record
       pthread_attrp : System.Address;
    end record;
Index: s-osinte-irix.adb
===================================================================
--- s-osinte-irix.adb	(revision 154433)
+++ s-osinte-irix.adb	(working copy)
@@ -60,11 +60,6 @@
       return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
    end To_Duration;
 
-   function To_Duration (TV : struct_timeval) return Duration is
-   begin
-      return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
-   end To_Duration;
-
    -----------------
    -- To_Timespec --
    -----------------
@@ -89,30 +84,4 @@
                        tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
    end To_Timespec;
 
-   ----------------
-   -- To_Timeval --
-   ----------------
-
-   function To_Timeval (D : Duration) return struct_timeval is
-      S : time_t;
-      F : Duration;
-
-   begin
-      S := time_t (Long_Long_Integer (D));
-      F := D - Duration (S);
-
-      --  If F has negative value due to a round-up, adjust for positive F
-      --  value.
-
-      if F < 0.0 then
-         S := S - 1;
-         F := F + 1.0;
-      end if;
-
-      return
-        struct_timeval'
-          (tv_sec => S,
-           tv_usec => time_t (Long_Long_Integer (F * 10#1#E6)));
-   end To_Timeval;
-
 end System.OS_Interface;
Index: s-osinte-solaris.adb
===================================================================
--- s-osinte-solaris.adb	(revision 154433)
+++ s-osinte-solaris.adb	(working copy)
@@ -77,40 +77,6 @@
                        tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
    end To_Timespec;
 
-   -----------------
-   -- To_Duration --
-   -----------------
-
-   function To_Duration (TV : struct_timeval) return Duration is
-   begin
-      return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
-   end To_Duration;
-
-   ----------------
-   -- To_Timeval --
-   ----------------
-
-   function To_Timeval (D : Duration) return struct_timeval is
-      S : long;
-      F : Duration;
-
-   begin
-      S := long (Long_Long_Integer (D));
-      F := D - Duration (S);
-
-      --  If F has negative value due to a round-up, adjust for positive F
-
-      if F < 0.0 then
-         S := S - 1;
-         F := F + 1.0;
-      end if;
-
-      return
-        struct_timeval'
-          (tv_sec  => S,
-           tv_usec => long (Long_Long_Integer (F * 10#1#E6)));
-   end To_Timeval;
-
    ------------------
    -- pthread_init --
    ------------------
Index: s-osinte-irix.ads
===================================================================
--- s-osinte-irix.ads	(revision 154433)
+++ s-osinte-irix.ads	(working copy)
@@ -201,14 +201,6 @@
    function To_Timespec (D : Duration) return timespec;
    pragma Inline (To_Timespec);
 
-   type struct_timeval is private;
-
-   function To_Duration (TV : struct_timeval) return Duration;
-   pragma Inline (To_Duration);
-
-   function To_Timeval (D : Duration) return struct_timeval;
-   pragma Inline (To_Timeval);
-
    -------------------------
    -- Priority Scheduling --
    -------------------------
@@ -493,12 +485,6 @@
    CLOCK_SGI_CYCLE : constant clockid_t := 2;
    CLOCK_SGI_FAST  : constant clockid_t := 3;
 
-   type struct_timeval is record
-      tv_sec  : time_t;
-      tv_usec : time_t;
-   end record;
-   pragma Convention (C, struct_timeval);
-
    type array_type_9 is array (Integer range 0 .. 4) of long;
    type pthread_attr_t is record
       X_X_D : array_type_9;
Index: s-osinte-solaris.ads
===================================================================
--- s-osinte-solaris.ads	(revision 154433)
+++ s-osinte-solaris.ads	(working copy)
@@ -263,16 +263,6 @@
    function To_Timespec (D : Duration) return timespec;
    pragma Inline (To_Timespec);
 
-   type struct_timeval is private;
-   --  This is needed on systems that do not have clock_gettime()
-   --  but do have gettimeofday().
-
-   function To_Duration (TV : struct_timeval) return Duration;
-   pragma Inline (To_Duration);
-
-   function To_Timeval (D : Duration) return struct_timeval;
-   pragma Inline (To_Timeval);
-
    -------------
    -- Process --
    -------------
@@ -528,12 +518,6 @@
    type clockid_t is new int;
    CLOCK_REALTIME : constant clockid_t := 0;
 
-   type struct_timeval is record
-      tv_sec  : long;
-      tv_usec : long;
-   end record;
-   pragma Convention (C, struct_timeval);
-
    type array_type_9 is array (0 .. 3) of unsigned_char;
    type record_type_3 is record
       flag  : array_type_9;


More information about the Gcc-patches mailing list