From 87dd9fd41e4cd9392704b7d3058ecaf41a442dd6 Mon Sep 17 00:00:00 2001 From: Victor Nova Date: Sun, 11 Apr 2021 12:58:24 -0700 Subject: [PATCH] added a few debug checks --- src/runtime/runtime.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/runtime/runtime.cs b/src/runtime/runtime.cs index 3929494d7..383de3c30 100644 --- a/src/runtime/runtime.cs +++ b/src/runtime/runtime.cs @@ -1128,13 +1128,31 @@ internal static int PyObject_Compare(IntPtr value1, IntPtr value2) internal static nint PyObject_Hash(IntPtr op) => Delegates.PyObject_Hash(op); - internal static IntPtr PyObject_Repr(IntPtr pointer) => Delegates.PyObject_Repr(pointer); + internal static IntPtr PyObject_Repr(IntPtr pointer) + { + AssertNoErorSet(); + return Delegates.PyObject_Repr(pointer); + } internal static IntPtr PyObject_Str(IntPtr pointer) => Delegates.PyObject_Str(pointer); - internal static IntPtr PyObject_Unicode(IntPtr pointer) => Delegates.PyObject_Unicode(pointer); + internal static IntPtr PyObject_Unicode(IntPtr pointer) + { + AssertNoErorSet(); + + return Delegates.PyObject_Unicode(pointer); + } + + [Conditional("DEBUG")] + internal static void AssertNoErorSet() + { + if (Exceptions.ErrorOccurred()) + throw new InvalidOperationException( + "Can't call with exception set", + PythonException.FetchCurrent()); + } internal static IntPtr PyObject_Dir(IntPtr pointer) => Delegates.PyObject_Dir(pointer);