comp.lang.ada
 help / color / mirror / Atom feed
From: James Alan Farrell <anonymous@anonymous.com>
Subject: Question on interface Ada to C
Date: Tue, 25 May 2004 17:00:51 -0400
Date: 2004-05-25T17:00:51-04:00	[thread overview]
Message-ID: <rac7b0tnlsoauhcharlguhr7v3g30npk6b@4ax.com> (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;



             reply	other threads:[~2004-05-25 21:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-25 21:00 James Alan Farrell [this message]
2004-05-25 21:30 ` Question on interface Ada to C 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
replies disabled

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