Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <bauerman@br.ibm.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: Python pretty-printing [3/6]
Date: Fri, 03 Apr 2009 20:34:00 -0000	[thread overview]
Message-ID: <1238790861.3236.72.camel@localhost.localdomain> (raw)
In-Reply-To: <m3bprebws2.fsf@fleche.redhat.com>

El jue, 02-04-2009 a las 14:55 -0600, Tom Tromey escribió:
> +static void
> +field_dealloc (PyObject *obj)
> +{
> +  field_object *f = (field_object *) obj;
> +  Py_XDECREF (f->dict);
> +}

You need to call f->ob_type->tp_free here.

> +static struct type *
> +typy_lookup_typename (char *type_name)
> +{
> +  struct type *type = NULL;
> +  volatile struct gdb_exception except;
> +  TRY_CATCH (except, RETURN_MASK_ALL)
> +    {
> +      if (!strncmp (type_name, "struct ", 7))
> +	type = lookup_struct (type_name + 7, NULL);
> +      else if (!strncmp (type_name, "union ", 6))
> +	type = lookup_union (type_name + 6, NULL);
> +      else if (!strncmp (type_name, "enum ", 5))
> +	type = lookup_enum (type_name + 5, NULL);
> +      else
> +	type = lookup_typename (type_name, NULL, 0);
> +    }
> +  if (except.reason < 0)
> +    {
> +      PyErr_Format (except.reason == RETURN_QUIT
> +		    ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
> +		    "%s", except.message);
> +      return NULL;
> +    }

Perhaps this is nitpicking, but: any reason why you don't use
GDB_PY_HANDLE_EXCEPTION here? This code seems to do the same thing.

> +static PyMethodDef type_object_methods[] =
> +{
> +  { "code", typy_code, METH_NOARGS, "Return the code for this type" },
> +  { "const", typy_const, METH_NOARGS, "Return a const variant of this type" },
> +  { "fields", typy_fields, METH_NOARGS,
> +    "Return a sequence holding all the fields of this type.\n\
> +Each field is a dictionary." },
> +  { "pointer", typy_pointer, METH_NOARGS, "Return pointer to this type" },
> +  { "reference", typy_reference, METH_NOARGS, "Return reference to this type" },
> +  { "sizeof", typy_sizeof, METH_NOARGS,
> +    "Return the size of this type, in bytes" },
> +  { "tag", typy_tag, METH_NOARGS,
> +    "Return the tag name for this type, or None." },
> +  { "strip_typedefs", typy_strip_typedefs, METH_NOARGS,
> +    "Return a type stripped of typedefs"},
> +  { "target", typy_target, METH_NOARGS,
> +    "Return the target type of this type" },
> +  { "template_argument", typy_template_argument, METH_VARARGS,
> +    "Return a single template argument type" },
> +  { "unqualified", typy_unqualified, METH_NOARGS,
> +    "Return a variant of this type without const or volatile attributes" },
> +  { "volatile", typy_volatile, METH_NOARGS,
> +    "Return a volatile variant of this type" },
> +  { NULL }
> +};

I think most of these methods could be attributes instead. The ones
which should stay as methods are those who have side-effects (like
causing a symtab to be loaded, or somesuch). Even the methods which
create new types only do so if the requested type doesn't exist yet,
IIUC. Are there side-effects in, say, Type.pointer or Type.reference?

Also, another no-no for an attribute would be if its getter would throw
an exception.

WDYT?

> @@ -855,6 +891,8 @@ gdbpy_initialize_values (void)
>    values_in_python = NULL;
>  }
>  
> +\f
> +

:-)

>  static PyMethodDef value_object_methods[] = {
> +  { "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." },
>    { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
> +  { "type", valpy_type, METH_NOARGS, "Return type of the value." },
>    { "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
>      "string ([encoding] [, errors]) -> string\n\
>  Return Unicode string representation of the value." },

What about making Value.type an attribute?
-- 
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center


  parent reply	other threads:[~2009-04-03 20:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-02 20:55 Tom Tromey
2009-04-03 15:16 ` Eli Zaretskii
2009-04-07 19:52   ` Tom Tromey
2009-04-07 21:45     ` Eli Zaretskii
2009-04-03 16:30 ` Daniel Jacobowitz
2009-04-06 23:26   ` Tom Tromey
2009-04-07  0:34     ` Thiago Jung Bauermann
2009-04-07  1:16     ` Daniel Jacobowitz
2009-04-07  2:03       ` Thiago Jung Bauermann
2009-04-07  2:27         ` Daniel Jacobowitz
2009-04-03 20:34 ` Thiago Jung Bauermann [this message]
2009-04-06 23:32   ` Tom Tromey
2009-04-08 18:26   ` Tom Tromey
2009-04-08 18:39 ` Tom Tromey
2009-04-08 19:23   ` Eli Zaretskii
2009-04-09  1:16     ` Tom Tromey

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=1238790861.3236.72.camel@localhost.localdomain \
    --to=bauerman@br.ibm.com \
    --cc=gdb-patches@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