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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1accf7a0502f27cd X-Google-Attributes: gid103376,public X-Google-Thread: 10dd18,1accf7a0502f27cd X-Google-Attributes: gid10dd18,public X-Google-ArrivalTime: 2000-08-31 19:08:18 PST Path: supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!nntp.primenet.com!nntp.gblx.net!feeder.via.net!headwall.stanford.edu!unlnews.unl.edu!newsfeed.ksu.edu!nntp.ksu.edu!news.okstate.edu!dvdeug From: dvdeug@x8b4e53cd.dhcp.okstate.edu (David Starner) Newsgroups: comp.lang.ada,comp.lang.python Subject: Re: Help with Calling Ada from Python Date: 1 Sep 2000 01:44:17 GMT Organization: Oklahoma State University Message-ID: <8on1lh$7hu1@news.cis.okstate.edu> References: Reply-To: dstarner98@aasaa.ofe.org NNTP-Posting-Host: x8b4e516e.dhcp.okstate.edu User-Agent: slrn/0.9.6.2 (Linux) Xref: supernews.google.com comp.lang.ada:455 comp.lang.python:3569 Date: 2000-09-01T01:44:17+00:00 List-Id: On Thu, 31 Aug 2000 18:36:27 -0600, David Hoffman 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@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"