* Importing a Unix function call
@ 1998-12-04 0:00 Steve Crowe
1998-12-04 0:00 ` Larry Kilgallen
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Steve Crowe @ 1998-12-04 0:00 UTC (permalink / raw)
Someone has bound to have done this before... hopefully.
Using Ada to import a function is easy, but if the function parameter
returns
a value, how is the Ada error overcome. As I want the return value as
well
as the out parameter. Is there away round this using a pragma?
GNAT AdA compiler running under Unix, the function being imported is a
Unix 'pipe'.
Anyone have any ideas on this?
--
MZ�
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Importing a Unix function call
1998-12-04 0:00 Importing a Unix function call Steve Crowe
@ 1998-12-04 0:00 ` Larry Kilgallen
1998-12-04 0:00 ` David Botton
1998-12-04 0:00 ` dennison
1998-12-06 0:00 ` Matthew Heaney
2 siblings, 1 reply; 9+ messages in thread
From: Larry Kilgallen @ 1998-12-04 0:00 UTC (permalink / raw)
In article <36683FA3.2512DECF@ndirect.co.uk>, Steve Crowe <stevecrowe@ndirect.co.uk> writes:
> Using Ada to import a function is easy, but if the function parameter
> returns
> a value, how is the Ada error overcome. As I want the return value as
> well
> as the out parameter. Is there away round this using a pragma?
Use IMPORT_VALUED_PROCEDURE in Gnat or DEC Ada.
Your purpose is exactly why it exists.
Larry Kilgallen
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Importing a Unix function call
1998-12-04 0:00 ` Larry Kilgallen
@ 1998-12-04 0:00 ` David Botton
1998-12-05 0:00 ` Larry Kilgallen
0 siblings, 1 reply; 9+ messages in thread
From: David Botton @ 1998-12-04 0:00 UTC (permalink / raw)
Do you have a piece of sample code to illustrate this?
David Botton
Larry Kilgallen wrote in message <1998Dec4.154225.1@eisner>...
>In article <36683FA3.2512DECF@ndirect.co.uk>, Steve Crowe
<stevecrowe@ndirect.co.uk> writes:
>
>> Using Ada to import a function is easy, but if the function parameter
>> returns
>> a value, how is the Ada error overcome. As I want the return value as
>> well
>> as the out parameter. Is there away round this using a pragma?
>
>Use IMPORT_VALUED_PROCEDURE in Gnat or DEC Ada.
>
>Your purpose is exactly why it exists.
>
>Larry Kilgallen
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Importing a Unix function call
1998-12-04 0:00 Importing a Unix function call Steve Crowe
1998-12-04 0:00 ` Larry Kilgallen
@ 1998-12-04 0:00 ` dennison
1998-12-06 0:00 ` Matthew Heaney
2 siblings, 0 replies; 9+ messages in thread
From: dennison @ 1998-12-04 0:00 UTC (permalink / raw)
In article <36683FA3.2512DECF@ndirect.co.uk>,
Steve Crowe <stevecrowe@ndirect.co.uk> wrote:
> Someone has bound to have done this before... hopefully.
>
> Using Ada to import a function is easy, but if the function parameter
> returns
> a value, how is the Ada error overcome. As I want the return value as
> well
> as the out parameter. Is there away round this using a pragma?
>
> GNAT AdA compiler running under Unix, the function being imported is a
> Unix 'pipe'.
If you are using gnat, you can use pragma Import_Valued_Procedure.
The portable way around this problem is to pass the parameters the same way C
does: all "in"s, with some being pointer objects. C doesn't have "out"
parameters either, you know.
--
T.E.D.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Importing a Unix function call
1998-12-04 0:00 Importing a Unix function call Steve Crowe
1998-12-04 0:00 ` Larry Kilgallen
1998-12-04 0:00 ` dennison
@ 1998-12-06 0:00 ` Matthew Heaney
1998-12-06 0:00 ` David Botton
2 siblings, 1 reply; 9+ messages in thread
From: Matthew Heaney @ 1998-12-06 0:00 UTC (permalink / raw)
Steve Crowe <stevecrowe@ndirect.co.uk> writes:
> GNAT AdA compiler running under Unix, the function being imported is a
> Unix 'pipe'.
From my man page:
int pipe(int filedes[2]);
pipe creates a pair of file descriptors, pointing to a
pipe inode, and places them in the array pointed to by
filedes. filedes[0] is for reading, filedes[1] is for
writing.
C doesn't have out parameters: only in parameters that point to the
return data.
How about something like:
with Interfaces.C; use Interfaces;
package UNIX is
type File_Descriptor is new C.int;
type File_Descriptor_Array is
array (Positive range 1 .. 2) of File_Descriptor;
pragma Convention (C, File_Descriptor_Array);
type File_Descriptor_Array_Access is
access all File_Descriptor_Array;
pragma Convention (C, File_Descriptor_Array_Access);
function Pipe
(Files : in File_Descriptor_Array_Access)
return C.Int;
pragma Import (C, Pipe);
end UNIX;
You'd use it like:
declare
Files : alised File_Descriptor_Array;
Status : constant C.Int := Pipe (Files'Access);
begin
...
Is that what you had in mind?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Importing a Unix function call
1998-12-06 0:00 ` Matthew Heaney
@ 1998-12-06 0:00 ` David Botton
1998-12-06 0:00 ` Matthew Heaney
0 siblings, 1 reply; 9+ messages in thread
From: David Botton @ 1998-12-06 0:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1177 bytes --]
Since in Ada non-scalar types are passed by reference (ie as pointers) to C
functions you could get rid of the Access type and treat it just like C:
For our case see RM95 B.3 (70) :
� An Ada parameter of an array type with component type T, of any mode, is
passed as a t* argument to a C function, where t is the C type corresponding
to the Ada type T.
function Pipe
(Files : in File_Descriptor_Array)
return C.Int;
pragma Import (C, Pipe);
declare
Files : File_Descriptor_Array;
Status : constant C.Int := Pipe (Files);
begin
It drives me crazy that many bindings are not written with these rules in
mind making them so much easier to use.
David Botton
Matthew Heaney wrote in message ...
>Steve Crowe <stevecrowe@ndirect.co.uk> writes:
>
>From my man page:
>
> int pipe(int filedes[2]);
>
>C doesn't have out parameters: only in parameters that point to the
>return data.
>
>How about something like:
>
>with Interfaces.C; use Interfaces;
>package UNIX is
>
> type File_Descriptor is new C.int;
>
> type File_Descriptor_Array is
> array (Positive range 1 .. 2) of File_Descriptor;
>
> pragma Convention (C, File_Descriptor_Array);
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Importing a Unix function call
1998-12-06 0:00 ` David Botton
@ 1998-12-06 0:00 ` Matthew Heaney
1998-12-07 0:00 ` dennison
0 siblings, 1 reply; 9+ messages in thread
From: Matthew Heaney @ 1998-12-06 0:00 UTC (permalink / raw)
"David Botton" <dbotton@hotmail.com> writes:
> Since in Ada non-scalar types are passed by reference (ie as pointers) to C
> functions you could get rid of the Access type and treat it just like C:
The file descriptor array is an out parameter. The solution you propose
makes the array an in parameter.
I think this is another example of the fact that value-returning
subprograms (which we spell F-U-N-C-T-I-O-N in Ada) should be allowed to
have in out parameters.
Clearly, what we want is the function
function Pipe (Files : out File_Descriptor_Array) return Int;
but we can't express this thought using the language.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Importing a Unix function call
1998-12-06 0:00 ` Matthew Heaney
@ 1998-12-07 0:00 ` dennison
0 siblings, 0 replies; 9+ messages in thread
From: dennison @ 1998-12-07 0:00 UTC (permalink / raw)
In article <m3ogph5b2p.fsf@mheaney.ni.net>,
Matthew Heaney <matthew_heaney@acm.org> wrote:
> "David Botton" <dbotton@hotmail.com> writes:
>
> > Since in Ada non-scalar types are passed by reference (ie as pointers) to C
> > functions you could get rid of the Access type and treat it just like C:
>
> Clearly, what we want is the function
>
> function Pipe (Files : out File_Descriptor_Array) return Int;
>
> but we can't express this thought using the language.
Yes. But neither can C, so for our purposes here its a good enough match.
--
T.E.D.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~1998-12-07 0:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-04 0:00 Importing a Unix function call Steve Crowe
1998-12-04 0:00 ` Larry Kilgallen
1998-12-04 0:00 ` David Botton
1998-12-05 0:00 ` Larry Kilgallen
1998-12-04 0:00 ` dennison
1998-12-06 0:00 ` Matthew Heaney
1998-12-06 0:00 ` David Botton
1998-12-06 0:00 ` Matthew Heaney
1998-12-07 0:00 ` dennison
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox