public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <bauerman@br.ibm.com>
To: Phil Muldoon <pmuldoon@redhat.com>
Cc: Tom Tromey <tromey@redhat.com>, Project Archer <archer@sourceware.org>
Subject: Re: [python][patch] Add options length parameter to value.string(...)
Date: Thu, 09 Apr 2009 18:46:00 -0000	[thread overview]
Message-ID: <1239302781.30578.59.camel@localhost.localdomain> (raw)
In-Reply-To: <49DE2221.50203@redhat.com>

El jue, 09-04-2009 a las 17:28 +0100, Phil Muldoon escribió:
> Thiago Jung Bauermann wrote:
> > If you call read_string with length = -1, it will stop at the first null
> > character, or when fetchlimit is reached. So the current code doesn't
> > fetch all of an array, it stops at the first null character. I believe
> > this is what we're trying to avoid?
> 
> Aha I see what you mean now. I wrote the patch to follow this logic:
> 
> 1) If a length of -1 is specified, read until first null character. This 
> is what read_string does, and seems sane in the C string sense. The 
> default parameter passed to LA_GET_STRING in value.string() is -1, and 
> so the current behaviour just fetches a string up to the first null  for 
> c strings.

Nice.

> 2) If a length is specified, ignore any embedded nulls - just fetch 
> until length is satisfied, or fetchlimit is reached.
> 
> So:
> 
> char foo[50]  ="george";
> char bar[50] = "george\0mildred";
> char *foobar = "bungle";
> 
> With the patch (I just sent Tom's requested changes back to him) the 
> behaviour is:
> 
> so just string() in the foo variable would return "george", length 6.
> string() in the bar variable would return "george", length 6
> string(length = 15) in the bar variable would override the null 
> termination and return "george\0mildred"
> string() in the foobar variable would return "bungle", but string(length 
> = 500), would return "bungle" + trash.

foobar is an interesting example. It is both a well-behaved
null-terminated string, and (AFAIK) an array with known size (7 bytes).

But your code will work correctly for it, no matter what default we
choose for the array-wit-known-size case, so it's not really important.

> With Tom's patch to the python string pretty printer (in C++) we can 
> determine length.
> 
> > So, in the case of an array with known size, if we want to fetch the
> > whole of it without paying attention to null characters inside it, we
> > should set length to its size.  
> 
> I'm not adverse to this if this is what is the most sensible thing to 
> do. I guess what is the sanest default?

I don't think it's clear what the default should be. In your examples
above, do we want string() to return "george", or "george\0mildred" + 35
bytes of garbage? Tough.
-- 
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center

  reply	other threads:[~2009-04-09 18:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-06 16:54 Phil Muldoon
2009-04-06 22:14 ` Tom Tromey
2009-04-06 22:33   ` Thiago Jung Bauermann
2009-04-09  9:58     ` Phil Muldoon
2009-04-09 16:08       ` Thiago Jung Bauermann
2009-04-09 16:28         ` Phil Muldoon
2009-04-09 18:46           ` Thiago Jung Bauermann [this message]
2009-04-09 20:28             ` Phil Muldoon
2009-04-09 20:39               ` Thiago Jung Bauermann
2009-04-09 16:12   ` Phil Muldoon
2009-04-09 20:39     ` Thiago Jung Bauermann
2009-04-09 21:29       ` Phil Muldoon
2009-04-13 22:08         ` Tom Tromey
2009-04-15  9:13           ` Phil Muldoon
2009-04-15  9:37             ` Phil Muldoon
2009-04-15 12:37               ` Tom Tromey
2009-04-15 14:52           ` Phil Muldoon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1239302781.30578.59.camel@localhost.localdomain \
    --to=bauerman@br.ibm.com \
    --cc=archer@sourceware.org \
    --cc=pmuldoon@redhat.com \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).