Help with Calling Ada from Python

David Starner dvdeug at x8b4e53cd.dhcp.okstate.edu
Thu Aug 31 21:44:17 EDT 2000


On Thu, 31 Aug 2000 18:36:27 -0600, David Hoffman <hoffman at insync.net> wrote:
>To create a Python extension in C, a module initialization function
>must be provided (in this case it is called initnumberPlay()). It is
>clear to me that the call to adainit(), which starts the Ada runtime,
>could easily be put into this function so that the Ada runtime would
>be started when the module is loaded. But how can I ensure that the
>Ada runtime is shutdown when the module exits? 

You may want to ask this on a Python newsgroup, because basically
runs down to "How do run a finialization procedure for a module
in Python?" which has the same answer whether you're doing it
in C or Ada.

>function Factorial ( N : Integer ) return Integer is
>  begin
>     if N = 1 then
>        return 1;
>     else
>        return N * Factorial(N-1);
>     end if;
>  end;

>function Ada_Factorial ( Value : C.Long ) return C.Long is
>   P, Q : Integer;
>begin
>   P := Integer(Value);
>   Q := Factorial(P);
>   return C.Long(Q);
>end;

Why are you doing this? C.Long is a perfectly good type. It's a modulus
type, so you're losing integer range checking, but you probably don't
have that anyway (you have to compile with -gnato to get it). You lose
range doing it this way (C.long is 64 bits on GNAT on ix86, whereas
Integer is 32), and you slow it down. 

On integer range checking, I would either supress all exceptions or 
make sure I caught them in Ada code. I believe the exceptions should
propogate through the C code (including Python), but at best it will
crash Python.

>This example was built under Linux (kernel 2.0.33, libc 5.4.33) using 
>the GNAT Ada compiler (version 3.11p). It runs under Python 1.5. 

Umm, archaic. Is there any particular reason why? Both GNAT 3.11 and 
libc 5 are very old versions, for which I don't recall any good reasons
to be running them.

-- 
David Starner - dstarner98 at aasaa.ofe.org
http/ftp: dvdeug.net.dhis.org
It was starting to rain on the night that they cried forever,
It was blinding with snow on the night that they screamed goodbye.
	- Dio, "Rock and Roll Children"



More information about the Python-list mailing list