* Ada with Protected Object & Importing C program in Linux
@ 2001-09-14 1:12 Lin
2001-09-14 1:33 ` James Rogers
0 siblings, 1 reply; 4+ messages in thread
From: Lin @ 2001-09-14 1:12 UTC (permalink / 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");
}
----------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Ada with Protected Object & Importing C program in Linux
2001-09-14 1:12 Ada with Protected Object & Importing C program in Linux Lin
@ 2001-09-14 1:33 ` James Rogers
2001-09-15 14:50 ` Lin
2001-09-15 17:14 ` Lin
0 siblings, 2 replies; 4+ messages in thread
From: James Rogers @ 2001-09-14 1:33 UTC (permalink / raw)
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 <stdio.h>
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Ada with Protected Object & Importing C program in Linux
2001-09-14 1:33 ` James Rogers
@ 2001-09-15 14:50 ` Lin
2001-09-15 17:14 ` Lin
1 sibling, 0 replies; 4+ messages in thread
From: Lin @ 2001-09-15 14:50 UTC (permalink / raw)
Thanks for the advice. But after adding "void" before the C routine,
it still raise "segmentation error".
---------------------
---the C program---
---------------------
#include <stdio.h>
Calling_C(){
printf ("\nC is Called now");
}
----------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Ada with Protected Object & Importing C program in Linux
2001-09-14 1:33 ` James Rogers
2001-09-15 14:50 ` Lin
@ 2001-09-15 17:14 ` Lin
1 sibling, 0 replies; 4+ messages in thread
From: Lin @ 2001-09-15 17:14 UTC (permalink / raw)
After I get rid of the Java shared library from the compile command,
the program works fine.
Actually, I need to use Ada to create JVM via a C program in Linux,
and the Ada program includes a protected object to update data as
well. That is, the compile command needs to include Java shared
library(-ljvm, -lhpi, -ljava). Without the protected object, Ada can
create JVM successfully,but when adding the protected object, it
raises the "segmentation fault". It seems that the protected object in
Ada is not compatible with Java shared library.
Anybody has ever used the combination of Ada protected object and Java
shared library?
Many Thanks,
Linda
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-09-15 17:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-14 1:12 Ada with Protected Object & Importing C program in Linux Lin
2001-09-14 1:33 ` James Rogers
2001-09-15 14:50 ` Lin
2001-09-15 17:14 ` Lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox