comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Interfaces.C.String.Update
Date: Mon, 28 Nov 2011 09:37:08 -0800 (PST)
Date: 2011-11-28T09:37:08-08:00	[thread overview]
Message-ID: <e7123f6a-b535-4077-b7fe-51b59185304b@f29g2000yqa.googlegroups.com> (raw)
In-Reply-To: bd21de6e-0b53-4c39-9112-e4b1e003ea3e@s6g2000vbc.googlegroups.com

awdorrin wrote on comp.lang.ada:
> Thanks for the confirmation and the suggestions.
>
> One followup question about Update and the use of Check=>True...
>
> If I'm understanding things properly, given the following scenario:
>
> Character array defined in C, initialized with a memset of nulls.
>
> Passing a char* to Ada, using the Chars_Ptr - Any attempt to use
> Update with Check=>True will raise an Update_Error, because Ada will
> see the string pointed to as zero length, right?

Right.

> So this requires us to disable the check and do some checking on both
> sides to make sure that we don't blow the char buffers.

Right.

> I think, updating these functions to pass in the buffer length (or
> 'cheating' by initializing the char arrays with spaces instead of
> nulls) would be safer, and allow me to take advantage of the
> Check=>True functionality.

In this case I would think it is easier to forget about C's notion
of a string (null-terminated, no length) and use Ada's notion on
both sides (length known at run time).  If you control the C side
of your system, you can easily make it allocate exactly the length
needed and pass the length explicitly.  Then on the Ada side you do
not need Interfaces.C.Strings anymore, just copy one char_array to
another.

--
Ludovic Brenta.
Our gut-feeling is that the stakeholders transition a progressive
trend across the board.



      reply	other threads:[~2011-11-28 17:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-28 15:55 Interfaces.C.String.Update awdorrin
2011-11-28 16:09 ` Interfaces.C.String.Update Adam Beneschan
2011-11-28 16:22 ` Interfaces.C.String.Update Ludovic Brenta
2011-11-28 16:35   ` Interfaces.C.String.Update awdorrin
2011-11-28 17:37     ` Ludovic Brenta [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox