aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-utils.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-12-23 20:20:46 -0500
committerSimon Marchi <simon.marchi@efficios.com>2022-03-23 07:41:19 -0400
commitedae3fd6600f10f9e16dc017b705959f541ed19a (patch)
tree0e8b6288c02dec48f369594a9032dcac20146e33 /gdb/python/py-utils.c
parente52a16f2aa20773f42c28bf91a568d0683e5767c (diff)
downloadgdb-edae3fd6600f10f9e16dc017b705959f541ed19a.zip
gdb-edae3fd6600f10f9e16dc017b705959f541ed19a.tar.gz
gdb-edae3fd6600f10f9e16dc017b705959f541ed19a.tar.bz2
gdb/python: remove Python 2 support
New in this version: - Add a PY_MAJOR_VERSION check in configure.ac / AC_TRY_LIBPYTHON. If the user passes --with-python=python2, this will cause a configure failure saying that GDB only supports Python 3. Support for Python 2 is a maintenance burden for any patches touching Python support. Among others, the differences between Python 2 and 3 string and integer types are subtle. It requires a lot of effort and thinking to get something that behaves correctly on both. And that's if the author and reviewer of the patch even remember to test with Python 2. See this thread for an example: https://sourceware.org/pipermail/gdb-patches/2021-December/184260.html So, remove Python 2 support. Update the documentation to state that GDB can be built against Python 3 (as opposed to Python 2 or 3). Update all the spots that use: - sys.version_info - IS_PY3K - PY_MAJOR_VERSION - gdb_py_is_py3k ... to only keep the Python 3 portions and drop the use of some now-removed compatibility macros. I did not update the configure script more than just removing the explicit references to Python 2. We could maybe do more there, like check the Python version and reject it if that version is not supported. Otherwise (with this patch), things will only fail at compile time, so it won't really be clear to the user that they are trying to use an unsupported Python version. But I'm a bit lost in the configure code that checks for Python, so I kept that for later. Change-Id: I75b0f79c148afbe3c07ac664cfa9cade052c0c62
Diffstat (limited to 'gdb/python/py-utils.c')
-rw-r--r--gdb/python/py-utils.c47
1 files changed, 2 insertions, 45 deletions
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 838853c..e7b147c 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -45,14 +45,10 @@ python_string_to_unicode (PyObject *obj)
unicode_str = obj;
Py_INCREF (obj);
}
-#ifndef IS_PY3K
- else if (PyString_Check (obj))
- unicode_str = PyUnicode_FromEncodedObject (obj, host_charset (), NULL);
-#endif
else
{
PyErr_SetString (PyExc_TypeError,
- _("Expected a string or unicode object."));
+ _("Expected a string object."));
unicode_str = NULL;
}
@@ -166,11 +162,7 @@ host_string_to_python_string (const char *str)
int
gdbpy_is_string (PyObject *obj)
{
-#ifdef IS_PY3K
return PyUnicode_Check (obj);
-#else
- return PyString_Check (obj) || PyUnicode_Check (obj);
-#endif
}
/* Return the string representation of OBJ, i.e., str (obj).
@@ -182,17 +174,7 @@ gdbpy_obj_to_string (PyObject *obj)
gdbpy_ref<> str_obj (PyObject_Str (obj));
if (str_obj != NULL)
- {
- gdb::unique_xmalloc_ptr<char> msg;
-
-#ifdef IS_PY3K
- msg = python_string_to_host_string (str_obj.get ());
-#else
- msg.reset (xstrdup (PyString_AsString (str_obj.get ())));
-#endif
-
- return msg;
- }
+ return python_string_to_host_string (str_obj.get ());
return NULL;
}
@@ -296,20 +278,9 @@ get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
gdbpy_ref<>
gdb_py_object_from_longest (LONGEST l)
{
-#ifdef IS_PY3K
if (sizeof (l) > sizeof (long))
return gdbpy_ref<> (PyLong_FromLongLong (l));
return gdbpy_ref<> (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. */
- if (sizeof (l) > sizeof (long)
- && (l > PyInt_GetMax () || l < (- (LONGEST) PyInt_GetMax ()) - 1))
- return gdbpy_ref<> (PyLong_FromLongLong (l));
-#endif
- return gdbpy_ref<> (PyInt_FromLong (l));
-#endif
}
/* Convert a ULONGEST to the appropriate Python object -- either an
@@ -318,23 +289,9 @@ gdb_py_object_from_longest (LONGEST l)
gdbpy_ref<>
gdb_py_object_from_ulongest (ULONGEST l)
{
-#ifdef IS_PY3K
if (sizeof (l) > sizeof (unsigned long))
return gdbpy_ref<> (PyLong_FromUnsignedLongLong (l));
return gdbpy_ref<> (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. */
- if (sizeof (l) > sizeof (unsigned long) && l > PyInt_GetMax ())
- return gdbpy_ref<> (PyLong_FromUnsignedLongLong (l));
-#endif
-
- if (l > PyInt_GetMax ())
- return gdbpy_ref<> (PyLong_FromUnsignedLong (l));
-
- return gdbpy_ref<> (PyInt_FromLong (l));
-#endif
}
/* Like PyInt_AsLong, but returns 0 on failure, 1 on success, and puts