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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b19471aa234c3c08 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-13 18:33:06 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.direct.ca!look.ca!wn1feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc05-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3BA15E67.D41D1D84@worldnet.att.net> From: James Rogers X-Mailer: Mozilla 4.76 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada with Protected Object & Importing C program in Linux References: <86772402.0109131712.7583f07f@posting.google.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 14 Sep 2001 01:33:05 GMT NNTP-Posting-Host: 12.81.170.28 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1000431185 12.81.170.28 (Fri, 14 Sep 2001 01:33:05 GMT) NNTP-Posting-Date: Fri, 14 Sep 2001 01:33:05 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:13071 Date: 2001-09-14T01:33:05+00:00 List-Id: Lin wrote: > > I've a problem of binding an Ada program(with protected objects) with > C programs in Linux. Any clue is helpful to me. Thanks. > > The working environment is Slackware Linux,Gnat3.13p > My problem: In Linux, the program with protected object can work fine > without importing a C program; the program will raise "Segmentation > fault when it imports a C program. The same program works fine in > WinNT. The code is shown below, which is to asks the protected object > for an new request id. > > --------------------- > ---Ada programs-- > --------------------- > with my_test; > with Ada.Text_IO;use Ada.Tex_IO; > procedure my_main is > my_id : my_test.Request_Id_Type := 0; > begin > Put_Line ("Hello World!!"); > for i in 1 .. 10 loop > my_test.Allocate_New_Id (my_id); > my_test.Calling_C; > Put_Line ( > "Request id=" & my_test.Request_Id_Type'Image (my_id)); > end loop; > end my_main; > ------------ > package my_test is > type Request_Id_Type is mod 2 ** 16; > procedure Allocate_New_Id (Id : out Request_Id_Type); > procedure Calling_C; > pragma Import (C, Calling_C); > pragma Import_Procedure (Calling_C, "Calling_C"); > end my_test; > ------------ > package body my_test is > type Is_Used_Array is array (Request_Id_Type) of Boolean; > protected type Request_Id_Server_Type is > entry Get (Id : out Request_Id_Type); > procedure Free (Id : in Request_Id_Type); > private > Latest : Request_Id_Type := Request_Id_Type'First; > Is_Used : Is_Used_Array := (others => False); > Count : Request_Id_Type := 0; > end Request_Id_Server_Type; > > protected body Request_Id_Server_Type > is > procedure Free (Id : in Request_Id_Type) > is > begin > if Is_Used (Id) then > Is_Used (Id) := False; > Count := Count - 1; > end if; > end Free; > > entry Get (Id : out Request_Id_Type) > when Count < Request_Id_Type'Last is > begin > while Is_Used (Latest) > loop > Latest := Latest + 1; > end loop; > Id := Latest; > Is_Used (Id) := True; > Count := Count + 1; > Latest := Latest + 1; > end Get; > end Request_Id_Server_Type; > type Access_Request_Id_Server_Type is access > Request_Id_Server_Type; > Request_Id_Server : Access_Request_Id_Server_Type := > new > Request_Id_Server_Type; > procedure Allocate_New_Id (Id : out Request_Id_Type) > is > begin > Request_Id_Server.Get (Id); > end Allocate_New_Id; > end my_test; > --------------------- > ---the C program--- > --------------------- > #include > Calling_C(){ > printf ("\nC is Called now"); > } > ---------------------- This C function does not match the signature of the procedure "Calling_C". The function Calling_C does not return void. A C program will return "int" unless you specify otherwise. Either the C function or the Ada procedure must be modified so that they both agree. Jim Rogers Colorado Springs, Colorado USA