8000 added a few debug checks · pythonnet/pythonnet@6679d1c · GitHub
[go: up one dir, main page]

Skip to content

Commit 6679d1c

Browse files
committed
added a few debug checks
1 parent 6819e7b commit 6679d1c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/runtime/runtime.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,13 +1128,31 @@ internal static int PyObject_Compare(IntPtr value1, IntPtr value2)
11281128
internal static nint PyObject_Hash(IntPtr op) => Delegates.PyObject_Hash(op);
11291129

11301130

1131-
internal static IntPtr PyObject_Repr(IntPtr pointer) => Delegates.PyObject_Repr(pointer);
1131+
internal static IntPtr PyObject_Repr(IntPtr pointer)
1132+
{
1133+
AssertNoErorSet();
11321134

1135+
return Delegates.PyObject_Repr(pointer);
1136+
}
11331137

11341138
internal static IntPtr PyObject_Str(IntPtr pointer) => Delegates.PyObject_Str(pointer);
11351139

11361140

1137-
internal static IntPtr PyObject_Unicode(IntPtr pointer) => Delegates.PyObject_Unicode(pointer);
1141+
internal static IntPtr PyObject_Unicode(IntPtr pointer)
1142+
{
1143+
AssertNoErorSet();
1144+
1145+
return Delegates.PyObject_Unicode(pointer);
1146+
}
1147+
1148+
[Conditional("DEBUG")]
1149+
internal static void AssertNoErorSet()
1150+
{
1151+
if (Exceptions.ErrorOccurred())
1152+
throw new InvalidOperationException(
1153+
"Can't call with exception set",
1154+
PythonException.FetchCurrent());
1155+
}
11381156

11391157

11401158
internal static IntPtr PyObject_Dir(IntPtr pointer) => Delegates.PyObject_Dir(pointer);

0 commit comments

Comments
 (0)
0