Inheritance: IDisposable
Esempio n. 1
0
 public void Collect()
 {
     using (var gilState = new Py.GILState())
     {
         DisposeAll();
     }
 }
Esempio n. 2
0
        internal static Exception?FetchCurrentOrNull(out ExceptionDispatchInfo?dispatchInfo)
        {
            dispatchInfo = null;

            // prevent potential interop errors in this method
            // from crashing process with undebuggable StackOverflowException
            RuntimeHelpers.EnsureSufficientExecutionStack();

            using var _ = new Py.GILState();
            Runtime.PyErr_Fetch(out var type, out var value, out var traceback);
            if (type.IsNull())
            {
                Debug.Assert(value.IsNull());
                Debug.Assert(traceback.IsNull());
                return(null);
            }

            Runtime.PyErr_NormalizeException(type: ref type, val: ref value, tb: ref traceback);

            try
            {
                return(FromPyErr(typeRef: type, valRef: value, tbRef: traceback, out dispatchInfo));
            }
            finally
            {
                type.Dispose();
                value.Dispose();
                traceback.Dispose();
            }
        }
Esempio n. 3
0
        internal static Exception?PeekCurrentOrNull(out ExceptionDispatchInfo?dispatchInfo)
        {
            using var _ = new Py.GILState();

            Runtime.PyErr_Fetch(out var type, out var value, out var traceback);
            Runtime.PyErr_Restore(
                new NewReference(type, canBeNull: true).StealNullable(),
                new NewReference(value, canBeNull: true).StealNullable(),
                new NewReference(traceback, canBeNull: true).StealNullable());

            var err = FetchCurrentOrNull(out dispatchInfo);

            Runtime.PyErr_Restore(type.StealNullable(), value.StealNullable(), traceback.StealNullable());

            return(err);
        }
Esempio n. 4
0
        internal static PythonException?FetchCurrentOrNullRaw()
        {
            using var _ = new Py.GILState();

            Runtime.PyErr_Fetch(type: out var type, val: out var value, tb: out var traceback);

            if (type.IsNull())
            {
                Debug.Assert(value.IsNull());
                Debug.Assert(traceback.IsNull());
                return(null);
            }

            return(new PythonException(
                       type: new PyType(type.Steal()),
                       value: value.MoveToPyObjectOrNull(),
                       traceback: traceback.MoveToPyObjectOrNull()));
        }