From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7f18265ce67560b3 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.50.169 with SMTP id d9mr1170672pbo.0.1320704777203; Mon, 07 Nov 2011 14:26:17 -0800 (PST) Path: h5ni10164pba.0!nntp.google.com!news2.google.com!news4.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Memory Access Date: Mon, 07 Nov 2011 23:26:04 +0100 Organization: Tidorum Ltd Message-ID: <9hr483F3liU1@mid.individual.net> References: Mime-Version: 1.0 X-Trace: individual.net 4UxIKGtdSNprN+z3wSFhlgdqkeWukgiRAboBC5qvYKKynsOXPP Cancel-Lock: sha1:5mhqMlG1eV+vBBjmq95jgqXM7VY= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 In-Reply-To: Xref: news2.google.com comp.lang.ada:14331 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2011-11-07T23:26:04+01:00 List-Id: 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 . @ .