public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Phil Muldoon <pmuldoon@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: Project Archer <archer@sourceware.org>
Subject: Re: [python][patch] Preserve string length, and embedded-nulls in pretty-print string emission.
Date: Wed, 27 May 2009 18:24:00 -0000	[thread overview]
Message-ID: <4A1D8544.2030006@redhat.com> (raw)
In-Reply-To: <m3octev48j.fsf@fleche.redhat.com>

Tom Tromey wrote:
> Phil> +convert_value_from_python (PyObject *obj, int *size)
>
> I don't understand why this needs the additional argument.
> It seems to me that the size is implicit in the returned value.
>   


This function returns a struct value. If that value contains a string 
with embedded nulls, is there a way to determine the size of the 
"gdb_byte *contents"? I might have missed a method - or the obvious - 
but this is the reason for the out parameter. If the parameter size is 
not NULL, the size of the string is returned there.


> Phil> +	  if (PyErr_Occurred ())
> Phil> +	      *out_value = NULL;
>
> This looks like it is indented improperly.
>   


Ok, thanks.


> Phil> +  str_length = pretty_print_one_value (printer, &replacement);
> Phil> +  if (replacement)
> Phil> +    if (str_length > 0)
> Phil> +      {
> Phil> +	LA_GET_STRING (replacement, &output, &str_length, &la_encoding);
> Phil> +	if (hint && !strcmp (hint, "string"))
> Phil> +	  LA_PRINT_STRING (stream, output, str_length, 1, 0, options);
> Phil> +	else
> Phil> +	  fputs_filtered (output, stream);
> Phil> +	xfree (output);
>
> Why do we need LA_GET_STRING here?  Aren't the string contents already
> in the value?
>   

I'll look at this a little more closely. But I use this to extract a 
string with embedded nulls with a concrete length. Do I misread your 
thoughts here? Or are you suggesting we just pass in value->contents to 
LA_PRINT_STRING?

> Also, why check "str_length > 0".  A string might have length 0.
> I think instead you probably want some kind of type check.
>   

Ok, thanks.

> Phil>    *replacement = NULL;
> Phil> -  result = pretty_print_one_value (printer_obj, replacement);
> Phil> -  if (result == NULL);
> Phil> +  size = pretty_print_one_value (printer_obj, replacement);
> Phil> +
> Phil> +  if (replacement == NULL);
> Phil>      gdbpy_print_stack ();
>
> This should check *replacement; 'replacement' can never be NULL.
>   


Ok, thanks.

> Phil> +std::string cplus_str ("embedded\0null\0string",20);
>
> A test relying on std::string is not very robust -- std::string may
> change over time, breaking the test.  Instead, it is better to write
> custom test code and a printer to match.  That way, we control the
> implementation.
>   


Ok thanks for the pointer. Can you please elaborate a bit more?

Regards

Phil

  reply	other threads:[~2009-05-27 18:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-22 20:23 Phil Muldoon
2009-05-27 17:35 ` Tom Tromey
2009-05-27 18:24   ` Phil Muldoon [this message]
2009-05-27 20:22     ` Tom Tromey
2009-06-01 16:26       ` Phil Muldoon
2009-06-02  5:11         ` Thiago Jung Bauermann
2009-06-02 23:46           ` Tom Tromey
2009-06-08 10:31             ` Phil Muldoon
2009-06-11 17:12               ` Tom Tromey
2009-06-15 20:50                 ` Phil Muldoon
2009-06-16 12:44                   ` Phil Muldoon
2009-06-16 18:07                     ` Tom Tromey
2009-06-18 12:20                       ` Phil Muldoon
2009-06-18 20:17                         ` Tom Tromey
2009-06-18 20:21                         ` Tom Tromey
2009-06-23 14:37                           ` Phil Muldoon
2009-06-23 16:37                             ` Tom Tromey
2009-06-23 16:56                               ` Phil Muldoon
2009-06-02 15:38         ` Jonas Maebe
2009-06-02 20:48           ` 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=4A1D8544.2030006@redhat.com \
    --to=pmuldoon@redhat.com \
    --cc=archer@sourceware.org \
    --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).