From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7836 invoked by alias); 3 Apr 2009 20:34:34 -0000 Received: (qmail 7505 invoked by uid 22791); 3 Apr 2009 20:34:33 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL,BAYES_20,J_CHICKENPOX_47,J_CHICKENPOX_54,SPF_PASS X-Spam-Check-By: sourceware.org Received: from e24smtp02.br.ibm.com (HELO e24smtp02.br.ibm.com) (32.104.18.86) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Apr 2009 20:34:28 +0000 Received: from mailhub1.br.ibm.com (mailhub1.br.ibm.com [9.18.232.109]) by e24smtp02.br.ibm.com (8.13.1/8.13.1) with ESMTP id n33KouQl019044 for ; Fri, 3 Apr 2009 17:50:56 -0300 Received: from d24av02.br.ibm.com (d24av02.br.ibm.com [9.18.232.47]) by mailhub1.br.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n33KYgPR1413596 for ; Fri, 3 Apr 2009 17:34:42 -0300 Received: from d24av02.br.ibm.com (loopback [127.0.0.1]) by d24av02.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n33KYN3Z010313 for ; Fri, 3 Apr 2009 17:34:23 -0300 Received: from [9.8.4.240] ([9.8.4.240]) by d24av02.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n33KYNc2010308; Fri, 3 Apr 2009 17:34:23 -0300 Subject: Re: Python pretty-printing [3/6] From: Thiago Jung Bauermann To: Tom Tromey Cc: gdb-patches@sourceware.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Date: Fri, 03 Apr 2009 20:34:00 -0000 Message-Id: <1238790861.3236.72.camel@localhost.localdomain> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-04/txt/msg00086.txt.bz2 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