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 [2/6]
Date: Thu, 02 Apr 2009 22:29:00 -0000	[thread overview]
Message-ID: <1238711355.3236.51.camel@localhost.localdomain> (raw)
In-Reply-To: <m3d4bubwsy.fsf@fleche.redhat.com>

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)
<snip>
> +  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


  reply	other threads:[~2009-04-02 22:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-02 20:55 Tom Tromey
2009-04-02 22:29 ` Thiago Jung Bauermann [this message]
2009-04-03  0:23   ` Tom Tromey
2009-04-03  0:47     ` Tom Tromey
2009-04-03 15:06       ` Eli Zaretskii
2009-04-06 19:25         ` Tom Tromey
2009-04-06 20:41           ` Eli Zaretskii
2009-04-03 20:36     ` Thiago Jung Bauermann

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=1238711355.3236.51.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