From 2c195e6cb826d4fc6ba35c96c21bb07340751853 Mon Sep 17 00:00:00 2001 From: charlet Date: Wed, 29 Apr 2009 13:47:42 +0000 Subject: [PATCH] 2009-04-29 Arnaud Charlet * gnat_ugn.texi: Update some documentation about interfacing with C++ Mention -fkeep-inline-functions. * gnat_ugn.texi: Minor edits 2009-04-29 Ed Schonberg * sem_aggr.adb (Resolve_Record_Aggregate): When building an aggregate for a defaulted component of an enclosing aggregate, inherit the type from the component declaration of the enclosing type. 2009-04-29 Albert Lee * g-socthi-vms.ads, g-socthi-vxworks.ads, s-oscons-tmplt.c, g-socthi-mingw.ads, g-socthi.ads, g-socket.adb, g-sothco.ads (System.OS_Constants): New type Msg_Iovlen_T which follows whether the msg_iovlen field in struct msghdr is 32 or 64 bits wide. Relocate the Msghdr record type from GNAT.Sockets.Thin to GNAT.Sockets.Common, and use System.OS_Constants.Msg_Iovlen_T as the type for the Msg_Iovlen field. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146969 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ada/ChangeLog | 23 ++++++++++++++++++++++ gcc/ada/g-socket.adb | 8 ++++---- gcc/ada/g-socthi-mingw.ads | 11 ----------- gcc/ada/g-socthi-vms.ads | 12 ------------ gcc/ada/g-socthi-vxworks.ads | 11 ----------- gcc/ada/g-socthi.ads | 11 ----------- gcc/ada/g-sothco.ads | 15 +++++++++++++++ gcc/ada/gnat_ugn.texi | 37 +++++++++++++++++++++--------------- gcc/ada/s-oscons-tmplt.c | 13 +++++++++++++ gcc/ada/sem_aggr.adb | 3 +++ 10 files changed, 80 insertions(+), 64 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 8e69ece234d0..553edf2d643a 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,26 @@ +2009-04-29 Arnaud Charlet + + * gnat_ugn.texi: Update some documentation about interfacing with C++ + Mention -fkeep-inline-functions. + + * gnat_ugn.texi: Minor edits + +2009-04-29 Ed Schonberg + + * sem_aggr.adb (Resolve_Record_Aggregate): When building an aggregate + for a defaulted component of an enclosing aggregate, inherit the type + from the component declaration of the enclosing type. + +2009-04-29 Albert Lee + + * g-socthi-vms.ads, g-socthi-vxworks.ads, s-oscons-tmplt.c, + g-socthi-mingw.ads, g-socthi.ads, g-socket.adb, g-sothco.ads + (System.OS_Constants): New type Msg_Iovlen_T which follows whether the + msg_iovlen field in struct msghdr is 32 or 64 bits wide. + Relocate the Msghdr record type from GNAT.Sockets.Thin to + GNAT.Sockets.Common, and use System.OS_Constants.Msg_Iovlen_T as the + type for the Msg_Iovlen field. + 2009-04-29 Vincent Celier * sinput-l.adb (Load_File): When preprocessing, set temporarily the diff --git a/gcc/ada/g-socket.adb b/gcc/ada/g-socket.adb index 70964053074b..63f6d7481429 100644 --- a/gcc/ada/g-socket.adb +++ b/gcc/ada/g-socket.adb @@ -1673,7 +1673,7 @@ package body GNAT.Sockets is (Msg_Name => System.Null_Address, Msg_Namelen => 0, Msg_Iov => Vector'Address, - Msg_Iovlen => Vector'Length, + Msg_Iovlen => SOSC.Msg_Iovlen_T (Vector'Length), Msg_Control => System.Null_Address, Msg_Controllen => 0, Msg_Flags => 0); @@ -1904,11 +1904,11 @@ package body GNAT.Sockets is Count : out Ada.Streams.Stream_Element_Count; Flags : Request_Flag_Type := No_Request_Flag) is - use type C.size_t; + use type SOSC.Msg_Iovlen_T; Res : ssize_t; - Iov_Count : C.size_t; - This_Iov_Count : C.size_t; + Iov_Count : SOSC.Msg_Iovlen_T; + This_Iov_Count : SOSC.Msg_Iovlen_T; Msg : Msghdr; begin diff --git a/gcc/ada/g-socthi-mingw.ads b/gcc/ada/g-socthi-mingw.ads index f06f7a80a550..7b24eeec4e1f 100644 --- a/gcc/ada/g-socthi-mingw.ads +++ b/gcc/ada/g-socthi-mingw.ads @@ -54,17 +54,6 @@ package GNAT.Sockets.Thin is .. +(2 ** (C.size_t'Size - 1) - 1); -- Signed type of the same size as size_t - type Msghdr is record - Msg_Name : System.Address; - Msg_Namelen : C.unsigned; - Msg_Iov : System.Address; - Msg_Iovlen : C.size_t; - Msg_Control : System.Address; - Msg_Controllen : C.size_t; - Msg_Flags : C.int; - end record; - pragma Convention (C, Msghdr); - function Socket_Errno return Integer; -- Returns last socket error number diff --git a/gcc/ada/g-socthi-vms.ads b/gcc/ada/g-socthi-vms.ads index 6df93351edde..2fd5009db151 100644 --- a/gcc/ada/g-socthi-vms.ads +++ b/gcc/ada/g-socthi-vms.ads @@ -57,18 +57,6 @@ package GNAT.Sockets.Thin is .. +(2 ** (C.size_t'Size - 1) - 1); -- Signed type of the same size as size_t - type Msghdr is record - Msg_Name : System.Address; - Msg_Namelen : C.unsigned; - Msg_Iov : System.Address; - Msg_Iovlen : C.size_t; - Msg_Control : System.Address; - Msg_Controllen : C.size_t; - Msg_Flags : C.int; - end record; - pragma Convention (C, Msghdr); - -- This type needs comments??? - function Socket_Errno return Integer renames GNAT.OS_Lib.Errno; -- Returns last socket error number diff --git a/gcc/ada/g-socthi-vxworks.ads b/gcc/ada/g-socthi-vxworks.ads index 88638f99d021..4b6bd34d080a 100644 --- a/gcc/ada/g-socthi-vxworks.ads +++ b/gcc/ada/g-socthi-vxworks.ads @@ -55,17 +55,6 @@ package GNAT.Sockets.Thin is .. +(2 ** (C.size_t'Size - 1) - 1); -- Signed type of the same size as size_t - type Msghdr is record - Msg_Name : System.Address; - Msg_Namelen : C.unsigned; - Msg_Iov : System.Address; - Msg_Iovlen : C.size_t; - Msg_Control : System.Address; - Msg_Controllen : C.size_t; - Msg_Flags : C.int; - end record; - pragma Convention (C, Msghdr); - function Socket_Errno return Integer renames GNAT.OS_Lib.Errno; -- Returns last socket error number diff --git a/gcc/ada/g-socthi.ads b/gcc/ada/g-socthi.ads index 31cbce8148f9..b5186d062c61 100644 --- a/gcc/ada/g-socthi.ads +++ b/gcc/ada/g-socthi.ads @@ -59,17 +59,6 @@ package GNAT.Sockets.Thin is .. +(2 ** (C.size_t'Size - 1) - 1); -- Signed type of the same size as size_t - type Msghdr is record - Msg_Name : System.Address; - Msg_Namelen : C.unsigned; - Msg_Iov : System.Address; - Msg_Iovlen : C.size_t; - Msg_Control : System.Address; - Msg_Controllen : C.size_t; - Msg_Flags : C.int; - end record; - pragma Convention (C, Msghdr); - function Socket_Errno return Integer renames GNAT.OS_Lib.Errno; -- Returns last socket error number diff --git a/gcc/ada/g-sothco.ads b/gcc/ada/g-sothco.ads index 448677174a86..9a8672830fa6 100644 --- a/gcc/ada/g-sothco.ads +++ b/gcc/ada/g-sothco.ads @@ -243,6 +243,21 @@ package GNAT.Sockets.Thin_Common is pragma Convention (C, Hostent_Access); -- Access to host entry + ------------------------------------ + -- Scatter/gather vector handling -- + ------------------------------------ + + type Msghdr is record + Msg_Name : System.Address; + Msg_Namelen : C.unsigned; + Msg_Iov : System.Address; + Msg_Iovlen : SOSC.Msg_Iovlen_T; + Msg_Control : System.Address; + Msg_Controllen : C.size_t; + Msg_Flags : C.int; + end record; + pragma Convention (C, Msghdr); + ---------------------------- -- Socket sets management -- ---------------------------- diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi index 31e7080fb2cc..ec10ef1021c8 100644 --- a/gcc/ada/gnat_ugn.texi +++ b/gcc/ada/gnat_ugn.texi @@ -2992,17 +2992,18 @@ Interface ---see http://www.codesourcery.com/archives/cxx-abi). Interfacing can be done at 3 levels: simple data, subprograms, and classes. In the first two cases, GNAT offers a specific @code{Convention C_Plus_Plus} (or @code{CPP}) that behaves exactly like @code{Convention C}. -Usually, C++ mangles the names of subprograms, and currently, GNAT does -not provide any help to solve the demangling problem. This problem can be -addressed in two ways: +Usually, C++ mangles the names of subprograms. To generate proper mangled +names automatically, see @ref{Generating Ada Bindings for C and C++ headers}). +This problem can also be addressed manually in two ways: + @itemize @bullet @item by modifying the C++ code in order to force a C convention using the @code{extern "C"} syntax. @item -by figuring out the mangled name and use it as the Link_Name argument of -the pragma import. +by figuring out the mangled name (using e.g. @command{nm}) and using it as the +Link_Name argument of the pragma import. @end itemize @noindent @@ -3025,15 +3026,17 @@ considered: @item Using GNAT and G++ (GNU C++ compiler) from the same GCC installation: The C++ linker can simply be called by using the C++ specific driver -called @code{c++}. Note that this setup is not very common because it -may involve recompiling the whole GCC tree from sources, which makes it -harder to upgrade the compilation system for one language without -destabilizing the other. +called @code{g++}. + +Note that if the C++ code uses inline functions, you will need to +compile your C++ code with the @code{-fkeep-inline-functions} switch in +order to provide an existing function implementation that the Ada code can +link with. @smallexample -$ c++ -c file1.C -$ c++ -c file2.C -$ gnatmake ada_unit -largs file1.o file2.o --LINK=c++ +$ g++ -c -fkeep-inline-functions file1.C +$ g++ -c -fkeep-inline-functions file2.C +$ gnatmake ada_unit -largs file1.o file2.o --LINK=g++ @end smallexample @item @@ -3105,6 +3108,10 @@ a pre-linking phase using GNAT will be necessary. @end enumerate +Another alternative is to use the @command{gprbuild} multi-language builder +which has a large knowledge base and knows how to link Ada and C++ code +together automatically in most cases. + @node A Simple Example @subsection A Simple Example @noindent @@ -3122,10 +3129,10 @@ languages. Here are the compilation commands: @smallexample $ gnatmake -c simple_cpp_interface -$ c++ -c cpp_main.C -$ c++ -c ex7.C +$ g++ -c cpp_main.C +$ g++ -c ex7.C $ gnatbind -n simple_cpp_interface -$ gnatlink simple_cpp_interface -o cpp_main --LINK=$(CPLUSPLUS) +$ gnatlink simple_cpp_interface -o cpp_main --LINK=g++ -lstdc++ ex7.o cpp_main.o @end smallexample diff --git a/gcc/ada/s-oscons-tmplt.c b/gcc/ada/s-oscons-tmplt.c index c3511b9b52f1..24555f1278ad 100644 --- a/gcc/ada/s-oscons-tmplt.c +++ b/gcc/ada/s-oscons-tmplt.c @@ -1179,6 +1179,19 @@ CND(SIZEOF_fd_set, "fd_set"); TXT(" subtype H_Addrtype_T is Interfaces.C." h_addrtype_t ";") TXT(" subtype H_Length_T is Interfaces.C." h_length_t ";") +/* + + -- Fields of struct msghdr +*/ + +#if defined (__VMS) || defined (__sun__) || defined (__hpux__) +# define msg_iovlen_t "int" +#else +# define msg_iovlen_t "size_t" +#endif + +TXT(" subtype Msg_Iovlen_T is Interfaces.C." msg_iovlen_t ";") + /* ---------------------------------------- diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb index 40f15aec0191..e7cb9cc1651c 100644 --- a/gcc/ada/sem_aggr.adb +++ b/gcc/ada/sem_aggr.adb @@ -3298,6 +3298,8 @@ package body Sem_Aggr is -- We build a partially initialized aggregate with the -- values of the discriminants and box initialization -- for the rest, if other components are present. + -- The type of the aggregate is the known subtype of + -- the component. declare Loc : constant Source_Ptr := Sloc (N); @@ -3309,6 +3311,7 @@ package body Sem_Aggr is begin Expr := Make_Aggregate (Loc, New_List, New_List); + Set_Etype (Expr, Ctyp); Discr_Elmt := First_Elmt (Discriminant_Constraint (Ctyp)); -- 2.47.2