Commit 51ec70b8 by Arnaud Charlet

[multiple changes]

2009-04-29  Arnaud Charlet  <charlet@adacore.com>

	* gnat_ugn.texi: Update some documentation about interfacing with C++
	Mention -fkeep-inline-functions.

	* gnat_ugn.texi: Minor edits

2009-04-29  Ed Schonberg  <schonberg@adacore.com>

	* 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  <lee@adacore.com>

	* 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.

From-SVN: r146969
parent 9e895ab5
2009-04-29 Arnaud Charlet <charlet@adacore.com>
* gnat_ugn.texi: Update some documentation about interfacing with C++
Mention -fkeep-inline-functions.
* gnat_ugn.texi: Minor edits
2009-04-29 Ed Schonberg <schonberg@adacore.com>
* 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 <lee@adacore.com>
* 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 <celier@adacore.com> 2009-04-29 Vincent Celier <celier@adacore.com>
* sinput-l.adb (Load_File): When preprocessing, set temporarily the * sinput-l.adb (Load_File): When preprocessing, set temporarily the
......
...@@ -1673,7 +1673,7 @@ package body GNAT.Sockets is ...@@ -1673,7 +1673,7 @@ package body GNAT.Sockets is
(Msg_Name => System.Null_Address, (Msg_Name => System.Null_Address,
Msg_Namelen => 0, Msg_Namelen => 0,
Msg_Iov => Vector'Address, Msg_Iov => Vector'Address,
Msg_Iovlen => Vector'Length, Msg_Iovlen => SOSC.Msg_Iovlen_T (Vector'Length),
Msg_Control => System.Null_Address, Msg_Control => System.Null_Address,
Msg_Controllen => 0, Msg_Controllen => 0,
Msg_Flags => 0); Msg_Flags => 0);
...@@ -1904,11 +1904,11 @@ package body GNAT.Sockets is ...@@ -1904,11 +1904,11 @@ package body GNAT.Sockets is
Count : out Ada.Streams.Stream_Element_Count; Count : out Ada.Streams.Stream_Element_Count;
Flags : Request_Flag_Type := No_Request_Flag) Flags : Request_Flag_Type := No_Request_Flag)
is is
use type C.size_t; use type SOSC.Msg_Iovlen_T;
Res : ssize_t; Res : ssize_t;
Iov_Count : C.size_t; Iov_Count : SOSC.Msg_Iovlen_T;
This_Iov_Count : C.size_t; This_Iov_Count : SOSC.Msg_Iovlen_T;
Msg : Msghdr; Msg : Msghdr;
begin begin
......
...@@ -54,17 +54,6 @@ package GNAT.Sockets.Thin is ...@@ -54,17 +54,6 @@ package GNAT.Sockets.Thin is
.. +(2 ** (C.size_t'Size - 1) - 1); .. +(2 ** (C.size_t'Size - 1) - 1);
-- Signed type of the same size as size_t -- 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; function Socket_Errno return Integer;
-- Returns last socket error number -- Returns last socket error number
......
...@@ -57,18 +57,6 @@ package GNAT.Sockets.Thin is ...@@ -57,18 +57,6 @@ package GNAT.Sockets.Thin is
.. +(2 ** (C.size_t'Size - 1) - 1); .. +(2 ** (C.size_t'Size - 1) - 1);
-- Signed type of the same size as size_t -- 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; function Socket_Errno return Integer renames GNAT.OS_Lib.Errno;
-- Returns last socket error number -- Returns last socket error number
......
...@@ -55,17 +55,6 @@ package GNAT.Sockets.Thin is ...@@ -55,17 +55,6 @@ package GNAT.Sockets.Thin is
.. +(2 ** (C.size_t'Size - 1) - 1); .. +(2 ** (C.size_t'Size - 1) - 1);
-- Signed type of the same size as size_t -- 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; function Socket_Errno return Integer renames GNAT.OS_Lib.Errno;
-- Returns last socket error number -- Returns last socket error number
......
...@@ -59,17 +59,6 @@ package GNAT.Sockets.Thin is ...@@ -59,17 +59,6 @@ package GNAT.Sockets.Thin is
.. +(2 ** (C.size_t'Size - 1) - 1); .. +(2 ** (C.size_t'Size - 1) - 1);
-- Signed type of the same size as size_t -- 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; function Socket_Errno return Integer renames GNAT.OS_Lib.Errno;
-- Returns last socket error number -- Returns last socket error number
......
...@@ -243,6 +243,21 @@ package GNAT.Sockets.Thin_Common is ...@@ -243,6 +243,21 @@ package GNAT.Sockets.Thin_Common is
pragma Convention (C, Hostent_Access); pragma Convention (C, Hostent_Access);
-- Access to host entry -- 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 -- -- Socket sets management --
---------------------------- ----------------------------
......
...@@ -2992,17 +2992,18 @@ Interface ---see http://www.codesourcery.com/archives/cxx-abi). ...@@ -2992,17 +2992,18 @@ Interface ---see http://www.codesourcery.com/archives/cxx-abi).
Interfacing can be done at 3 levels: simple data, subprograms, and Interfacing can be done at 3 levels: simple data, subprograms, and
classes. In the first two cases, GNAT offers a specific @code{Convention 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}. C_Plus_Plus} (or @code{CPP}) that behaves exactly like @code{Convention C}.
Usually, C++ mangles the names of subprograms, and currently, GNAT does Usually, C++ mangles the names of subprograms. To generate proper mangled
not provide any help to solve the demangling problem. This problem can be names automatically, see @ref{Generating Ada Bindings for C and C++ headers}).
addressed in two ways: This problem can also be addressed manually in two ways:
@itemize @bullet @itemize @bullet
@item @item
by modifying the C++ code in order to force a C convention using by modifying the C++ code in order to force a C convention using
the @code{extern "C"} syntax. the @code{extern "C"} syntax.
@item @item
by figuring out the mangled name and use it as the Link_Name argument of by figuring out the mangled name (using e.g. @command{nm}) and using it as the
the pragma import. Link_Name argument of the pragma import.
@end itemize @end itemize
@noindent @noindent
...@@ -3025,15 +3026,17 @@ considered: ...@@ -3025,15 +3026,17 @@ considered:
@item @item
Using GNAT and G++ (GNU C++ compiler) from the same GCC installation: 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 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 called @code{g++}.
may involve recompiling the whole GCC tree from sources, which makes it
harder to upgrade the compilation system for one language without Note that if the C++ code uses inline functions, you will need to
destabilizing the other. 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 @smallexample
$ c++ -c file1.C $ g++ -c -fkeep-inline-functions file1.C
$ c++ -c file2.C $ g++ -c -fkeep-inline-functions file2.C
$ gnatmake ada_unit -largs file1.o file2.o --LINK=c++ $ gnatmake ada_unit -largs file1.o file2.o --LINK=g++
@end smallexample @end smallexample
@item @item
...@@ -3105,6 +3108,10 @@ a pre-linking phase using GNAT will be necessary. ...@@ -3105,6 +3108,10 @@ a pre-linking phase using GNAT will be necessary.
@end enumerate @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 @node A Simple Example
@subsection A Simple Example @subsection A Simple Example
@noindent @noindent
...@@ -3122,10 +3129,10 @@ languages. ...@@ -3122,10 +3129,10 @@ languages.
Here are the compilation commands: Here are the compilation commands:
@smallexample @smallexample
$ gnatmake -c simple_cpp_interface $ gnatmake -c simple_cpp_interface
$ c++ -c cpp_main.C $ g++ -c cpp_main.C
$ c++ -c ex7.C $ g++ -c ex7.C
$ gnatbind -n simple_cpp_interface $ 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 -lstdc++ ex7.o cpp_main.o
@end smallexample @end smallexample
...@@ -1181,6 +1181,19 @@ TXT(" subtype H_Length_T is Interfaces.C." h_length_t ";") ...@@ -1181,6 +1181,19 @@ 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 ";")
/*
---------------------------------------- ----------------------------------------
-- Properties of supported interfaces -- -- Properties of supported interfaces --
---------------------------------------- ----------------------------------------
......
...@@ -3298,6 +3298,8 @@ package body Sem_Aggr is ...@@ -3298,6 +3298,8 @@ package body Sem_Aggr is
-- We build a partially initialized aggregate with the -- We build a partially initialized aggregate with the
-- values of the discriminants and box initialization -- values of the discriminants and box initialization
-- for the rest, if other components are present. -- for the rest, if other components are present.
-- The type of the aggregate is the known subtype of
-- the component.
declare declare
Loc : constant Source_Ptr := Sloc (N); Loc : constant Source_Ptr := Sloc (N);
...@@ -3309,6 +3311,7 @@ package body Sem_Aggr is ...@@ -3309,6 +3311,7 @@ package body Sem_Aggr is
begin begin
Expr := Make_Aggregate (Loc, New_List, New_List); Expr := Make_Aggregate (Loc, New_List, New_List);
Set_Etype (Expr, Ctyp);
Discr_Elmt := Discr_Elmt :=
First_Elmt (Discriminant_Constraint (Ctyp)); First_Elmt (Discriminant_Constraint (Ctyp));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment