Skip to content

Commit 146ebf3

Browse files
committed
fixed type of reference in PyException_SetCause
1 parent d976acf commit 146ebf3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/runtime/exceptions.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public static void SetCause(Exception cause)
295295
var currentException = PythonException.FetchCurrentRaw();
296296
currentException.Normalize();
297297
using var causeInstance = Converter.ToPythonReference(cause);
298-
Runtime.PyException_SetCause(currentException.Value.Reference, causeInstance);
298+
Runtime.PyException_SetCause(currentException.Value!.Reference, causeInstance.Steal());
299299
currentException.Restore();
300300
}
301301

@@ -392,7 +392,9 @@ internal static IntPtr RaiseTypeError(string message)
392392
var typeError = PythonException.FetchCurrentRaw();
393393
typeError.Normalize();
394394

395-
Runtime.PyException_SetCause(typeError.Value.Reference, cause.Value.Reference);
395+
Runtime.PyException_SetCause(
396+
typeError.Value!.Reference,
397+
new NewReference(cause.Value!.Reference).Steal());
396398
typeError.Restore();
397399

398400
return IntPtr.Zero;

src/runtime/runtime.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ internal static NewReference PyException_GetTraceback(BorrowedReference ex)
21122112
/// <summary>
21132113
/// Set the cause associated with the exception to cause. Use NULL to clear it. There is no type check to make sure that cause is either an exception instance or None. This steals a reference to cause.
21142114
/// </summary>
2115-
internal static void PyException_SetCause(BorrowedReference ex, BorrowedReference cause)
2115+
internal static void PyException_SetCause(BorrowedReference ex, StolenReference cause)
21162116
=> Delegates.PyException_SetCause(ex, cause);
21172117
internal static int PyException_SetTraceback(BorrowedReference ex, BorrowedReference tb)
21182118
=> Delegates.PyException_SetTraceback(ex, tb);
@@ -2516,7 +2516,7 @@ static Delegates()
25162516
PyDict_GetItemWithError = (delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference, BorrowedReference>)GetFunctionByName(nameof(PyDict_GetItemWithError), GetUnmanagedDll(_PythonDll));
25172517
PyException_GetCause = (delegate* unmanaged[Cdecl]<BorrowedReference, NewReference>)GetFunctionByName(nameof(PyException_GetCause), GetUnmanagedDll(_PythonDll));
25182518
PyException_GetTraceback = (delegate* unmanaged[Cdecl]<BorrowedReference, NewReference>)GetFunctionByName(nameof(PyException_GetTraceback), GetUnmanagedDll(_PythonDll));
2519-
PyException_SetCause = (delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference, void>)GetFunctionByName(nameof(PyException_SetCause), GetUnmanagedDll(_PythonDll));
2519+
PyException_SetCause = (delegate* unmanaged[Cdecl]<BorrowedReference, StolenReference, void>)GetFunctionByName(nameof(PyException_SetCause), GetUnmanagedDll(_PythonDll));
25202520
PyException_SetTraceback = (delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference, int>)GetFunctionByName(nameof(PyException_SetTraceback), GetUnmanagedDll(_PythonDll));
25212521
PyThreadState_SetAsyncExcLLP64 = (delegate* unmanaged[Cdecl]<uint, IntPtr, int>)GetFunctionByName("PyThreadState_SetAsyncExc", GetUnmanagedDll(_PythonDll));
25222522
PyThreadState_SetAsyncExcLP64 = (delegate* unmanaged[Cdecl]<ulong, IntPtr, int>)GetFunctionByName("PyThreadState_SetAsyncExc", GetUnmanagedDll(_PythonDll));
@@ -2796,7 +2796,7 @@ static Delegates()
27962796
internal static delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference, BorrowedReference> PyDict_GetItemWithError { get; }
27972797
internal static delegate* unmanaged[Cdecl]<BorrowedReference, NewReference> PyException_GetCause { get; }
27982798
internal static delegate* unmanaged[Cdecl]<BorrowedReference, NewReference> PyException_GetTraceback { get; }
2799-
internal static delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference, void> PyException_SetCause { get; }
2799+
internal static delegate* unmanaged[Cdecl]<BorrowedReference, StolenReference, void> PyException_SetCause { get; }
28002800
internal static delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference, int> PyException_SetTraceback { get; }
28012801
internal static delegate* unmanaged[Cdecl]<uint, IntPtr, int> PyThreadState_SetAsyncExcLLP64 { get; }
28022802
internal static delegate* unmanaged[Cdecl]<ulong, IntPtr, int> PyThreadState_SetAsyncExcLP64 { get; }

0 commit comments

Comments
 (0)