This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: Python pretty-printing [3/6]
- From: Thiago Jung Bauermann <bauerman at br dot ibm dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Fri, 03 Apr 2009 17:34:21 -0300
- Subject: Re: Python pretty-printing [3/6]
- References: <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;
> }
>
> +
> +
:-)
> 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