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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b19471aa234c3c08,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-13 18:12:39 PST Path: archiver1.google.com!newsfeed.google.com!postnews1.google.com!not-for-mail From: lin@post.com (Lin) Newsgroups: comp.lang.ada Subject: Ada with Protected Object & Importing C program in Linux Date: 13 Sep 2001 18:12:38 -0700 Organization: http://groups.google.com/ Message-ID: <86772402.0109131712.7583f07f@posting.google.com> NNTP-Posting-Host: 144.32.177.108 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1000429959 13297 127.0.0.1 (14 Sep 2001 01:12:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 14 Sep 2001 01:12:39 GMT Xref: archiver1.google.com comp.lang.ada:13070 Date: 2001-09-14T01:12:39+00:00 List-Id: 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"); } ----------------------