From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7217 invoked by alias); 2 Apr 2009 22:29:27 -0000 Received: (qmail 6763 invoked by uid 22791); 2 Apr 2009 22:29:26 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_50,J_CHICKENPOX_38,SPF_PASS X-Spam-Check-By: sourceware.org Received: from e24smtp03.br.ibm.com (HELO e24smtp03.br.ibm.com) (32.104.18.24) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Apr 2009 22:29:21 +0000 Received: from mailhub1.br.ibm.com (mailhub1.br.ibm.com [9.18.232.109]) by e24smtp03.br.ibm.com (8.13.1/8.13.1) with ESMTP id n32MOvJw028091 for ; Thu, 2 Apr 2009 19:24:57 -0300 Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.18.232.46]) by mailhub1.br.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n32MTZ9u1339726 for ; Thu, 2 Apr 2009 19:29:35 -0300 Received: from d24av01.br.ibm.com (loopback [127.0.0.1]) by d24av01.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n32MTG1q032655 for ; Thu, 2 Apr 2009 19:29:17 -0300 Received: from [9.8.4.240] ([9.8.4.240]) by d24av01.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n32MTGhk032646; Thu, 2 Apr 2009 19:29:16 -0300 Subject: Re: Python pretty-printing [2/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: Thu, 02 Apr 2009 22:29:00 -0000 Message-Id: <1238711355.3236.51.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/msg00052.txt.bz2 El jue, 02-04-2009 a las 14:55 -0600, Tom Tromey escribió: > This patch adds a minimal Python wrapper for struct objfile, > and arranges to auto-load Python code when an objfile is created. Hooray. Just a few comments... > +@findex gdb.current_objfile > +@defun current_objfile > +When auto-loading a Python script (@pxref{Auto-loading}), @value{GDBN} > +sets the ``current objfile'' to the corresponding objfile. This > +function returns the current objfile. If there is no current objfile, > +this function returns @code{None}. > +@end defun > + > +@findex gdb.objfiles > +@defun objfiles > +Return a sequence of all the objfiles current known to @value{GDBN}. > +@xref{Objfiles In Python}. > +@end defun IMHO these should go in the "Objfiles In Python" section, like e.g. gdb.selected_frame goes in the "Frames In Python" section. > +static int > +objfpy_set_printers (PyObject *o, PyObject *value, void *ignore) > + Py_XDECREF (self->printers); > + Py_INCREF (value); > + self->printers = value; I'm trying to decide if the sequence above is ok or not. Python docs say[1] in a warning box: "... any object that is reachable from a global variable should be in a consistent state before Py_DECREF is invoked. For example, code to delete an object from a list should copy a reference to the deleted object in a temporary variable, update the list data structure, and then call Py_DECREF for the temporary variable." So perhaps you should: tmp = self->printers; Py_INCREF (value); self->printers = value; Py_XDECREF (tmp); You certainly have more experience in this area than me though. WDYT? > +/* Return the Python object of type Objfile representing OBJFILE. If > + the object has already been created, return it. Otherwise, create > + it. Return NULL and set the Python error on failure. */ > +PyObject * > +objfile_to_objfile_object (struct objfile *objfile) Perhaps it would be useful to mention that this function returns a borrowed reference to the object? Also, just to check: the lack of testcases is because you believe this code is tested enough with python-prettyprint.exp in a later patch? [1] - http://docs.python.org/c-api/refcounting.html#Py_DECREF -- []'s Thiago Jung Bauermann IBM Linux Technology Center