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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.129.50.67 with SMTP id y64mr5333167ywy.102.1499469253389; Fri, 07 Jul 2017 16:14:13 -0700 (PDT) X-Received: by 10.36.3.72 with SMTP id e69mr50156ite.1.1499469253340; Fri, 07 Jul 2017 16:14:13 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!m54no869925qtb.1!news-out.google.com!f200ni1634itc.0!nntp.google.com!188no1041788itx.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 7 Jul 2017 16:14:13 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=149.32.224.36; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 NNTP-Posting-Host: 149.32.224.36 References: <567a23f5-a7dc-4b3d-8c16-942a8551c02f@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Convert chars_ptr to Ada String From: Anh Vo Injection-Date: Fri, 07 Jul 2017 23:14:13 +0000 Content-Type: text/plain; charset="UTF-8" Xref: news.eternal-september.org comp.lang.ada:47327 Date: 2017-07-07T16:14:13-07:00 List-Id: On Friday, July 7, 2017 at 3:49:20 PM UTC-7, Victor Porton wrote: > Anh Vo wrote: > > > On Friday, July 7, 2017 at 2:03:32 PM UTC-7, Victor Porton wrote: > >> Remind me how to convert a pair of Ptr: chars_ptr and Size: size_t to an > >> Ada string. > >> > >> Ptr may contain NULs and this should not influence the length of the > >> resulting string. > > > > Look at APIs defined in package Interfaces.C.Strings. > > I've done it: > > https://github.com/vporton/redland-bindings/blob/ada2012/ada/src/rdf-auxiliary-convert.adb > > It requires not only Interfaces.C.Strings but also Interfaces.C.Pointers > to make things more confusing. Why make it more confusing while it is actually simpler as shown below. with Interfaces.C.Strings; use Interfaces.C.Strings; package body RDF.Auxiliary.Convert is function Value_With_Possible_NULs (Item: RDF.Auxiliary.C_Pointers.Pointer; Length: size_t) return String is begin return To_Ada(Item, Length); end; end RDF.Auxiliary.Convert;