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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,fb17569fccf2604b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!s21g2000prm.googlegroups.com!not-for-mail From: Jerry Newsgroups: comp.lang.ada Subject: Re: Trouble writing Ada callback from C Date: Fri, 11 Sep 2009 22:28:05 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2db6b2d3-88c6-43ae-b1e8-4bcb44ce2ee3@s21g2000prm.googlegroups.com> References: NNTP-Posting-Host: 75.172.194.61 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1252733286 10982 127.0.0.1 (12 Sep 2009 05:28:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 12 Sep 2009 05:28:06 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s21g2000prm.googlegroups.com; posting-host=75.172.194.61; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/528.16+(KHTML, like Gecko, Safari/528.16) OmniWeb/v622.8.0,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8297 Date: 2009-09-11T22:28:05-07:00 List-Id: On Sep 11, 1:24=A0am, Ludovic Brenta wrote: > > I take it you mean "not known at compile time" because it is indeed > "known at call time". > > C doesn't have proper strings; it has pointers to null-terminated > arrays of characters, which do not carry bounds information. So, the > specification of your callback is not "return a string in an array" > but "write N characters starting where label points, where N+1 < > a_length, followed by a null character (ASCII.NUL)". =A0Here is a > possible implementation (not compiled or tested either): > > with Interfaces.C.Strings; use Interfaces.C.Strings; > procedure geolocation_labeler (label : in chars_ptr; length : in > size_t) is > =A0 =A0Result : constant String :=3D " N"; -- or whatever > begin > =A0 =A0Update (Item =3D> label, Offset =3D> 0, Str =3D> To_C (Result), Ch= eck =3D> > False); > =A0 =A0-- See AARM B.3.1(43, 50.a/2) > exception > =A0 =A0when others =3D> > =A0 =A0 =A0 -- Important: callbacks must handle all exceptions because th= e C > layer > =A0 =A0 =A0 -- calling us cannot propagate or handle them. > =A0 =A0 =A0 null; -- or report it. > end geolocation_labeler; > > HTH > > -- > Ludovic Brenta. Thanks, Ludovic. Unfortunately, the C overlords are giving me a string of length 0--the first character is the null character. So Update quits with raised INTERFACES.C.STRINGS.UPDATE_ERROR as is expected since Update can't write before the null character. I'm now (desperately) studying the GNAT code in i-cstrin.adb and attempting to make something like its Poke command, and then using it in a modified Update which I'm calling Unsafe_Update which is just like Update but with these lines deleted: if Check and then Offset + Chars'Length > Strlen (Item) then raise Update_Error; end if; I'm getting several errors which I'm trying to work through. Jerry