* Convert chars_ptr to Ada String @ 2017-07-07 21:03 Victor Porton 2017-07-07 22:23 ` Anh Vo 0 siblings, 1 reply; 11+ messages in thread From: Victor Porton @ 2017-07-07 21:03 UTC (permalink / raw) 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. -- Victor Porton - http://portonvictor.org ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Convert chars_ptr to Ada String 2017-07-07 21:03 Convert chars_ptr to Ada String Victor Porton @ 2017-07-07 22:23 ` Anh Vo 2017-07-07 22:48 ` Victor Porton 0 siblings, 1 reply; 11+ messages in thread From: Anh Vo @ 2017-07-07 22:23 UTC (permalink / raw) 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. Anh Vo ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Convert chars_ptr to Ada String 2017-07-07 22:23 ` Anh Vo @ 2017-07-07 22:48 ` Victor Porton 2017-07-07 23:14 ` Anh Vo 0 siblings, 1 reply; 11+ messages in thread From: Victor Porton @ 2017-07-07 22:48 UTC (permalink / raw) 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. -- Victor Porton - http://portonvictor.org ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Convert chars_ptr to Ada String 2017-07-07 22:48 ` Victor Porton @ 2017-07-07 23:14 ` Anh Vo 2017-07-09 6:49 ` Victor Porton 0 siblings, 1 reply; 11+ messages in thread From: Anh Vo @ 2017-07-07 23:14 UTC (permalink / raw) 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; ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Convert chars_ptr to Ada String 2017-07-07 23:14 ` Anh Vo @ 2017-07-09 6:49 ` Victor Porton 2017-07-10 4:58 ` Anh Vo 0 siblings, 1 reply; 11+ messages in thread From: Victor Porton @ 2017-07-09 6:49 UTC (permalink / raw) Anh Vo wrote: > 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); I see no such two-argument To_Ada in Interfaces.C. Or where to import such To_Ada from? > end; > > end RDF.Auxiliary.Convert; -- Victor Porton - http://portonvictor.org ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Convert chars_ptr to Ada String 2017-07-09 6:49 ` Victor Porton @ 2017-07-10 4:58 ` Anh Vo 2017-07-10 9:31 ` Victor Porton 0 siblings, 1 reply; 11+ messages in thread From: Anh Vo @ 2017-07-10 4:58 UTC (permalink / raw) On Saturday, July 8, 2017 at 11:49:34 PM UTC-7, Victor Porton wrote: > Anh Vo wrote: > > > 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); > > I see no such two-argument To_Ada in Interfaces.C. > > Or where to import such To_Ada from? Oops! I meant function value which is defined in Interfaces.C.Strings. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Convert chars_ptr to Ada String 2017-07-10 4:58 ` Anh Vo @ 2017-07-10 9:31 ` Victor Porton 2017-07-10 9:48 ` Dmitry A. Kazakov 0 siblings, 1 reply; 11+ messages in thread From: Victor Porton @ 2017-07-10 9:31 UTC (permalink / raw) Anh Vo wrote: > On Saturday, July 8, 2017 at 11:49:34 PM UTC-7, Victor Porton wrote: >> Anh Vo wrote: >> >> > 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); >> >> I see no such two-argument To_Ada in Interfaces.C. >> >> Or where to import such To_Ada from? > > Oops! I meant function value which is defined in Interfaces.C.Strings. Read description of Value() carefully. It stops at first NUL. -- Victor Porton - http://portonvictor.org ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Convert chars_ptr to Ada String 2017-07-10 9:31 ` Victor Porton @ 2017-07-10 9:48 ` Dmitry A. Kazakov 2017-07-10 12:41 ` Mark Lorenzen 0 siblings, 1 reply; 11+ messages in thread From: Dmitry A. Kazakov @ 2017-07-10 9:48 UTC (permalink / raw) On 10/07/2017 11:31, Victor Porton wrote: > Read description of Value() carefully. It stops at first NUL. if Ptr = Null_Ptr then return ""; else return To_Ada (Value (Ptr, Length), False); end if; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Convert chars_ptr to Ada String 2017-07-10 9:48 ` Dmitry A. Kazakov @ 2017-07-10 12:41 ` Mark Lorenzen 2017-07-10 14:24 ` Dmitry A. Kazakov 0 siblings, 1 reply; 11+ messages in thread From: Mark Lorenzen @ 2017-07-10 12:41 UTC (permalink / raw) On Monday, July 10, 2017 at 11:48:29 AM UTC+2, Dmitry A. Kazakov wrote: > On 10/07/2017 11:31, Victor Porton wrote: > > > Read description of Value() carefully. It stops at first NUL. > > if Ptr = Null_Ptr then > return ""; > else > return To_Ada (Value (Ptr, Length), False); > end if; > > -- > Regards, > Dmitry A. Kazakov > http://www.dmitry-kazakov.de I don't think that it will work as (if I understand it correctly) the string the OP tries to convert may contain NULL characters that are not to be interpreted as string terminators. I think the problem is, that the OP is confused about the difference between C strings and C arrays of characters and tries to use Interfaces.C.Strings to manipulate C arrays of characters thar are not be interpreted as C strings but as simple arrays of characters. Maybe Interfaces.C.Pointers is more appropriate? Regards, Mark L ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Convert chars_ptr to Ada String 2017-07-10 12:41 ` Mark Lorenzen @ 2017-07-10 14:24 ` Dmitry A. Kazakov 2017-07-10 21:21 ` Victor Porton 0 siblings, 1 reply; 11+ messages in thread From: Dmitry A. Kazakov @ 2017-07-10 14:24 UTC (permalink / raw) On 10/07/2017 14:41, Mark Lorenzen wrote: > On Monday, July 10, 2017 at 11:48:29 AM UTC+2, Dmitry A. Kazakov wrote: >> On 10/07/2017 11:31, Victor Porton wrote: >> >>> Read description of Value() carefully. It stops at first NUL. >> >> if Ptr = Null_Ptr then >> return ""; >> else >> return To_Ada (Value (Ptr, Length), False); >> end if; > > I don't think that it will work as (if I understand it correctly) the > string the OP tries to convert may contain NULL characters that are > not to be interpreted as string terminators. I see, it seems that Value is broken in ARM B.3.1(35). The semantics specified is: "If Item = Null_Ptr, then Value propagates Dereference_Error. Otherwise, Value returns the shorter of two arrays, either the first Length chars pointed to by Item, or Value(Item). The lower bound of the result is 0. If Length is 0, then Value propagates Constraint_Error." which is if not useless then incomplete. There must be Trim_Nul or Ignore_Nul parameter as in To_Ada and Length=0 must be OK. > I think the problem is, that the OP is confused about the difference > between C strings and C arrays of characters and tries to use > Interfaces.C.Strings to manipulate C arrays of characters thar are not > be interpreted as C strings but as simple arrays of characters. There is no such difference. Some C functions use NUL some ignore it. The OP's request is absolutely reasonable. > Maybe Interfaces.C.Pointers is more appropriate? Yes. There seems no way other than to use Interfaces.C.Pointers and convert each character individually. I would suggest the OP to post a change request to ARG. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Convert chars_ptr to Ada String 2017-07-10 14:24 ` Dmitry A. Kazakov @ 2017-07-10 21:21 ` Victor Porton 0 siblings, 0 replies; 11+ messages in thread From: Victor Porton @ 2017-07-10 21:21 UTC (permalink / raw) Dmitry A. Kazakov wrote: > I would suggest the OP to post a change request to ARG. Done. -- Victor Porton - http://portonvictor.org ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2017-07-10 21:21 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-07-07 21:03 Convert chars_ptr to Ada String Victor Porton 2017-07-07 22:23 ` Anh Vo 2017-07-07 22:48 ` Victor Porton 2017-07-07 23:14 ` Anh Vo 2017-07-09 6:49 ` Victor Porton 2017-07-10 4:58 ` Anh Vo 2017-07-10 9:31 ` Victor Porton 2017-07-10 9:48 ` Dmitry A. Kazakov 2017-07-10 12:41 ` Mark Lorenzen 2017-07-10 14:24 ` Dmitry A. Kazakov 2017-07-10 21:21 ` Victor Porton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox