From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id F07DB3858419; Sat, 9 Mar 2024 15:12:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F07DB3858419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1709997164; bh=pLLgDKmNvCNYRqtQtYHN/6IGPhqdX1ei2xW48j7C7J8=; h=From:To:Subject:Date:From; b=hOC1BiGOUCjX9tS3s0unMXZUqjSM4JFR16y1XbQU887TMLkY9pHYrrY8OGr64uVJA r20xN4tJKDqOWAiWSLJDCcLgBH69+HjSdTLXAEPum88SrLihYeSVi4JGZXyqFv/y5Q nQ0tP82A9V9GwvFCPjEC3od+DmKoSsGOMiDKxzK0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/python] Handle deprecation of PyErr_{Fetch,Restore} in 3.12 X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 50ede76876981364d6b1a314bb79c0412980c435 X-Git-Newrev: 2cf3c79c807917097a2eea5a2b3eb326f17581d1 Message-Id: <20240309151244.F07DB3858419@sourceware.org> Date: Sat, 9 Mar 2024 15:12:44 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D2cf3c79c8079= 17097a2eea5a2b3eb326f17581d1 commit 2cf3c79c807917097a2eea5a2b3eb326f17581d1 Author: Tom de Vries Date: Sat Mar 9 16:13:10 2024 +0100 [gdb/python] Handle deprecation of PyErr_{Fetch,Restore} in 3.12 =20 Starting python version 3.12, PyErr_Fetch and PyErr_Restore are depreca= ted. =20 Use PyErr_GetRaisedException and PyErr_SetRaisedException instead, for python >=3D 3.12. =20 Tested on aarch64-linux. =20 Approved-By: Tom Tromey Diff: --- gdb/python/python-internal.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 30802ae2480..d603b3a1b85 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -640,12 +640,18 @@ public: =20 gdbpy_err_fetch () { +#if PY_VERSION_HEX < 0x030c0000 PyObject *error_type, *error_value, *error_traceback; =20 PyErr_Fetch (&error_type, &error_value, &error_traceback); m_error_type.reset (error_type); m_error_value.reset (error_value); m_error_traceback.reset (error_traceback); +#else + /* PyErr_Fetch is deprecated in python 3.12, use PyErr_GetRaisedExcept= ion + instead. */ + m_exc.reset (PyErr_GetRaisedException ()); +#endif } =20 /* Call PyErr_Restore using the values stashed in this object. @@ -654,9 +660,15 @@ public: =20 void restore () { +#if PY_VERSION_HEX < 0x030c0000 PyErr_Restore (m_error_type.release (), m_error_value.release (), m_error_traceback.release ()); +#else + /* PyErr_Restore is deprecated in python 3.12, use PyErr_SetRaisedExce= ption + instead. */ + PyErr_SetRaisedException (m_exc.release ()); +#endif } =20 /* Return the string representation of the exception represented by @@ -683,6 +695,7 @@ public: =20 gdbpy_ref<> value () const { +#if PY_VERSION_HEX < 0x030c0000 if (!m_normalized) { PyObject *error_type, *error_value, *error_traceback; @@ -696,19 +709,32 @@ public: m_normalized =3D true; } return m_error_value; +#else + return m_exc; +#endif } =20 /* Return a new reference to the exception type object. */ =20 gdbpy_ref<> type () const { +#if PY_VERSION_HEX < 0x030c0000 return m_error_type; +#else + if (m_exc.get() =3D=3D nullptr) + return nullptr; + return gdbpy_ref<>::new_reference ((PyObject *)Py_TYPE (m_exc.get ())); +#endif } =20 private: =20 +#if PY_VERSION_HEX < 0x030c0000 mutable gdbpy_ref<> m_error_type, m_error_value, m_error_traceback; mutable bool m_normalized =3D false; +#else + gdbpy_ref<> m_exc; +#endif }; =20 /* Called before entering the Python interpreter to install the