@@ -176,44 +176,23 @@ func PyErr_ExceptionMatches(exc *PyObject) bool {
176176 return ret == 1
177177}
178178
179- // PyErr_Fetch retrieves the error indicator into three variables whose addresses are passed. If the error indicator is
180- // not set, set all three variables to NULL. If it is set, it will be cleared and you own a reference to each object
181- // retrieved. The value and traceback object may be NULL even when the type object is not.
179+ // PyErr_GetRaisedException Return the exception currently being raised, clearing the error indicator at the same time.
180+ // Return NULL if the error indicator is not set.
182181//
183- // Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Fetch
184- func PyErr_Fetch () (* PyObject , * PyObject , * PyObject ) {
185- var pyType , value , traceback * C.PyObject
186-
187- C .PyErr_Fetch (& pyType , & value , & traceback ) //nolint: gocritic
188-
189- return togo (pyType ), togo (value ), togo (traceback )
190- }
191-
192- // PyErr_Restore sets the error indicator from the three objects, type, value, and traceback, clearing the existing
193- // exception if one is set. If the objects are NULL, the error indicator is cleared. Do not pass a NULL type and
194- // non-NULL value or traceback. The exception type should be a class. Do not pass an invalid exception type or value.
195- // (Violating these rules will cause subtle problems later.) This call takes away a reference to each object: you must
196- // own a reference to each object before the call and after the call you no longer own these references.
197- // (If you don't understand this, don't use this function. I warned you.)
182+ // This function is used by code that needs to catch exceptions, or code that needs to save and restore the error
183+ // indicator temporarily.
198184//
199- // Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Restore
200- func PyErr_Restore ( pyType * PyObject , value * PyObject , traceback * PyObject ) {
201- C . PyErr_Restore ( toc ( pyType ), toc ( value ), toc ( traceback ))
185+ // Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_GetRaisedException
186+ func PyErr_GetRaisedException () * PyObject {
187+ return togo ( C . PyErr_GetRaisedException ( ))
202188}
203189
204- // PyErr_NormalizeException is used to instantiate the class in that the values returned by PyErr_Fetch() below can be
205- // "unnormalized", meaning that *exc is a class object but *val is not an instance of the same class. If the values are
206- // already normalized, nothing happens. The delayed normalization is implemented to improve performance.
190+ // PyErr_SetRaisedException Set exc as the exception currently being raised, clearing the existing exception if one is
191+ // set.
207192//
208- // Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NormalizeException
209- func PyErr_NormalizeException (exc , val , tb * PyObject ) (* PyObject , * PyObject , * PyObject ) {
210- cexc := toc (exc )
211- cval := toc (val )
212- ctb := toc (tb )
213-
214- C .PyErr_NormalizeException (& cexc , & cval , & ctb ) //nolint: gocritic
215-
216- return togo (cexc ), togo (cval ), togo (ctb )
193+ // Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetRaisedException
194+ func PyErr_SetRaisedException (exec * PyObject ) {
195+ C .PyErr_SetRaisedException (toc (exec ))
217196}
218197
219198// PyErr_GetExcInfo retrieves the old-style representation of the exception info, as known from sys.exc_info(). This
0 commit comments