From: lin@post.com (Lin)
Subject: Ada with Protected Object & Importing C program in Linux
Date: 13 Sep 2001 18:12:38 -0700
Date: 2001-09-14T01:12:39+00:00 [thread overview]
Message-ID: <86772402.0109131712.7583f07f@posting.google.com> (raw)
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 <stdio.h>
Calling_C(){
printf ("\nC is Called now");
}
----------------------
next reply other threads:[~2001-09-14 1:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-14 1:12 Lin [this message]
2001-09-14 1:33 ` Ada with Protected Object & Importing C program in Linux James Rogers
2001-09-15 14:50 ` Lin
2001-09-15 17:14 ` Lin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox