Re: [RFA] Add la_getstr member to language_defn

Daniel Jacobowitz
2008-11-24T20:22:37Z

On Mon, Nov 24, 2008 at 04:34:19PM -0200, Thiago Jung Bauermann wrote:
> Would the comment above be clearer if it read as follows?
>
> If LEN > 0, reads exactly LEN characters (including eventual NULs in
> the middle or end of the string). If LEN is -1, stops at the first
> null character (not necessarily the first null byte) up to a maximum
> of FETCHLIMIT characters. Set FETCHLIMIT to UINT_MAX to read as many
> characters as possible from the string.

Yes, I do think that's clearer. I didn't realize on a quick read that
LEN and FETCHLIMIT were different... sorry for the confusion.

> By the way, I just realised that if LEN is 0, BUFFER is not allocated,
> contradicting the property I mention in the comment that "unless an
> exception is thrown, BUFFER will always be allocated, even on failure".
> I'll change it to allocate a 1 byte buffer in this case, to keep the
> caller's life simple.

Speaking of BUFFER, this is GDB - it's written in a language with
null-terminated strings. Would a definition of read_string that
always null-terminated the buffer be more useful, or just confusing?
Now the result is null-terminated iff the target string is. Of
course the string might include zero bytes if it's an array, but
the caller knows this. It would make it easier to use the returned
buffer when reading a variable-length string, I think.

--
Daniel Jacobowitz
CodeSourcery