comp.lang.ada
 help / color / mirror / Atom feed
* Question on interface Ada to C
@ 2004-05-25 21:00 James Alan Farrell
  2004-05-25 21:30 ` Dale Stanbrough
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: James Alan Farrell @ 2004-05-25 21:00 UTC (permalink / raw)


Hello all,
I've inherited a project that is half written in C and half in Ada.
I'm finding a lot of code  like that below (this is psuedocode and I
do not know that it will compile.  It gives the idea of what is going
without revealing company proprietary information)

The procedure is called by C.  It passes back a pointer to list, which
the C code uses to read data from list.

It seems to me that this is not safe because of the possibility that
the memory that holding the data will "go away" (be deallocated,
removed from the stack or whatever happens in this situation).

My boss at first thought this was good code but when he took a second
look he wasn't so sure.  So he's asked me to investigate.  What
exactly happens with the memory used by list in this situation?

We're using GNAT, but I don't think that's an issue -- I would think
this code would behave (or misbehave) the same no matter what
compiler.

Thanks,
James Alan Farrell
GrammaTech.

 type stuff is integer; -- just for example

 type List_Type is array(Integer range <>) of stuff;
 
 package MyPointers is 
              new System.Address_To_Access_Conversions(List_Type);
 subtype List_Pointer is MyPointers.Object_Pointer;

 procedure MyProc
     (Items     : in out List_Pointer;
      Nitems    : in out Integer) is

      List : List_Type := function_that_returns_a_list;

   begin
      Nitems := List'Length;
      Items  := MyPointers.To_Pointer(List'Address);
   end;



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

end of thread, other threads:[~2004-05-26 16:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-25 21:00 Question on interface Ada to C James Alan Farrell
2004-05-25 21:30 ` Dale Stanbrough
2004-05-25 21:38 ` Simon Wright
2004-05-26 10:23   ` Dale Stanbrough
2004-05-26 13:05   ` James Alan Farrell
2004-05-26 16:01     ` Martin Krischik
2004-05-26  7:34 ` Martin Krischik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox