From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32415 invoked by alias); 12 Nov 2012 16:06:38 -0000 Received: (qmail 32399 invoked by uid 22791); 12 Nov 2012 16:06:36 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL,BAYES_50,KAM_STOCKTIP,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,TW_BJ,TW_IV,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: sourceware.org Received: from ausc60pc101.us.dell.com (HELO ausc60pc101.us.dell.com) (143.166.85.206) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 12 Nov 2012 16:06:20 +0000 X-Loopcount0: from 10.170.28.40 From: To: Subject: [PATCH] Python 3 support, part 1 (non-testsuite part) Date: Mon, 12 Nov 2012 16:06:00 -0000 Message-ID: Content-Type: text/plain; charset="us-ascii" Content-ID: <874EDD56F9C2ED458D4BBAB4AEC0719F@dell.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: 2012-11/txt/msg00285.txt.bz2 The attached set of patches updates the Python scripting support in GDB to = add Python 3 to the existing Python 2 support. The majority of the changes are actually in the test suite. I'll send the = changes in two parts (base code then testsuite) because the patch is pretty= long. In the C code for Python support, the main changes are: 1. Type objects have a PyVarObject header, and because of the syntax change= s in the underlying macros in Python 3, you need a PyVarObject_HEAD_INIT ma= cro to initialize those. For the same reason, calls to the tp_free method = need to go through a PyObject * pointer, not a type object pointer. 2. Python 3 has only long integers and unicode strings, called "int" and "s= tr" in Python code but still accessed by PyLong* and PyUnicode* API functio= ns. Most of these changes are acceptable for Python 2 as well. The ones that n= eed to be different between the two versions are conditional on IS_PY3K (as= suggested in the Porting Python 2 to Python 3 manual from python.org). Tested on Linux with Python version 2.4, 2.6, 2.7, 3.2, and 3.3. No regres= sions on any of the tests. Ok to commit? paul 2012-11-12 Paul Koning Add support for Python 3. * varobj.c (value_get_print_value): Use python_string_to_target_string. * python/py-block.c: Use PyVarObject_HEAD_INIT in initialization of type objects. * python/py-breakpoint.c: Ditto. * python/py-cmd.c: Ditto. * python/py-event.c: Ditto. * python/py-event.h: Ditto. * python/py-evtregistry.c: Ditto. * python/py-finishbreakpoint.c: Ditto. * python/py-frame.c: Ditto. * python/py-function.c: Ditto. * python/py-infthread.c: Ditto. * python/py-lazy-string.c: Ditto. * python/py-progspace.c: Ditto. * /python/py-symbol.c: Ditto. * python/py-evts.c: (gdbpy_initialize_py_events): Add module initialization for Python 3. * python/py-inferior.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (infpy_read_memory): Return memoryview object if Python 3. (infpy_write_memory): Use "s*" operand parsing code for Python 3. (infpy_search_memory): Ditto. (get_buffer): New function for Python 3. * python/py-objfile.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (objfpy_dealloc): Use PyObject pointer to call tp_free. * python/py-param.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (get_attr): Use PyUnicode_CompareWithASCIIString if Python 3. (set_attr): Ditto. * python/py-prettyprint.c (print_string_repr): use PyBytes methods instead of PyString methods if Python 3. (print_children): Skip push_dummy_python_frame call if Python 3. * python/py-symtab.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (salpy_dealloc): Use PyObject pointer to call tp_free. * python/py-type.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (field_dealloc): Use PyObject pointer to call tp_free. (typy_dealloc): Ditto. (type_object_as_number): Adjust struct initializations for differences in layout for Python 2 vs. Python 3. * python/py-utils.c (python_string_to_unicode): Omit non-Unicode string case for Python 3. (unicode_to_encoded_python_string): Shorten code (no functional change).=20 (python_string_to_target_python_string): Comment that in Python 3 returned value is a Python "bytes" type. (gdbpy_is_string): Omit non-Unicode string check in Python 3. (gdb_py_object_from_longest): Omit non-long integer case in Python 3. (gdb_py_object_from_ulongest): Ditto. * python/py-value.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (valpy_dealloc): Use PyObject pointer to call tp_free. (valpy_int): Omit function if Python 3. (convert_value_from_python): Use "%S" format (Python object as a string) if Python 3. (value_object_as_number): Adjust struct initializations for differences in layout for Python 2 vs. Python 3. * python/python-config.py: Adjust syntax for Python 3 compatibility.=20 Include "sys.abiflags" string as part of python library name, if that attribute exists (Python 3). * python/python-internal.h (IS_PY3): Define if Python 3. (Py_TPFLAGS_HAVE_ITER, Py_TPFLAGS_CHECKTYPES): Define with placeholder value if Python 3. (PyInt_Check, PyInt_FromLong, PyInt_AsLong, PyString_FromString, PyString_Decode, PyString_FromFormat, PyString_Check): Define as analogous Python 3 API function if Python 3. (PyVarObject_HEAD_INIT): Define if Python 2.4. * python/python.c (eval_python_command): Omit Py_FlushLine call if Python 3. (_initialize_python): Convert argc to wchar_t** if Python 3. Add module initialization for Python 3. (finish_python_initialization): Pass wchar_t * argument to PySys_SetPath if Python 3. * python/lib/gdb/__init__.py: Define "reload" if Python 3. (_GdbFile): New class for common output file behavior. (GdbOutFile): Subclass from _GdbFile. (GdbOutputErrorFile): Ditto. (auto_load_packages): Adjust syntax for Python 3 compatibility. * python/lib/gdb/printing.py: Define basestr and int if Python 3. * python/lib/gdb/prompt.py: Use sorted() function rather than sort() method. * python/lib/gdb/command/explore.py: Define raw_input if Python 3. Adjust syntax for Python 3 compatibility. * python/lib/gdb/command/pretty_printers.py: Use sorted() function rather than sort() method. Adjust syntax for Python 3 compatibility. * doc/gdb.texinfo (Inferior.read_memory): Mention that the return value is a memoryview object if Python 3. Index: gdb/varobj.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/varobj.c,v retrieving revision 1.200 diff -u -r1.200 varobj.c --- gdb/varobj.c 6 Aug 2012 18:44:44 -0000 1.200 +++ gdb/varobj.c 12 Nov 2012 15:51:27 -0000 @@ -2910,12 +2910,10 @@ string_print. Otherwise just return the extracted string as a value. */ =20 - PyObject *py_str - =3D python_string_to_target_python_string (output); + char *s =3D python_string_to_target_string (output); =20 - if (py_str) + if (s) { - char *s =3D PyString_AsString (py_str); char *hint; =20 hint =3D gdbpy_get_display_hint (value_formatter); @@ -2926,10 +2924,10 @@ xfree (hint); } =20 - len =3D PyString_Size (py_str); + len =3D strlen (s); thevalue =3D xmemdup (s, len + 1, len + 1); type =3D builtin_type (gdbarch)->builtin_char; - Py_DECREF (py_str); + xfree (s); =20 if (!string_print) { Index: gdb/doc/gdb.texinfo =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.1017 diff -u -r1.1017 gdb.texinfo --- gdb/doc/gdb.texinfo 5 Nov 2012 19:36:38 -0000 1.1017 +++ gdb/doc/gdb.texinfo 12 Nov 2012 15:51:30 -0000 @@ -23982,7 +23982,8 @@ Read @var{length} bytes of memory from the inferior, starting at @var{address}. Returns a buffer object, which behaves much like an array or a string. It can be modified and given to the -@code{Inferior.write_memory} function. +@code{Inferior.write_memory} function. In @code{Python} 3, the return +value is a @code{memoryview} object. @end defun =20 @findex Inferior.write_memory Index: gdb/python/py-block.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-block.c,v retrieving revision 1.12 diff -u -r1.12 py-block.c --- gdb/python/py-block.c 10 May 2012 19:50:09 -0000 1.12 +++ gdb/python/py-block.c 12 Nov 2012 15:51:30 -0000 @@ -475,8 +475,7 @@ }; =20 PyTypeObject block_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Block", /*tp_name*/ sizeof (block_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -516,8 +515,7 @@ }; =20 static PyTypeObject block_syms_iterator_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.BlockIterator", /*tp_name*/ sizeof (block_syms_iterator_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-breakpoint.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-breakpoint.c,v retrieving revision 1.34 diff -u -r1.34 py-breakpoint.c --- gdb/python/py-breakpoint.c 14 May 2012 15:38:40 -0000 1.34 +++ gdb/python/py-breakpoint.c 12 Nov 2012 15:51:30 -0000 @@ -981,8 +981,7 @@ =20 PyTypeObject breakpoint_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Breakpoint", /*tp_name*/ sizeof (breakpoint_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-cmd.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-cmd.c,v retrieving revision 1.21 diff -u -r1.21 py-cmd.c --- gdb/python/py-cmd.c 13 Jun 2012 15:47:16 -0000 1.21 +++ gdb/python/py-cmd.c 12 Nov 2012 15:51:30 -0000 @@ -607,8 +607,7 @@ =20 static PyTypeObject cmdpy_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Command", /*tp_name*/ sizeof (cmdpy_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-event.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-event.c,v retrieving revision 1.4 diff -u -r1.4 py-event.c --- gdb/python/py-event.c 15 Aug 2012 14:22:02 -0000 1.4 +++ gdb/python/py-event.c 12 Nov 2012 15:51:30 -0000 @@ -142,8 +142,7 @@ =20 PyTypeObject event_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Event", /* tp_name */ sizeof (event_object), /* tp_basicsize */ 0, /* tp_itemsize */ Index: gdb/python/py-event.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-event.h,v retrieving revision 1.5 diff -u -r1.5 py-event.h --- gdb/python/py-event.h 4 Jan 2012 08:17:25 -0000 1.5 +++ gdb/python/py-event.h 12 Nov 2012 15:51:30 -0000 @@ -49,8 +49,7 @@ \ qual PyTypeObject name##_event_object_type =3D \ { \ - PyObject_HEAD_INIT (NULL) \ - 0, /* ob_size */ \ + PyVarObject_HEAD_INIT (NULL, 0) \ py_path, /* tp_name */ \ sizeof (event_object), /* tp_basicsize */ \ 0, /* tp_itemsize */ \ Index: gdb/python/py-evtregistry.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-evtregistry.c,v retrieving revision 1.3 diff -u -r1.3 py-evtregistry.c --- gdb/python/py-evtregistry.c 4 Jan 2012 08:17:25 -0000 1.3 +++ gdb/python/py-evtregistry.c 12 Nov 2012 15:51:30 -0000 @@ -131,8 +131,7 @@ =20 static PyTypeObject eventregistry_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.EventRegistry", /* tp_name */ sizeof (eventregistry_object), /* tp_basicsize */ 0, /* tp_itemsize */ Index: gdb/python/py-evts.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-evts.c,v retrieving revision 1.4 diff -u -r1.4 py-evts.c --- gdb/python/py-evts.c 4 Jan 2012 08:17:25 -0000 1.4 +++ gdb/python/py-evts.c 12 Nov 2012 15:51:30 -0000 @@ -19,6 +19,21 @@ =20 #include "py-events.h" =20 +#ifdef IS_PY3K +static struct PyModuleDef EventModuleDef =3D +{ + PyModuleDef_HEAD_INIT, + "gdb.events", + NULL, + -1,=20 + NULL, + NULL, + NULL, + NULL, + NULL +}; +#endif + /* Initialize python events. */ =20 static int @@ -44,7 +59,11 @@ void gdbpy_initialize_py_events (void) { +#ifdef IS_PY3K + gdb_py_events.module =3D PyModule_Create (&EventModuleDef); +#else gdb_py_events.module =3D Py_InitModule ("events", NULL); +#endif =20 if (!gdb_py_events.module) goto fail; @@ -61,7 +80,9 @@ if (add_new_registry (&gdb_py_events.new_objfile, "new_objfile") < 0) goto fail; =20 +#ifndef IS_PY3K Py_INCREF (gdb_py_events.module); +#endif if (PyModule_AddObject (gdb_module, "events", (PyObject *) gdb_py_events.module) < 0) Index: gdb/python/py-finishbreakpoint.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-finishbreakpoint.c,v retrieving revision 1.7 diff -u -r1.7 py-finishbreakpoint.c --- gdb/python/py-finishbreakpoint.c 18 May 2012 21:02:52 -0000 1.7 +++ gdb/python/py-finishbreakpoint.c 12 Nov 2012 15:51:30 -0000 @@ -425,8 +425,7 @@ =20 static PyTypeObject finish_breakpoint_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.FinishBreakpoint", /*tp_name*/ sizeof (struct finish_breakpoint_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-frame.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-frame.c,v retrieving revision 1.26 diff -u -r1.26 py-frame.c --- gdb/python/py-frame.c 7 Feb 2012 19:47:15 -0000 1.26 +++ gdb/python/py-frame.c 12 Nov 2012 15:51:30 -0000 @@ -662,8 +662,7 @@ }; =20 PyTypeObject frame_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Frame", /* tp_name */ sizeof (frame_object), /* tp_basicsize */ 0, /* tp_itemsize */ Index: gdb/python/py-function.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-function.c,v retrieving revision 1.12 diff -u -r1.12 py-function.c --- gdb/python/py-function.c 4 Jan 2012 08:17:25 -0000 1.12 +++ gdb/python/py-function.c 12 Nov 2012 15:51:30 -0000 @@ -208,8 +208,7 @@ =20 static PyTypeObject fnpy_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Function", /*tp_name*/ sizeof (PyObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-inferior.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-inferior.c,v retrieving revision 1.25 diff -u -r1.25 py-inferior.c --- gdb/python/py-inferior.c 22 Aug 2012 15:17:21 -0000 1.25 +++ gdb/python/py-inferior.c 12 Nov 2012 15:51:30 -0000 @@ -454,9 +454,14 @@ membuf_obj->addr =3D addr; membuf_obj->length =3D length; =20 +#ifdef IS_PY3K + result =3D PyMemoryView_FromObject ((PyObject *) membuf_obj); +#else result =3D PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0, Py_END_OF_BUFFER); +#endif Py_DECREF (membuf_obj); + return result; } =20 @@ -476,12 +481,22 @@ PyObject *addr_obj, *length_obj =3D NULL; volatile struct gdb_exception except; static char *keywords[] =3D { "address", "buffer", "length", NULL }; +#ifdef IS_PY3K + Py_buffer pybuf; =20 + if (! PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords, + &addr_obj, &pybuf, + &length_obj)) + return NULL; =20 + buffer =3D pybuf.buf; + buf_len =3D pybuf.len; +#else if (! PyArg_ParseTupleAndKeywords (args, kw, "Os#|O", keywords, &addr_obj, &buffer, &buf_len, &length_obj)) return NULL; +#endif =20 TRY_CATCH (except, RETURN_MASK_ALL) { @@ -528,6 +543,23 @@ pulongest (membuf_obj->length)); } =20 +#ifdef IS_PY3K +static int +get_buffer (PyObject *self, Py_buffer *buf, int flags) +{ + membuf_object *membuf_obj =3D (membuf_object *) self; + int ret; +=20=20 + ret =3D PyBuffer_FillInfo (buf, self, membuf_obj->buffer, + membuf_obj->length, 0,=20 + PyBUF_CONTIG); + buf->format =3D "c"; + + return ret; +} + +#else + static Py_ssize_t get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr) { @@ -572,6 +604,8 @@ return ret; } =20 +#endif /* IS_PY3K */ + /* Implementation of gdb.search_memory (address, length, pattern). ADDRESS is the address to start the search. LENGTH specifies the scope of the @@ -585,17 +619,41 @@ { CORE_ADDR start_addr, length; static char *keywords[] =3D { "address", "length", "pattern", NULL }; - PyObject *pattern, *start_addr_obj, *length_obj; + PyObject *start_addr_obj, *length_obj; volatile struct gdb_exception except; Py_ssize_t pattern_size; const void *buffer; CORE_ADDR found_addr; int found =3D 0; +#ifdef IS_PY3K + Py_buffer pybuf; =20 - if (! PyArg_ParseTupleAndKeywords (args, kw, "OOO", keywords, + if (! PyArg_ParseTupleAndKeywords (args, kw, "OOs*", keywords, &start_addr_obj, &length_obj, + &pybuf)) + return NULL; + + buffer =3D pybuf.buf; + pattern_size =3D pybuf.len; +#else + PyObject *pattern; +=20=20 + if (! PyArg_ParseTupleAndKeywords (args, kw, "OOO", keywords, + &start_addr_obj, &length_obj, &pattern)) + return NULL; + + if (!PyObject_CheckReadBuffer (pattern)) + { + PyErr_SetString (PyExc_RuntimeError, + _("The pattern is not a Python buffer.")); + + return NULL; + } + + if (PyObject_AsReadBuffer (pattern, &buffer, &pattern_size) =3D=3D -1) return NULL; +#endif =20 if (get_addr_from_python (start_addr_obj, &start_addr) && get_addr_from_python (length_obj, &length)) @@ -619,17 +677,6 @@ else return NULL; =20 - if (!PyObject_CheckReadBuffer (pattern)) - { - PyErr_SetString (PyExc_RuntimeError, - _("The pattern is not a Python buffer.")); - - return NULL; - } - - if (PyObject_AsReadBuffer (pattern, &buffer, &pattern_size) =3D=3D -1) - return NULL; - TRY_CATCH (except, RETURN_MASK_ALL) { found =3D target_search_memory (start_addr, length, @@ -777,8 +824,7 @@ =20 static PyTypeObject inferior_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Inferior", /* tp_name */ sizeof (inferior_object), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -817,6 +863,13 @@ 0 /* tp_alloc */ }; =20 +#ifdef IS_PY3K +static PyBufferProcs buffer_procs =3D { + get_buffer +}; + +#else + /* Python doesn't provide a decent way to get compatibility here. */ #if HAVE_LIBPYTHON2_4 #define CHARBUFFERPROC_NAME getcharbufferproc @@ -832,10 +885,10 @@ Python 2.5. */ (CHARBUFFERPROC_NAME) get_char_buffer }; +#endif /* IS_PY3K */ =20 static PyTypeObject membuf_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Membuf", /*tp_name*/ sizeof (membuf_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-infthread.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-infthread.c,v retrieving revision 1.7 diff -u -r1.7 py-infthread.c --- gdb/python/py-infthread.c 18 May 2012 21:02:52 -0000 1.7 +++ gdb/python/py-infthread.c 12 Nov 2012 15:51:30 -0000 @@ -301,8 +301,7 @@ =20 static PyTypeObject thread_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.InferiorThread", /*tp_name*/ sizeof (thread_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-lazy-string.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-lazy-string.c,v retrieving revision 1.12 diff -u -r1.12 py-lazy-string.c --- gdb/python/py-lazy-string.c 1 Mar 2012 21:06:54 -0000 1.12 +++ gdb/python/py-lazy-string.c 12 Nov 2012 15:51:30 -0000 @@ -216,8 +216,7 @@ }; =20 static PyTypeObject lazy_string_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.LazyString", /*tp_name*/ sizeof (lazy_string_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-objfile.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-objfile.c,v retrieving revision 1.11 diff -u -r1.11 py-objfile.c --- gdb/python/py-objfile.c 4 Jan 2012 08:17:25 -0000 1.11 +++ gdb/python/py-objfile.c 12 Nov 2012 15:51:30 -0000 @@ -58,7 +58,7 @@ objfile_object *self =3D (objfile_object *) o; =20 Py_XDECREF (self->printers); - self->ob_type->tp_free ((PyObject *) self); + o->ob_type->tp_free ((PyObject *) self); } =20 static PyObject * @@ -215,8 +215,7 @@ =20 static PyTypeObject objfile_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Objfile", /*tp_name*/ sizeof (objfile_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-param.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-param.c,v retrieving revision 1.15 diff -u -r1.15 py-param.c --- gdb/python/py-param.c 4 Jan 2012 08:17:25 -0000 1.15 +++ gdb/python/py-param.c 12 Nov 2012 15:51:30 -0000 @@ -102,7 +102,11 @@ get_attr (PyObject *obj, PyObject *attr_name) { if (PyString_Check (attr_name) +#ifdef IS_PY3K + && ! PyUnicode_CompareWithASCIIString (attr_name, "value")) +#else && ! strcmp (PyString_AsString (attr_name), "value")) +#endif { parmpy_object *self =3D (parmpy_object *) obj; =20 @@ -276,7 +280,11 @@ set_attr (PyObject *obj, PyObject *attr_name, PyObject *val) { if (PyString_Check (attr_name) +#ifdef IS_PY3K + && ! PyUnicode_CompareWithASCIIString (attr_name, "value")) +#else && ! strcmp (PyString_AsString (attr_name), "value")) +#endif { if (!val) { @@ -773,8 +781,7 @@ =20 static PyTypeObject parmpy_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Parameter", /*tp_name*/ sizeof (parmpy_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-prettyprint.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-prettyprint.c,v retrieving revision 1.28 diff -u -r1.28 py-prettyprint.c --- gdb/python/py-prettyprint.c 13 Sep 2012 21:49:31 -0000 1.28 +++ gdb/python/py-prettyprint.c 12 Nov 2012 15:51:30 -0000 @@ -348,8 +348,13 @@ struct type *type; =20 make_cleanup_py_decref (string); +#ifdef IS_PY3K + output =3D (gdb_byte *) PyBytes_AS_STRING (string); + length =3D PyBytes_GET_SIZE (string); +#else output =3D PyString_AsString (string); length =3D PyString_Size (string); +#endif type =3D builtin_type (gdbarch)->builtin_char; =20 if (hint && !strcmp (hint, "string")) @@ -383,6 +388,7 @@ return result; } =20 +#ifndef IS_PY3K static void py_restore_tstate (void *p) { @@ -458,6 +464,7 @@ make_cleanup (py_restore_tstate, frame->f_back); return (PyObject *) frame; } +#endif =20 /* Helper for apply_val_pretty_printer that formats children of the printer, if any exist. If is_py_none is true, then nothing has @@ -471,7 +478,10 @@ { int is_map, is_array, done_flag, pretty; unsigned int i; - PyObject *children, *iter, *frame; + PyObject *children, *iter; +#ifndef IS_PY3K + PyObject *frame; +#endif struct cleanup *cleanups; =20 if (! PyObject_HasAttr (printer, gdbpy_children_cst)) @@ -515,6 +525,7 @@ /* Manufacture a dummy Python frame to work around Python 2.4 bug, where it insists on having a non-NULL tstate->frame when a generator is called. */ +#ifndef IS_PY3K frame =3D push_dummy_python_frame (); if (!frame) { @@ -522,6 +533,7 @@ goto done; } make_cleanup_py_decref (frame); +#endif =20 done_flag =3D 0; for (i =3D 0; i < options->print_max; ++i) Index: gdb/python/py-progspace.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-progspace.c,v retrieving revision 1.9 diff -u -r1.9 py-progspace.c --- gdb/python/py-progspace.c 22 Aug 2012 15:17:21 -0000 1.9 +++ gdb/python/py-progspace.c 12 Nov 2012 15:51:30 -0000 @@ -202,8 +202,7 @@ =20 static PyTypeObject pspace_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Progspace", /*tp_name*/ sizeof (pspace_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-symbol.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-symbol.c,v retrieving revision 1.15 diff -u -r1.15 py-symbol.c --- gdb/python/py-symbol.c 15 Oct 2012 15:20:26 -0000 1.15 +++ gdb/python/py-symbol.c 12 Nov 2012 15:51:30 -0000 @@ -561,8 +561,7 @@ }; =20 PyTypeObject symbol_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Symbol", /*tp_name*/ sizeof (symbol_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-symtab.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-symtab.c,v retrieving revision 1.12 diff -u -r1.12 py-symtab.c --- gdb/python/py-symtab.c 18 Oct 2012 20:14:45 -0000 1.12 +++ gdb/python/py-symtab.c 12 Nov 2012 15:51:30 -0000 @@ -307,7 +307,7 @@ =20 Py_DECREF (self_sal->symtab); xfree (self_sal->sal); - self_sal->ob_type->tp_free (self); + self->ob_type->tp_free (self); } =20 /* Given a sal, and a sal_object that has previously been allocated @@ -539,8 +539,7 @@ }; =20 static PyTypeObject symtab_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Symtab", /*tp_name*/ sizeof (symtab_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -590,8 +589,7 @@ }; =20 static PyTypeObject sal_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Symtab_and_line", /*tp_name*/ sizeof (sal_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-type.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-type.c,v retrieving revision 1.43 diff -u -r1.43 py-type.c --- gdb/python/py-type.c 16 Aug 2012 07:36:28 -0000 1.43 +++ gdb/python/py-type.c 12 Nov 2012 15:51:30 -0000 @@ -122,7 +122,7 @@ field_object *f =3D (field_object *) obj; =20 Py_XDECREF (f->dict); - f->ob_type->tp_free (obj); + obj->ob_type->tp_free (obj); } =20 static PyObject * @@ -1260,7 +1260,7 @@ if (type->next) type->next->prev =3D type->prev; =20 - type->ob_type->tp_free (type); + obj->ob_type->tp_free (type); } =20 /* Return number of fields ("length" of the field dictionary). */ @@ -1655,7 +1655,9 @@ NULL, /* nb_add */ NULL, /* nb_subtract */ NULL, /* nb_multiply */ +#ifndef IS_PY3K NULL, /* nb_divide */ +#endif NULL, /* nb_remainder */ NULL, /* nb_divmod */ NULL, /* nb_power */ @@ -1669,12 +1671,19 @@ NULL, /* nb_and */ NULL, /* nb_xor */ NULL, /* nb_or */ +#ifdef IS_PY3K + NULL, /* nb_int */ + NULL, /* reserved */ +#else NULL, /* nb_coerce */ NULL, /* nb_int */ NULL, /* nb_long */ +#endif NULL, /* nb_float */ +#ifndef IS_PY3K NULL, /* nb_oct */ NULL /* nb_hex */ +#endif }; =20 static PyMappingMethods typy_mapping =3D { @@ -1685,8 +1694,7 @@ =20 static PyTypeObject type_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Type", /*tp_name*/ sizeof (type_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -1735,8 +1743,7 @@ =20 static PyTypeObject field_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Field", /*tp_name*/ sizeof (field_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -1777,8 +1784,7 @@ }; =20 static PyTypeObject type_iterator_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.TypeIterator", /*tp_name*/ sizeof (typy_iterator_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/py-utils.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-utils.c,v retrieving revision 1.13 diff -u -r1.13 py-utils.c --- gdb/python/py-utils.c 1 Mar 2012 21:06:54 -0000 1.13 +++ gdb/python/py-utils.c 12 Nov 2012 15:51:30 -0000 @@ -54,7 +54,8 @@ =20 As an added bonus, the functions accepts a unicode string and returns it right away, so callers don't need to check which kind of string they've - got. + got. In Python 3, all strings are Unicode so this case is always the=20 + one that applies. =20 If the given object is not one of the mentioned string types, NULL is returned, with the TypeError python exception set. */ @@ -70,9 +71,10 @@ unicode_str =3D obj; Py_INCREF (obj); } -=20=20 +#ifndef IS_PY3K else if (PyString_Check (obj)) unicode_str =3D PyUnicode_FromEncodedObject (obj, host_charset (), NUL= L); +#endif else { PyErr_SetString (PyExc_TypeError, @@ -99,7 +101,11 @@ if (string =3D=3D NULL) return NULL; =20 +#ifdef IS_PY3K + result =3D xstrdup (PyBytes_AsString (string)); +#else result =3D xstrdup (PyString_AsString (string)); +#endif =20 Py_DECREF (string); =20 @@ -113,14 +119,8 @@ static PyObject * unicode_to_encoded_python_string (PyObject *unicode_str, const char *chars= et) { - PyObject *string; - /* Translate string to named charset. */ - string =3D PyUnicode_AsEncodedString (unicode_str, charset, NULL); - if (string =3D=3D NULL) - return NULL; - - return string; + return PyUnicode_AsEncodedString (unicode_str, charset, NULL); } =20 /* Returns a newly allocated string with the contents of the given unicode @@ -167,7 +167,9 @@ =20 /* Converts a python string (8-bit or unicode) to a target string in the target's charset. Returns NULL on error, with a python exception - set. */ + set. + + In Python 3, the returned object is a "bytes" object (not a string). */ PyObject * python_string_to_target_python_string (PyObject *obj) { @@ -221,7 +223,11 @@ int gdbpy_is_string (PyObject *obj) { +#ifdef IS_PY3K + return PyUnicode_Check (obj); +#else return PyString_Check (obj) || PyUnicode_Check (obj); +#endif } =20 /* Return the string representation of OBJ, i.e., str (obj). @@ -235,7 +241,11 @@ =20 if (str_obj !=3D NULL) { +#ifdef IS_PY3K + char *msg =3D python_string_to_host_string (str_obj); +#else char *msg =3D xstrdup (PyString_AsString (str_obj)); +#endif =20 Py_DECREF (str_obj); return msg; @@ -335,6 +345,11 @@ PyObject * gdb_py_object_from_longest (LONGEST l) { +#ifdef IS_PY3K + if (sizeof (l) > sizeof (long)) + return PyLong_FromLongLong (l); + return PyLong_FromLong (l); +#else #ifdef HAVE_LONG_LONG /* Defined by Python. */ /* If we have 'long long', and the value overflows a 'long', use a Python Long; otherwise use a Python Int. */ @@ -343,6 +358,7 @@ return PyLong_FromLongLong (l); #endif return PyInt_FromLong (l); +#endif } =20 /* Convert a ULONGEST to the appropriate Python object -- either an @@ -351,6 +367,11 @@ PyObject * gdb_py_object_from_ulongest (ULONGEST l) { +#ifdef IS_PY3K + if (sizeof (l) > sizeof (unsigned long)) + return PyLong_FromUnsignedLongLong (l); + return PyLong_FromUnsignedLong (l); +#else #ifdef HAVE_LONG_LONG /* Defined by Python. */ /* If we have 'long long', and the value overflows a 'long', use a Python Long; otherwise use a Python Int. */ @@ -362,6 +383,7 @@ return PyLong_FromUnsignedLong (l); =20 return PyInt_FromLong (l); +#endif } =20 /* Like PyInt_AsLong, but returns 0 on failure, 1 on success, and puts Index: gdb/python/py-value.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-value.c,v retrieving revision 1.36 diff -u -r1.36 py-value.c --- gdb/python/py-value.c 30 Mar 2012 20:05:55 -0000 1.36 +++ gdb/python/py-value.c 12 Nov 2012 15:51:30 -0000 @@ -106,7 +106,7 @@ =20 Py_XDECREF (self->dynamic_type); =20 - self->ob_type->tp_free (self); + obj->ob_type->tp_free (self); } =20 /* Helper to push a Value object on the global list. */ @@ -1140,6 +1140,7 @@ || (ptr_ok && TYPE_CODE (type) =3D=3D TYPE_CODE_PTR)); } =20 +#ifndef IS_PY3K /* Implements conversion to int. */ static PyObject * valpy_int (PyObject *self) @@ -1161,6 +1162,7 @@ =20 return gdb_py_object_from_longest (l); } +#endif =20 /* Implements conversion to long. */ static PyObject * @@ -1335,9 +1337,14 @@ value =3D value_copy (((value_object *) result)->value); } else +#ifdef IS_PY3K + PyErr_Format (PyExc_TypeError, + _("Could not convert Python object: %S."), obj); +#else PyErr_Format (PyExc_TypeError, _("Could not convert Python object: %s."), PyString_AsString (PyObject_Str (obj))); +#endif } if (except.reason < 0) { @@ -1439,7 +1446,9 @@ valpy_add, valpy_subtract, valpy_multiply, +#ifndef IS_PY3K valpy_divide, +#endif valpy_remainder, NULL, /* nb_divmod */ valpy_power, /* nb_power */ @@ -1453,12 +1462,31 @@ valpy_and, /* nb_and */ valpy_xor, /* nb_xor */ valpy_or, /* nb_or */ +#ifdef IS_PY3K + valpy_long, /* nb_int */ + NULL, /* reserved */ +#else NULL, /* nb_coerce */ valpy_int, /* nb_int */ valpy_long, /* nb_long */ +#endif valpy_float, /* nb_float */ +#ifndef IS_PY3K NULL, /* nb_oct */ - NULL /* nb_hex */ + NULL, /* nb_hex */ +#endif + NULL, /* nb_inplace_add */ + NULL, /* nb_inplace_subtract */ + NULL, /* nb_inplace_multiply */ + NULL, /* nb_inplace_remainder */ + NULL, /* nb_inplace_power */ + NULL, /* nb_inplace_lshift */ + NULL, /* nb_inplace_rshift */ + NULL, /* nb_inplace_and */ + NULL, /* nb_inplace_xor */ + NULL, /* nb_inplace_or */ + NULL, /* nb_floor_divide */ + valpy_divide /* nb_true_divide */ }; =20 static PyMappingMethods value_object_as_mapping =3D { @@ -1468,8 +1496,7 @@ }; =20 PyTypeObject value_object_type =3D { - PyObject_HEAD_INIT (NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT (NULL, 0) "gdb.Value", /*tp_name*/ sizeof (value_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ Index: gdb/python/python-config.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/python-config.py,v retrieving revision 1.3 diff -u -r1.3 python-config.py --- gdb/python/python-config.py 31 Jan 2011 04:42:08 -0000 1.3 +++ gdb/python/python-config.py 12 Nov 2012 15:51:30 -0000 @@ -10,8 +10,8 @@ 'ldflags', 'help'] =20 def exit_with_usage(code=3D1): - print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0], - '|'.join('--'+opt for opt in v= alid_opts)) + sys.stderr.write ("Usage: %s [%s]\n" % (sys.argv[0], + '|'.join('--'+opt for opt in val= id_opts))) sys.exit(code) =20 try: @@ -24,6 +24,7 @@ =20 pyver =3D sysconfig.get_config_var('VERSION') getvar =3D sysconfig.get_config_var +abiflags =3D getattr (sys, "abiflags", "") =20 opt_flags =3D [flag for (flag, val) in opts] =20 @@ -44,17 +45,17 @@ =20 for opt in opt_flags: if opt =3D=3D '--prefix': - print to_unix_path(sysconfig.PREFIX) + print (to_unix_path(sysconfig.PREFIX)) =20 elif opt =3D=3D '--exec-prefix': - print to_unix_path(sysconfig.EXEC_PREFIX) + print (to_unix_path(sysconfig.EXEC_PREFIX)) =20 elif opt in ('--includes', '--cflags'): flags =3D ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=3DTrue)] if opt =3D=3D '--cflags': flags.extend(getvar('CFLAGS').split()) - print to_unix_path(' '.join(flags)) + print (to_unix_path(' '.join(flags))) =20 elif opt in ('--libs', '--ldflags'): libs =3D [] @@ -62,7 +63,7 @@ libs.extend(getvar('LIBS').split()) if getvar('SYSLIBS') is not None: libs.extend(getvar('SYSLIBS').split()) - libs.append('-lpython'+pyver) + libs.append('-lpython'+pyver + abiflags) # add the prefix/lib/pythonX.Y/config dir, but only if there is no # shared library in prefix/lib/. if opt =3D=3D '--ldflags': @@ -73,5 +74,5 @@ libs.insert(0, '-L' + sysconfig.PREFIX + '/libs') if getvar('LINKFORSHARED') is not None: libs.extend(getvar('LINKFORSHARED').split()) - print to_unix_path(' '.join(libs)) + print (to_unix_path(' '.join(libs))) =20 Index: gdb/python/python-internal.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/python-internal.h,v retrieving revision 1.59 diff -u -r1.59 python-internal.h --- gdb/python/python-internal.h 13 Sep 2012 21:49:31 -0000 1.59 +++ gdb/python/python-internal.h 12 Nov 2012 15:51:30 -0000 @@ -49,12 +49,36 @@ from including our python/python.h header file. */ #include #include + +#if PY_MAJOR_VERSION >=3D 3 +#define IS_PY3K 1 +#endif + +#ifdef IS_PY3K +#define Py_TPFLAGS_HAVE_ITER 0 +#define Py_TPFLAGS_CHECKTYPES 0 + +#define PyInt_Check PyLong_Check +#define PyInt_FromLong PyLong_FromLong +#define PyInt_AsLong PyLong_AsLong + +#define PyString_FromString PyUnicode_FromString +#define PyString_Decode PyUnicode_Decode +#define PyString_FromFormat PyUnicode_FromFormat +#define PyString_Check PyUnicode_Check +#endif + #if HAVE_LIBPYTHON2_4 /* Py_ssize_t is not defined until 2.5. Logical type for Py_ssize_t is Py_intptr_t, but that fails in 64-bit compilation due to several apparent mistakes in python2.4 API, so we use 'int' instead. */ typedef int Py_ssize_t; + +/* Python 2.4 does not define PyVarObject_HEAD_INIT. */ +#define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, + #endif =20 /* If Python.h does not define WITH_THREAD, then the various Index: gdb/python/python.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/python.c,v retrieving revision 1.98 diff -u -r1.98 python.c --- gdb/python/python.c 21 Sep 2012 12:57:34 -0000 1.98 +++ gdb/python/python.c 12 Nov 2012 15:51:30 -0000 @@ -70,9 +70,14 @@ #include "gdbthread.h" #include "observer.h" #include "interps.h" +#include "event-top.h" =20 static PyMethodDef GdbMethods[]; =20 +#ifdef IS_PY3K +static struct PyModuleDef GdbModuleDef; +#endif + PyObject *gdb_module; PyObject *gdb_python_module; =20 @@ -198,8 +203,10 @@ return -1; =20 Py_DECREF (v); +#ifndef IS_PY3K if (Py_FlushLine ()) PyErr_Clear (); +#endif =20 return 0; } @@ -1295,6 +1302,14 @@ { char *cmd_name; struct cmd_list_element *cmd; + char *progname; +#ifdef IS_PY3K + int i; + size_t progsize, count; + char *oldloc; + wchar_t *progname_copy; +#endif + =20 add_com ("python-interactive", class_obscure, python_interactive_command, @@ -1374,14 +1389,44 @@ /foo/bin/python /foo/lib/pythonX.Y/... This must be done before calling Py_Initialize. */ - Py_SetProgramName (concat (ldirname (python_libdir), SLASH_STRING, "bin", - SLASH_STRING, "python", NULL)); + progname =3D concat (ldirname (python_libdir), SLASH_STRING, "bin", + SLASH_STRING, "python", NULL); +#ifdef IS_PY3K + oldloc =3D setlocale (LC_ALL, NULL); + setlocale (LC_ALL, ""); + progsize =3D strlen (progname); + if (progsize =3D=3D (size_t) -1) + { + fprintf(stderr, "Could not convert python path to string\n"); + exit (1); + } + progname_copy =3D PyMem_Malloc((progsize + 1) * sizeof (wchar_t)); + if (!progname_copy) + { + fprintf(stderr, "out of memory\n"); + exit (1); + } + count =3D mbstowcs (progname_copy, progname, progsize + 1); + if (count =3D=3D (size_t) -1) { + fprintf(stderr, "Could not convert python path to string\n"); + exit (1); + } + setlocale (LC_ALL, oldloc); + Py_SetProgramName (progname_copy); +#else + Py_SetProgramName (progname); +#endif #endif =20 Py_Initialize (); PyEval_InitThreads (); =20 +#ifdef IS_PY3K + gdb_module =3D PyModule_Create (&GdbModuleDef); + _PyImport_FixupBuiltin (gdb_module, "_gdb"); +#else gdb_module =3D Py_InitModule ("_gdb", GdbMethods); +#endif =20 /* The casts to (char*) are for python 2.4. */ PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version); @@ -1476,7 +1521,17 @@ =20 sys_path =3D PySys_GetObject ("path"); =20 - if (sys_path && PyList_Check (sys_path)) + /* If sys.path is not defined yet, define it first. */ + if (!(sys_path && PyList_Check (sys_path))) + { +#ifdef IS_PY3K + PySys_SetPath (L""); +#else + PySys_SetPath (""); +#endif + sys_path =3D PySys_GetObject ("path"); + } + if (sys_path && PyList_Check (sys_path))=20=20 { PyObject *pythondir; int err; @@ -1492,7 +1547,7 @@ Py_DECREF (pythondir); } else - PySys_SetPath (gdb_pythondir); + goto fail; =20 /* Import the gdb module to finish the initialization, and add it to __main__ for convenience. */ @@ -1632,4 +1687,18 @@ {NULL, NULL, 0, NULL} }; =20 +#ifdef IS_PY3K +static struct PyModuleDef GdbModuleDef =3D +{ + PyModuleDef_HEAD_INIT, + "_gdb", + NULL, + -1,=20 + GdbMethods, + NULL, + NULL, + NULL, + NULL +}; +#endif #endif /* HAVE_PYTHON */ Index: gdb/python/lib/gdb/__init__.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/lib/gdb/__init__.py,v retrieving revision 1.6 diff -u -r1.6 __init__.py --- gdb/python/lib/gdb/__init__.py 13 Sep 2012 21:49:31 -0000 1.6 +++ gdb/python/lib/gdb/__init__.py 12 Nov 2012 15:51:30 -0000 @@ -18,9 +18,17 @@ import sys import _gdb =20 +if sys.version_info[0] > 2: + # Python 3 moved "reload" + from imp import reload + from _gdb import * =20 -class GdbOutputFile: +class _GdbFile (object): + # These two are needed in Python 3 + encoding =3D "UTF-8" + errors =3D "strict" +=20=20=20=20 def close(self): # Do nothing. return None @@ -28,9 +36,6 @@ def isatty(self): return False =20 - def write(self, s): - write(s, stream=3DSTDOUT) - def writelines(self, iterable): for line in iterable: self.write(line) @@ -38,26 +43,16 @@ def flush(self): flush() =20 -sys.stdout =3D GdbOutputFile() - -class GdbOutputErrorFile: - def close(self): - # Do nothing. - return None +class GdbOutputFile (_GdbFile): + def write(self, s): + write(s, stream=3DSTDOUT) =20 - def isatty(self): - return False +sys.stdout =3D GdbOutputFile() =20 +class GdbOutputErrorFile (_GdbFile): def write(self, s): write(s, stream=3DSTDERR) =20 - def writelines(self, iterable): - for line in iterable: - self.write(line) - - def flush(self): - flush() - sys.stderr =3D GdbOutputErrorFile() =20 # Default prompt hook does nothing. @@ -104,7 +99,7 @@ else: __import__(modname) except: - print >> sys.stderr, traceback.format_exc() + sys.stderr.write (traceback.format_exc() + "\n") =20 auto_load_packages() =20 Index: gdb/python/lib/gdb/printing.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/lib/gdb/printing.py,v retrieving revision 1.9 diff -u -r1.9 printing.py --- gdb/python/lib/gdb/printing.py 18 Apr 2012 06:46:46 -0000 1.9 +++ gdb/python/lib/gdb/printing.py 12 Nov 2012 15:51:30 -0000 @@ -19,7 +19,12 @@ import gdb import gdb.types import re +import sys =20 +if sys.version_info[0] > 2: + # Python 3 removed basestring and long + basestring =3D str + long =3D int =20 class PrettyPrinter(object): """A basic pretty-printer. Index: gdb/python/lib/gdb/prompt.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/lib/gdb/prompt.py,v retrieving revision 1.2 diff -u -r1.2 prompt.py --- gdb/python/lib/gdb/prompt.py 4 Jan 2012 08:17:24 -0000 1.2 +++ gdb/python/lib/gdb/prompt.py 12 Nov 2012 15:51:30 -0000 @@ -98,8 +98,7 @@ functions.""" =20 result =3D '' - keys =3D prompt_substitutions.keys() - keys.sort() + keys =3D sorted (prompt_substitutions.keys()) for key in keys: result +=3D ' \\%s\t%s\n' % (key, prompt_substitutions[key].__doc= __) result +=3D """ Index: gdb/python/lib/gdb/command/explore.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/lib/gdb/command/explore.py,v retrieving revision 1.1 diff -u -r1.1 explore.py --- gdb/python/lib/gdb/command/explore.py 11 Apr 2012 05:50:44 -0000 1.1 +++ gdb/python/lib/gdb/command/explore.py 12 Nov 2012 15:51:30 -0000 @@ -17,7 +17,12 @@ """Implementation of the GDB 'explore' command using the GDB Python API.""" =20 import gdb +import sys =20 +if sys.version_info[0] > 2: + # Python 3 renamed raw_input to input + raw_input =3D input +=20=20=20=20 class Explorer(object): """Internal class which invokes other explorers.""" =20 @@ -155,7 +160,7 @@ """A utility function which prints that the current exploration se= ssion is returning to the parent value. Useful when exploring values. """ - print "\nReturning to parent value...\n" + print ("\nReturning to parent value...\n") =20=20=20=20=20=20=20=20=20 @staticmethod def return_to_parent_value_prompt(): @@ -170,7 +175,7 @@ """A utility function which prints that the current exploration se= ssion is returning to the enclosing type. Useful when exploring types. """ - print "\nReturning to enclosing type...\n" + print ("\nReturning to enclosing type...\n") =20=20=20=20=20=20=20=20=20 @staticmethod def return_to_enclosing_type_prompt(): @@ -192,7 +197,7 @@ """ print ("'%s' is a scalar value of type '%s'." % (expr, value.type)) - print "%s =3D %s" % (expr, str(value)) + print ("%s =3D %s" % (expr, str(value))) =20 if is_child: Explorer.return_to_parent_value_prompt() @@ -211,13 +216,13 @@ print ("%s is of an enumerated type '%s'." % (name, str(datatype))) else: - print "'%s' is an enumerated type." % name + print ("'%s' is an enumerated type." % name) else: if is_child: print ("%s is of a scalar type '%s'." % (name, str(datatype))) else: - print "'%s' is a scalar type." % name + print ("'%s' is a scalar type." % name) =20 if is_child: Explorer.return_to_enclosing_type_prompt() @@ -268,7 +273,7 @@ try: str(element) except gdb.MemoryError: - print "Cannot read value at index %d." % index + print ("Cannot read value at index %d." % index) continue Explorer.explore_expr(element_expr, element, True) return False @@ -338,7 +343,7 @@ element =3D value[index] str(element) except gdb.MemoryError: - print "Cannot read value at index %d." % index + print ("Cannot read value at index %d." % index) raw_input("Press enter to continue... ") return True =20=20=20=20=20=20=20=20=20=20=20=20=20 @@ -352,7 +357,7 @@ See Explorer.explore_type for more information. """ target_type =3D datatype.target() - print "%s is an array of '%s'." % (name, str(target_type)) + print ("%s is an array of '%s'." % (name, str(target_type))) =20 Explorer.explore_type("the array element of %s" % name, target_typ= e, is_child) @@ -371,9 +376,8 @@ if max_field_name_length < len(pair[0]): max_field_name_length =3D len(pair[0]) =20 - format_str =3D " {0:>%d} =3D {1}" % max_field_name_length for pair in print_list: - print format_str.format(pair[0], pair[1]) + print ("%*s =3D %s" % (max_field_name_length, pair[0], pair[1]= )) =20 @staticmethod def _get_real_field_count(fields): @@ -447,7 +451,7 @@ print_list.append((field.name, literal_value)) =20 CompoundExplorer._print_fields(print_list) - print "" + print ("") =20 if has_explorable_fields: choice =3D raw_input("Enter the field number of choice: ") @@ -484,7 +488,7 @@ (name, type_desc, str(datatype))) Explorer.return_to_enclosing_type_prompt() else: - print "'%s' is a %s with no fields." % (name, type_desc) + print ("'%s' is a %s with no fields." % (name, type_desc)) return False =20 if is_child: @@ -515,7 +519,7 @@ current_choice =3D current_choice + 1 =20 CompoundExplorer._print_fields(print_list) - print "" + print ("") =20 if len(choice_to_compound_field_map) > 0: choice =3D raw_input("Enter the field number of choice: ") @@ -741,7 +745,7 @@ =20 value =3D ExploreUtils.get_value_from_str(arg_str) if value is not None: - print "'%s' is of type '%s'." % (arg_str, str(value.type)) + print ("'%s' is of type '%s'." % (arg_str, str(value.type))) Explorer.explore_type(str(value.type), value.type, False) =20 raise gdb.GdbError(("'%s' is not a type or value in the current " Index: gdb/python/lib/gdb/command/pretty_printers.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/lib/gdb/command/pretty_printers.py,v retrieving revision 1.7 diff -u -r1.7 pretty_printers.py --- gdb/python/lib/gdb/command/pretty_printers.py 4 Jan 2012 08:17:25 -0000= 1.7 +++ gdb/python/lib/gdb/command/pretty_printers.py 12 Nov 2012 15:51:30 -0000 @@ -124,21 +124,17 @@ """Print a list of pretty-printers.""" # A potential enhancement is to provide an option to list printers= in # "lookup order" (i.e. unsorted). - sorted_pretty_printers =3D copy.copy(pretty_printers) - sorted_pretty_printers.sort(lambda x, y: - cmp(self.printer_name(x), - self.printer_name(y))) + sorted_pretty_printers =3D sorted (copy.copy(pretty_printers), + key =3D self.printer_name) for printer in sorted_pretty_printers: name =3D self.printer_name(printer) enabled =3D self.enabled_string(printer) if name_re.match(name): - print " %s%s" % (name, enabled) + print (" %s%s" % (name, enabled)) if (hasattr(printer, "subprinters") and printer.subprinters is not None): - sorted_subprinters =3D copy.copy(printer.subprinters) - sorted_subprinters.sort(lambda x, y: - cmp(self.printer_name(x), - self.printer_name(y))) + sorted_subprinters =3D sorted (copy.copy(printer.subpr= inters), + key =3D self.printer_name) for subprinter in sorted_subprinters: if (not subname_re or subname_re.match(subprinter.name)): @@ -150,7 +146,7 @@ obj_name_to_match, object_re, name_re, subname_re): """Subroutine of invoke to simplify it.""" if printer_list and object_re.match(obj_name_to_match): - print title + print (title) self.list_pretty_printers(printer_list, name_re, subname_re) =20 def invoke(self, arg, from_tty): @@ -219,7 +215,7 @@ We count subprinters individually. """ (enabled_count, total_count) =3D count_all_enabled_printers() - print "%d of %d printers enabled" % (enabled_count, total_count) + print ("%d of %d printers enabled" % (enabled_count, total_count)) =20 =20 def do_enable_pretty_printer_1 (pretty_printers, name_re, subname_re, flag= ): @@ -301,7 +297,7 @@ state =3D "enabled" else: state =3D "disabled" - print "%d %s %s" % (total, pluralize("printer", total), state) + print ("%d %s %s" % (total, pluralize("printer", total), state)) =20 # Print the total list of printers currently enabled/disabled. # This is to further assist the user in determining whether the result