public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix declaration of pthread-structs in s-osinte-rtems.ads
@ 2015-10-31 15:55 Jan Sommer
  2015-10-31 16:17 ` Jan Sommer
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Jan Sommer @ 2015-10-31 15:55 UTC (permalink / raw)
  To: gcc-patches, devel

[-- Attachment #1: Type: text/plain, Size: 504 bytes --]

Hi,

This patch changes the Ada-declaration of the pthread-related structs such as pthread_attr_t from a field-equivalent declaration to just reserving the right amount of memory.
It is only rtems related and essentially copies the way how the types are defined in s-osinte-linux.ads. It makes the declarations independent of a particular newlib-version and fixes the bug I filed here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68169

CC are the rtems developers for discussion.

Best regards,

   Jan

[-- Attachment #2: 0001-Add-rtems-to-the-list-of-platforms-for-which-Ada-con.patch --]
[-- Type: text/x-patch, Size: 1200 bytes --]

From 1092dda339a12d3f7d437335e93dcdea540051c8 Mon Sep 17 00:00:00 2001
From: Jan Sommer <soja-lists@aries.uberspace.de>
Date: Sat, 31 Oct 2015 16:09:32 +0100
Subject: [PATCH 1/2] Add rtems to the list of platforms for which
 Ada-constants of pthread-types are generated

Constant values for the sizes of pthread-types will be generated in s-oscons.ads for rtems.

Related to bugreport: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68169
---
 gcc/ada/s-oscons-tmplt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/s-oscons-tmplt.c b/gcc/ada/s-oscons-tmplt.c
index 5a034d5..5c26890 100644
--- a/gcc/ada/s-oscons-tmplt.c
+++ b/gcc/ada/s-oscons-tmplt.c
@@ -154,7 +154,7 @@ pragma Style_Checks ("M32766");
 # include <_types.h>
 #endif
 
-#ifdef __linux__
+#if defined (__linux__) || defined (__rtems__)
 # include <pthread.h>
 # include <signal.h>
 #endif
@@ -1441,7 +1441,7 @@ CND(CLOCK_THREAD_CPUTIME_ID, "Thread CPU clock")
 CNS(CLOCK_RT_Ada, "")
 #endif
 
-#if defined (__APPLE__) || defined (__linux__) || defined (DUMMY)
+#if defined (__APPLE__) || defined (__linux__) || defined (__rtems__) || defined (DUMMY)
 /*
 
    --  Sizes of pthread data types
-- 
2.5.0


[-- Attachment #3: 0002-Update-type-definitions-to-use-the-constant-values-f.patch --]
[-- Type: text/x-patch, Size: 4857 bytes --]

From 6b445bc37bf59641f46c01ec64a248efb5ec40f4 Mon Sep 17 00:00:00 2001
From: Jan Sommer <soja-lists@aries.uberspace.de>
Date: Sat, 31 Oct 2015 16:25:14 +0100
Subject: [PATCH 2/2] Update type definitions to use the constant values from
 s-oscons.ads

Currently the pthread type definitions list all fields of the corresponding c-struct in Ada.
However, at least pthread_attr_t has more fields in current newlib than in the Ada declaration here.

This change will declare the pthread-related structs in the same way as in s-osinte-linux.ads by using fixed length char-arrays with the length obtained from s-oscons.ads.
This way the declaration is independent of a certain changes in newlib.

It also replaces some hardcoded errnos with the corresponding constants from s-oscons.ads

Fixes bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68169
---
 gcc/ada/s-osinte-rtems.ads | 50 ++++++++++++++++++++--------------------------
 1 file changed, 22 insertions(+), 28 deletions(-)

diff --git a/gcc/ada/s-osinte-rtems.ads b/gcc/ada/s-osinte-rtems.ads
index 8b9ae12..992254f 100644
--- a/gcc/ada/s-osinte-rtems.ads
+++ b/gcc/ada/s-osinte-rtems.ads
@@ -51,6 +51,8 @@
 --  It is designed to be a bottom-level (leaf) package.
 
 with Interfaces.C;
+with System.OS_Constants;
+
 package System.OS_Interface is
    pragma Preelaborate;
 
@@ -60,6 +62,7 @@ package System.OS_Interface is
    subtype rtems_id       is Interfaces.C.unsigned;
 
    subtype int            is Interfaces.C.int;
+   subtype char           is Interfaces.C.char;
    subtype short          is Interfaces.C.short;
    subtype long           is Interfaces.C.long;
    subtype unsigned       is Interfaces.C.unsigned;
@@ -68,7 +71,6 @@ package System.OS_Interface is
    subtype unsigned_char  is Interfaces.C.unsigned_char;
    subtype plain_char     is Interfaces.C.plain_char;
    subtype size_t         is Interfaces.C.size_t;
-
    -----------
    -- Errno --
    -----------
@@ -76,11 +78,11 @@ package System.OS_Interface is
    function errno return int;
    pragma Import (C, errno, "__get_errno");
 
-   EAGAIN    : constant := 11;
-   EINTR     : constant := 4;
-   EINVAL    : constant := 22;
-   ENOMEM    : constant := 12;
-   ETIMEDOUT : constant := 116;
+   EAGAIN    : constant := System.OS_Constants.EAGAIN;
+   EINTR     : constant := System.OS_Constants.EINTR;
+   EINVAL    : constant := System.OS_Constants.EINVAL;
+   ENOMEM    : constant := System.OS_Constants.ENOMEM;
+   ETIMEDOUT : constant := System.OS_Constants.ETIMEDOUT;
 
    -------------
    -- Signals --
@@ -448,6 +450,7 @@ package System.OS_Interface is
       ss_low_priority     : int;
       ss_replenish_period : timespec;
       ss_initial_budget   : timespec;
+      sched_ss_max_repl   : int;
    end record;
    pragma Convention (C, struct_sched_param);
 
@@ -621,43 +624,34 @@ private
    end record;
    pragma Convention (C, timespec);
 
-   CLOCK_REALTIME :  constant clockid_t := 1;
-   CLOCK_MONOTONIC : constant clockid_t := 4;
+   CLOCK_REALTIME :  constant clockid_t := System.OS_Constants.CLOCK_REALTIME;
+   CLOCK_MONOTONIC : constant clockid_t := System.OS_Constants.CLOCK_MONOTONIC;
+
+   subtype char_array is Interfaces.C.char_array;
 
    type pthread_attr_t is record
-      is_initialized  : int;
-      stackaddr       : System.Address;
-      stacksize       : int;
-      contentionscope : int;
-      inheritsched    : int;
-      schedpolicy     : int;
-      schedparam      : struct_sched_param;
-      cputime_clocked_allowed : int;
-      detatchstate    : int;
+      Data : char_array (1 .. OS_Constants.PTHREAD_ATTR_SIZE);
    end record;
    pragma Convention (C, pthread_attr_t);
+   for pthread_attr_t'Alignment use Interfaces.C.unsigned_long'Alignment;
 
    type pthread_condattr_t is record
-      flags           : int;
-      process_shared  : int;
+      Data : char_array (1 .. OS_Constants.PTHREAD_CONDATTR_SIZE);
    end record;
    pragma Convention (C, pthread_condattr_t);
+   for pthread_condattr_t'Alignment use Interfaces.C.int'Alignment;
 
    type pthread_mutexattr_t is record
-      is_initialized  : int;
-      process_shared  : int;
-      prio_ceiling    : int;
-      protocol        : int;
-      mutex_type      : int;
-      recursive       : int;
-   end record;
+      Data : char_array (1 .. OS_Constants.PTHREAD_MUTEXATTR_SIZE);
+   end  record;
    pragma Convention (C, pthread_mutexattr_t);
+   for pthread_mutexattr_t'Alignment use Interfaces.C.int'Alignment;
 
    type pthread_rwlockattr_t is record
-      is_initialized  : int;
-      process_shared  : int;
+      Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCKATTR_SIZE);
    end record;
    pragma Convention (C, pthread_rwlockattr_t);
+   for pthread_rwlockattr_t'Alignment use Interfaces.C.unsigned_long'Alignment;
 
    type pthread_t is new rtems_id;
 
-- 
2.5.0


^ permalink raw reply	[flat|nested] 14+ messages in thread
* [PATCH] Fix declaration of pthread-structs in s-osinte-rtems.ads
@ 2015-11-03 14:22 Jan Sommer
  2015-11-03 17:10 ` Arnaud Charlet
  0 siblings, 1 reply; 14+ messages in thread
From: Jan Sommer @ 2015-11-03 14:22 UTC (permalink / raw)
  To: gcc-patches, Arnaud Charlet; +Cc: devel

Hi,

Let's try again. This time I made the diff against trunk with the changes Sebastian recommended, included a ChangeLog and used svn-diff.
If this patch goes through, please let me know how the backporting works.

Best regards,

   Jan

Index: ChangeLog
===================================================================
--- ChangeLog   (Revision 229709)
+++ ChangeLog   (Arbeitskopie)
@@ -1,3 +1,10 @@
+
+2015-11-03  Jan Sommer <soja-lists@aries.uberspace.de>
+
+       Use opaque types for Ada-declaration of pthread types
+       in Gnat for Rtems.
+       PR ada/68169
+
 2015-10-23  Steve Ellcey  <sellcey@imgtec.com>
 
        * MAINTAINERS: Update email address.
Index: gcc/ada/s-oscons-tmplt.c
===================================================================
--- gcc/ada/s-oscons-tmplt.c    (Revision 229709)
+++ gcc/ada/s-oscons-tmplt.c    (Arbeitskopie)
@@ -157,7 +157,7 @@ pragma Style_Checks ("M32766");
 # include <_types.h>
 #endif
 
-#if defined (__linux__) || defined (__ANDROID__)
+#if defined (__linux__) || defined (__ANDROID__) || defined (__rtems__)
 # include <pthread.h>
 # include <signal.h>
 #endif
@@ -1458,7 +1458,7 @@ CNS(CLOCK_RT_Ada, "")
 #endif
 
 #if defined (__APPLE__) || defined (__linux__) || defined (__ANDROID__) \
-  || defined (DUMMY)
+  || defined (__rtems__) || defined (DUMMY)
 /*
 
    --  Sizes of pthread data types
@@ -1501,7 +1501,7 @@ CND(PTHREAD_RWLOCKATTR_SIZE, "pthread_rwlockattr_t
 CND(PTHREAD_RWLOCK_SIZE,     "pthread_rwlock_t")
 CND(PTHREAD_ONCE_SIZE,       "pthread_once_t")
 
-#endif /* __APPLE__ || __linux__ || __ANDROID__ */
+#endif /* __APPLE__ || __linux__ || __ANDROID__ || __rtems__ */
 
 /*
 
Index: gcc/ada/s-osinte-rtems.ads
===================================================================
--- gcc/ada/s-osinte-rtems.ads  (Revision 229709)
+++ gcc/ada/s-osinte-rtems.ads  (Arbeitskopie)
@@ -51,6 +51,8 @@
 --  It is designed to be a bottom-level (leaf) package.
 
 with Interfaces.C;
+with System.OS_Constants;
+
 package System.OS_Interface is
    pragma Preelaborate;
 
@@ -60,6 +62,7 @@ package System.OS_Interface is
    subtype rtems_id       is Interfaces.C.unsigned;
 
    subtype int            is Interfaces.C.int;
+   subtype char           is Interfaces.C.char;
    subtype short          is Interfaces.C.short;
    subtype long           is Interfaces.C.long;
    subtype unsigned       is Interfaces.C.unsigned;
@@ -68,7 +71,6 @@ package System.OS_Interface is
    subtype unsigned_char  is Interfaces.C.unsigned_char;
    subtype plain_char     is Interfaces.C.plain_char;
    subtype size_t         is Interfaces.C.size_t;
-
    -----------
    -- Errno --
    -----------
@@ -76,11 +78,11 @@ package System.OS_Interface is
    function errno return int;
    pragma Import (C, errno, "__get_errno");
 
-   EAGAIN    : constant := 11;
-   EINTR     : constant := 4;
-   EINVAL    : constant := 22;
-   ENOMEM    : constant := 12;
-   ETIMEDOUT : constant := 116;
+   EAGAIN    : constant := System.OS_Constants.EAGAIN;
+   EINTR     : constant := System.OS_Constants.EINTR;
+   EINVAL    : constant := System.OS_Constants.EINVAL;
+   ENOMEM    : constant := System.OS_Constants.ENOMEM;
+   ETIMEDOUT : constant := System.OS_Constants.ETIMEDOUT;
 
    -------------
    -- Signals --
@@ -448,6 +450,7 @@ package System.OS_Interface is
       ss_low_priority     : int;
       ss_replenish_period : timespec;
       ss_initial_budget   : timespec;
+      sched_ss_max_repl   : int;
    end record;
    pragma Convention (C, struct_sched_param);
 
@@ -621,43 +624,34 @@ private
    end record;
    pragma Convention (C, timespec);
 
-   CLOCK_REALTIME :  constant clockid_t := 1;
-   CLOCK_MONOTONIC : constant clockid_t := 4;
+   CLOCK_REALTIME :  constant clockid_t := System.OS_Constants.CLOCK_REALTIME;
+   CLOCK_MONOTONIC : constant clockid_t := System.OS_Constants.CLOCK_MONOTONIC;
 
+   subtype char_array is Interfaces.C.char_array;
+
    type pthread_attr_t is record
-      is_initialized  : int;
-      stackaddr       : System.Address;
-      stacksize       : int;
-      contentionscope : int;
-      inheritsched    : int;
-      schedpolicy     : int;
-      schedparam      : struct_sched_param;
-      cputime_clocked_allowed : int;
-      detatchstate    : int;
+      Data : char_array (1 .. OS_Constants.PTHREAD_ATTR_SIZE);
    end record;
    pragma Convention (C, pthread_attr_t);
+   for pthread_attr_t'Alignment use Interfaces.C.double'Alignment;
 
    type pthread_condattr_t is record
-      flags           : int;
-      process_shared  : int;
+      Data : char_array (1 .. OS_Constants.PTHREAD_CONDATTR_SIZE);
    end record;
    pragma Convention (C, pthread_condattr_t);
+   for pthread_condattr_t'Alignment use Interfaces.C.double'Alignment;
 
    type pthread_mutexattr_t is record
-      is_initialized  : int;
-      process_shared  : int;
-      prio_ceiling    : int;
-      protocol        : int;
-      mutex_type      : int;
-      recursive       : int;
-   end record;
+      Data : char_array (1 .. OS_Constants.PTHREAD_MUTEXATTR_SIZE);
+   end  record;
    pragma Convention (C, pthread_mutexattr_t);
+   for pthread_mutexattr_t'Alignment use Interfaces.C.double'Alignment;
 
    type pthread_rwlockattr_t is record
-      is_initialized  : int;
-      process_shared  : int;
+      Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCKATTR_SIZE);
    end record;
    pragma Convention (C, pthread_rwlockattr_t);
+   for pthread_rwlockattr_t'Alignment use Interfaces.C.double'Alignment;
 
    type pthread_t is new rtems_id;
 

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-11-04 12:21 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-31 15:55 [PATCH] Fix declaration of pthread-structs in s-osinte-rtems.ads Jan Sommer
2015-10-31 16:17 ` Jan Sommer
2015-10-31 17:16   ` Arnaud Charlet
2015-11-02 10:57     ` Jan Sommer
2015-11-02 10:59       ` Arnaud Charlet
2015-11-01 16:47 ` Joel Sherrill
2015-11-02 11:40 ` Sebastian Huber
2015-11-03 11:36   ` Jan Sommer
2015-11-03 14:22 Jan Sommer
2015-11-03 17:10 ` Arnaud Charlet
2015-11-03 17:41   ` Jan Sommer
2015-11-03 19:13     ` Arnaud Charlet
2015-11-04 11:47       ` Jan Sommer
2015-11-04 12:21         ` Arnaud Charlet

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 read-only IMAP folder(s) and NNTP newsgroup(s).