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.7 required=5.0 tests=BAYES_00,MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f58edf3a3fc00db X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-21 10:20:05 PST Path: supernews.google.com!sn-xit-02!supernews.com!router1.news.adelphia.net!cyclone.news.idirect.com.MISMATCH!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!nntp2.deja.com!nnrp1.deja.com!not-for-mail From: Chris Newsgroups: comp.lang.ada Subject: Re: Interface to C; Storage_Error Date: Thu, 21 Dec 2000 18:07:25 GMT Organization: Deja.com Message-ID: <91tgsm$grq$1@nnrp1.deja.com> References: <91ondg$lpu$1@nnrp1.deja.com> <3a409667.1742507013@paragate1> <91qote$9cj$1@nnrp1.deja.com> <91rh14$vco$1@nnrp1.deja.com> <3a422218.1843803860@paragate1> NNTP-Posting-Host: 63.164.137.27 To: twolf@acm.org X-Article-Creation-Date: Thu Dec 21 18:07:25 2000 GMT X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) X-Http-Proxy: 1.1 x63.deja.com:80 (Squid/1.1.22) for client 63.164.137.27 X-MyDeja-Info: XMYDJUIDenderx12 Xref: supernews.google.com comp.lang.ada:3327 Date: 2000-12-21T18:07:25+00:00 List-Id: In article <3a422218.1843803860@paragate1>, twolf@acm.org wrote: > Try this: (It compiles, but of course I may have misunderstood > something in your C code, or introduced new blunders. Use at > your own risk, and don't blame me for bugs!) > > Let me know whether or not it works... Yes, it does!! Thank you incredibly much. A few comments and/or questions, though... > procedure Get_Next_Value > -- Raises Constraint_Error if 'Name' is not long enough to hold the > -- full name returned by the underlying C routine. Otherwise, > -- Name (Name'First .. Last) contains the name as returned by the C > -- routine (without a trailing NUL character). Not an issue; the C library is "guaranteed" to expect a 255-byte array. > type C_Context is > record > Server : SRV_HANDLE := Interfaces.C.Strings.Null_Ptr; > Results : RSLT_HANDLE := Interfaces.C.Strings.Null_Ptr; > Current : CTX_HANDLE := Interfaces.C.Strings.Null_Ptr; > end record; Is there any particular reason that wrapping these in a context record would make a difference, as opposed to passing the handles individually as "in out RSLT_HANDLE", for example? I can see the point of having them as private types, but it shouldn't affect how they get passed to C, should it? > procedure Lookup > (Status : out C_Error_Code; > Server : in SRV_HANDLE; > Name : in Interfaces.C.Char_Array; > Results : in out RSLT_HANDLE); > pragma Import (C, Lookup, "LookupResults"); > pragma Import_Valued_Procedure (Lookup); Okay... this is the part I *really* want to understand. Why does "in out RSLT_HANDLE" work and "access RSLT_HANDLE" doesn't? There is certainly a semantic difference, but isn't access closer to the C semantics? And how would they be differently implemented by the compiler (GNAT in this case, but interested in general)? > if Status = Success then > Interfaces.C.To_Ada (C_String, Name, Last); This was the only change I really had to make: Interfaces.C.To_Ada ( Item => C_String, Target => Name, Count => Last, Trim_Nul => False ); I'm not entirely sure why that matters, but if I think about if for a bit I'm sure it will make sense. It wasn't raising Terminator_Error without it, but generally just getting junk. > Dr. Thomas Wolf (twolf@acm.org) Again, I am grateful and indebted for the assistance. I just wish I got to use Ada more often so I keep sharp. (The tragedy is that the client will probably rewrite it in C++ so it's "easier to maintain".) --chris Sent via Deja.com http://www.deja.com/