comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Memory Access
Date: Mon, 07 Nov 2011 23:26:04 +0100
Date: 2011-11-07T23:26:04+01:00	[thread overview]
Message-ID: <9hr483F3liU1@mid.individual.net> (raw)
In-Reply-To: <f4a52e5d-2514-4713-a68d-877f09af7ec3@d17g2000yql.googlegroups.com>

On 11-11-07 21:09 , awdorrin wrote:
> I am trying to migrate source code from an older AdaMulti compiler
> than ran on Solaris to GNAT on Linux.
>
> The original program makes use of shared memory and has structures
> populated in C code that are accessed within Ada code.

By "shared memory", do you mean the "System V" inter-process 
communication mechanism that involves kernel calls to map shared memory 
areas into the address space of a process? Or do you mean just some 
variables within one and the same process and address space that are 
shared (accessed) by different threads, in different languages, but 
within the same process and same address space?

Are the structures (variables) defined (that is, allocated) in C code 
and imported into the Ada code, or vice versa?

Are they statically allocated or dynamically allocated?

How are the variables passed between the C code and the Ada code? As 
parameters in subprogram calls, or through some kind of global pointers 
or addresses?

> The original developers used some AdaMulti 'features' that do not
> appear to exist within GNAT to play some tricks on setting up a
> pointer as an array of records.
>
> For instance:
>
> Config_Type is an Ada Record which matches a C struct.
> A Dev_Table is used as an array of these Config_Type records.
>
> The original code has the following statements:
>
> type Dev_Table_Type is array (Device_Num_Type range<>) of
> Config_Type;
> type Dev_Table_Ptr_Type is access Dev_Table_Type;
> Dev_Table := Dev_Table_Ptr_Type;
> Bounds_Ptr : Global_Types.Int_Ptr_Type;
>
> Then, in the Ada Procedure we have:
>
> Dev_Data_Obj := Get_Object_Pointer( Dev_Data_Obj_Name );

What is Dev_Data_Obj_Name?
What is Get_Object_Pointer?
What is Dev_Data_Obj?

>
> Dev_Table := To_Dev_Table_Ptr( Get_UDP( Dev_Data_Obj) );

What is Get_UDP?

>
> Bounds_Ptr := Dev_Table_Ptr_To_Int_Ptr( Dev_Table );
> Bounds_Ptr.all := 1;
>
> Bounds_Ptr := Int_To_Int_Ptr( Dev_Table_Ptr_To_Int( Dev_Table ) + 4);
> Bounds_Ptr.all := Int32( Num_Devs_Cnst );

What is Num_Devs_Cnst? Is it a static (compile-time) constant, or a 
dynamically computed variable?

>
> The To_Dev_Table_Ptr, Dev_Table_Ptr_To_Int_Ptr, Int_To_Int_Ptr are all
> unchecked conversion methods.

Such conversions beween access types and other types should be avoided 
(as unportable). Current Ada has better facilities (see 
System.Address_To_Access_Conversions, if my memory serves; can't look it 
up, sorry, my mobile net connection is too puny).

>
> I understand that the Bounds_Ptr is being used to assign array
> constraints to the dope vector.

That looks likely, from the code above.

> But I'm guessing that GNAT doesn't
> define these dope vectors using this sort of definition.

Whatever kind of dope vectors GNAT has, one should not access them 
through such low-level and unportable tricks.

>
> I'm
> making the assumption that the way this code was implemented
> (somewhere between 1992 and 98) was not really the right way to
> approach this problem.

I fully agree with that.

> But I'm not sure what method should be used,
> and haven't had much luck the past few days searching the web and
> newsgroups.
>
> I would have thought I could have defined the Dev_Table differently,
> perhaps:
>
> Dev_Table : Dev_Table_Ptr_Type := new Dev_Table_Type( 1 ..
> Num_Devs_Cnst );
>
> If I knew the address of pointer at the time of declaration I figured
> I could do:
>
> for Dev_Table'Address use {address_of_memory_array} - but I won't know
> that until run time, so I'm not sure how I can assign that properly.
>
> I hope I'm making sense here - because I'm pretty confused about all
> of this at the moment... :-)

I think you are on the right track, or tracks, but the solution depends 
on the answers to my questions above.

While waiting for the answers: I hope you are already using pragma 
Convention to tell the Ada compiler to lay out the Ada record types and 
array types following the C conventions.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



  parent reply	other threads:[~2011-11-07 22:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-07 20:09 Memory Access awdorrin
2011-11-07 21:26 ` Simon Wright
2011-11-07 22:03 ` anon
2011-11-07 22:21 ` Adam Beneschan
2011-11-07 22:42   ` Adam Beneschan
2011-11-07 23:13   ` Simon Wright
2011-11-07 23:32     ` Adam Beneschan
2011-11-08 12:22       ` awdorrin
2011-11-08 16:00         ` Adam Beneschan
2011-11-08 17:46           ` awdorrin
2011-11-08 20:11             ` Adam Beneschan
2011-11-08 20:24               ` awdorrin
2011-11-09 14:42                 ` awdorrin
2011-11-08 16:10         ` awdorrin
2011-11-08 18:33           ` Simon Wright
2011-11-08 18:34             ` Simon Wright
2011-11-08 20:18             ` awdorrin
2011-11-08 12:44       ` Simon Wright
2011-11-07 22:26 ` Niklas Holsti [this message]
2011-11-07 22:53   ` Adam Beneschan
replies disabled

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