public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/python] Handle deprecation of PyErr_{Fetch,Restore} in 3.12
@ 2024-03-09 15:12 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2024-03-09 15:12 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2cf3c79c807917097a2eea5a2b3eb326f17581d1

commit 2cf3c79c807917097a2eea5a2b3eb326f17581d1
Author: Tom de Vries <tdevries@suse.de>
Date:   Sat Mar 9 16:13:10 2024 +0100

    [gdb/python] Handle deprecation of PyErr_{Fetch,Restore} in 3.12
    
    Starting python version 3.12, PyErr_Fetch and PyErr_Restore are deprecated.
    
    Use PyErr_GetRaisedException and PyErr_SetRaisedException instead, for
    python >= 3.12.
    
    Tested on aarch64-linux.
    
    Approved-By: Tom Tromey <tom@tromey.com>

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:
 
   gdbpy_err_fetch ()
   {
+#if PY_VERSION_HEX < 0x030c0000
     PyObject *error_type, *error_value, *error_traceback;
 
     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_GetRaisedException
+       instead.  */
+    m_exc.reset (PyErr_GetRaisedException ());
+#endif
   }
 
   /* Call PyErr_Restore using the values stashed in this object.
@@ -654,9 +660,15 @@ public:
 
   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_SetRaisedException
+       instead.  */
+    PyErr_SetRaisedException (m_exc.release ());
+#endif
   }
 
   /* Return the string representation of the exception represented by
@@ -683,6 +695,7 @@ public:
 
   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 = true;
       }
     return m_error_value;
+#else
+    return m_exc;
+#endif
   }
 
   /* Return a new reference to the exception type object.  */
 
   gdbpy_ref<> type () const
   {
+#if PY_VERSION_HEX < 0x030c0000
     return m_error_type;
+#else
+    if (m_exc.get() == nullptr)
+      return nullptr;
+    return gdbpy_ref<>::new_reference ((PyObject *)Py_TYPE (m_exc.get ()));
+#endif
   }
 
 private:
 
+#if PY_VERSION_HEX < 0x030c0000
   mutable gdbpy_ref<> m_error_type, m_error_value, m_error_traceback;
   mutable bool m_normalized = false;
+#else
+  gdbpy_ref<> m_exc;
+#endif
 };
 
 /* Called before entering the Python interpreter to install the

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-09 15:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-09 15:12 [binutils-gdb] [gdb/python] Handle deprecation of PyErr_{Fetch,Restore} in 3.12 Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).