Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: <Paul_Koning@Dell.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Python 3 support, part 1 (non-testsuite part)
Date: Mon, 12 Nov 2012 20:43:00 -0000	[thread overview]
Message-ID: <87mwyma6xi.fsf@fleche.redhat.com> (raw)
In-Reply-To: <C75A84166056C94F84D238A44AF9F6AD29C353@AUSX10MPC103.AMER.DELL.COM>	(Paul Koning's message of "Mon, 12 Nov 2012 16:06:11 +0000")

>>>>> "Paul" ==   <Paul_Koning@Dell.com> writes:

Paul> The attached set of patches updates the Python scripting support
Paul> in GDB to add Python 3 to the existing Python 2 support.

Thanks.

First, I think this is definitely something we want to support.  And, I
think you did it the right way, by making it possible to support both
versions with the same source tree.

Paul> 1. Type objects have a PyVarObject header, and because of the
Paul> syntax changes in the underlying macros in Python 3, you need a
Paul> PyVarObject_HEAD_INIT macro to initialize those.  For the same
Paul> reason, calls to the tp_free method need to go through a PyObject
Paul> * pointer, not a type object pointer.

I think the ob_type stuff should be accessed using the Py_TYPE macro.
IIUC this is new in 2.6 or 2.7, but we can easily define it
conditionally.

Paul> The ones that need to be different between the two versions are
Paul> conditional on IS_PY3K (as suggested in the Porting Python 2 to
Paul> Python 3 manual from python.org).

Sounds good to me.

Paul> Tested on Linux with Python version 2.4, 2.6, 2.7, 3.2, and 3.3.
Paul> No regressions on any of the tests.

Paul> Ok to commit?

I have some comments on the patch, but nothing too serious.

Paul>  PyTypeObject block_object_type = {
Paul> -  PyObject_HEAD_INIT (NULL)
Paul> -  0,				  /*ob_size*/
Paul> +  PyVarObject_HEAD_INIT (NULL, 0)

All the changes to use this macro are ok.  You can put them in
separately if you are so motivated (but see the note for
python-internal.h).

Paul> @@ -44,7 +59,11 @@
Paul>  void
Paul>  gdbpy_initialize_py_events (void)
Paul>  {
Paul> +#ifdef IS_PY3K
Paul> +  gdb_py_events.module = PyModule_Create (&EventModuleDef);
Paul> +#else
Paul>    gdb_py_events.module = Py_InitModule ("events", NULL);
Paul> +#endif

I was going to suggest a convenience function here, but I see we only
have two uses, so it doesn't matter all that much to me; but...

Paul> +#ifndef IS_PY3K
Paul>    Py_INCREF (gdb_py_events.module);
Paul> +#endif

Why is this needed?

Paul> +#ifdef IS_PY3K
Paul> +  Py_buffer pybuf;
 
Paul> +  if (! PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords,
Paul> +				     &addr_obj, &pybuf,
Paul> +				     &length_obj))
Paul> +    return NULL;

At least in 2.7, if you use 's*' it appears you must call
PyBuffer_Release at the appropriate moment.

Paul> +++ gdb/python/py-objfile.c	12 Nov 2012 15:51:30 -0000
Paul> @@ -58,7 +58,7 @@
Paul>    objfile_object *self = (objfile_object *) o;
 
Paul>    Py_XDECREF (self->printers);
Paul> -  self->ob_type->tp_free ((PyObject *) self);
Paul> +  o->ob_type->tp_free ((PyObject *) self);
Paul>  }

One of the spots where we could write

    Py_TYPE (o)->tp_free ((PyObject *) self);

... with Py_TYPE conditionally defined in python-internal.h.

Paul> +/* Python 2.4 does not define PyVarObject_HEAD_INIT.  */
Paul> +#define PyVarObject_HEAD_INIT(type, size)       \
Paul> +    PyObject_HEAD_INIT(type) size,

According to the docs, this wasn't introduced until Python 2.5
So rather than putting it in the HAVE_LIBPYTHON2_4 section, how about
conditionally defining it like:

#ifndef PyVarObject_HEAD_INIT
#define ...
#endif

Paul> +  wchar_t *progname_copy;

Can we really assume a working wchar_t?

Paul> +  if (progsize == (size_t) -1)
Paul> +    {
Paul> +      fprintf(stderr, "Could not convert python path to string\n");
Paul> +      exit (1);
Paul> +    }

I think if Python initialization fails, we should disable Python and
keep going.  It should not be a fatal error.

Paul> +  progname_copy = PyMem_Malloc((progsize + 1) * sizeof (wchar_t));

Missing space before paren.

Paul> +  count = mbstowcs (progname_copy, progname, progsize + 1);

Another portability question here.

Paul> +  if (count == (size_t) -1) {

Wrong brace placement.

Paul> +  _PyImport_FixupBuiltin (gdb_module, "_gdb");

What does this do?

Paul> +#endif
Paul>  #endif /* HAVE_PYTHON */

A blank line between these two would be nice.

Tom


  reply	other threads:[~2012-11-12 20:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-12 16:06 Paul_Koning
2012-11-12 20:43 ` Tom Tromey [this message]
2012-11-12 21:37   ` Paul_Koning
2012-11-13 18:53     ` Tom Tromey
2012-11-13 19:02       ` Paul_Koning
2012-11-13 19:12         ` Tom Tromey
2012-11-13 19:26           ` Paul_Koning
2012-11-13 19:43             ` Tom Tromey
2012-11-13 19:56               ` Paul_Koning
2012-11-13 20:24                 ` Tom Tromey
2012-11-14 16:03                   ` Paul_Koning
2012-11-19 16:49                     ` Tom Tromey
2012-12-11 20:22                       ` Paul_Koning
2012-12-11 20:37                         ` Eli Zaretskii
2012-12-11 21:24                         ` Tom Tromey
2012-12-12 17:00                           ` Paul_Koning

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=87mwyma6xi.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=Paul_Koning@Dell.com \
    --cc=gdb-patches@sourceware.org \
    /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