comp.lang.ada
 help / color / mirror / Atom feed
* Interfaces.C.Strings_Chars_Ptr as an out mode parameter
@ 1999-06-10  0:00 David C. Hoos, Sr.
  1999-06-11  0:00 ` Tucker Taft
  1999-06-11  0:00 ` dennison
  0 siblings, 2 replies; 3+ messages in thread
From: David C. Hoos, Sr. @ 1999-06-10  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1275 bytes --]

RM B.3.1 (1) may have something important to say by
what it does _not_ say, viz. :

The package Interfaces.C.Strings declares types and
subprograms allowing an Ada program to allocate,
reference, update, and free C-style strings. In
particular, the private type chars_ptr corresponds
to a common use of �char *� in C programs, and an
object of this type can be passed to a subprogram to
which pragma Import(C,...) has been applied, and for
which �char *� is the type of the argument of the C
function.

What is does _not_ say is that an object of this
type can be passed to a  subprogram to which pragma
Export(C,...) has been applied, and for which
�char *� is the type of the argument of the C
function.

So... the question is.. if one wishes to have a
procedure with a profile of, say:

procedure My_Proc (Result : out Interfaces.C.Strings.Chars_Ptr);

is it legal to export it like so:

pragma Export (C, My_Proc, "My_Proc");

where the C prototype is void My_Proc (char * result);

The results I'm having are that if the exported procedure
is called from Ada, everything works as expected.

If called from C, a Segmentation fault occurs at the
point where the out mode parameter is assigned its
value in the Ada procedure My_Proc.

What say ye?














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

* Re: Interfaces.C.Strings_Chars_Ptr as an out mode parameter
  1999-06-10  0:00 Interfaces.C.Strings_Chars_Ptr as an out mode parameter David C. Hoos, Sr.
  1999-06-11  0:00 ` Tucker Taft
@ 1999-06-11  0:00 ` dennison
  1 sibling, 0 replies; 3+ messages in thread
From: dennison @ 1999-06-11  0:00 UTC (permalink / raw)


In article <7jpe2e$m7i@hobbes.crc.com>,
  "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> wrote:
> procedure My_Proc (Result : out Interfaces.C.Strings.Chars_Ptr);
>
> is it legal to export it like so:
>
> pragma Export (C, My_Proc, "My_Proc");
>
> where the C prototype is void My_Proc (char * result);
>
> The results I'm having are that if the exported procedure
> is called from Ada, everything works as expected.
>
> If called from C, a Segmentation fault occurs at the
> point where the out mode parameter is assigned its
> value in the Ada procedure My_Proc.

If the implementation advice in the RM is followed, then your Ada
"myproc" is equivalent to a C "My_Proc (char ** result)". To get the
equivalent of a C "My_Proc (char * result)" you should either change
your mode to "in" or change your type to "Interfaces.C.Signed_Char"


--
T.E.D.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




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

* Re: Interfaces.C.Strings_Chars_Ptr as an out mode parameter
  1999-06-10  0:00 Interfaces.C.Strings_Chars_Ptr as an out mode parameter David C. Hoos, Sr.
@ 1999-06-11  0:00 ` Tucker Taft
  1999-06-11  0:00 ` dennison
  1 sibling, 0 replies; 3+ messages in thread
From: Tucker Taft @ 1999-06-11  0:00 UTC (permalink / raw)


David C. Hoos, Sr. wrote:
> ...
> So... the question is.. if one wishes to have a
> procedure with a profile of, say:
> 
> procedure My_Proc (Result : out Interfaces.C.Strings.Chars_Ptr);
> 
> is it legal to export it like so:
> 
> pragma Export (C, My_Proc, "My_Proc");
> 
> where the C prototype is void My_Proc (char * result);

The C prototype should be:  void My_Proc (char ** result);
because "out" parameters are given an extra level of indirection.
The caller must also use "&" on the actual parameter (in C).

> The results I'm having are that if the exported procedure
> is called from Ada, everything works as expected.
> 
> If called from C, a Segmentation fault occurs at the
> point where the out mode parameter is assigned its
> value in the Ada procedure My_Proc.

Doesn't surprise me.

> What say ye?

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




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

end of thread, other threads:[~1999-06-11  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-10  0:00 Interfaces.C.Strings_Chars_Ptr as an out mode parameter David C. Hoos, Sr.
1999-06-11  0:00 ` Tucker Taft
1999-06-11  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