Skip to content

Conversation

lostmsu
Copy link
Member

@lostmsu lostmsu commented Apr 13, 2021

What does this implement/fix? Explain your changes.

Calls to PyObject_Str and PyObject_Repr should not be made with error set, as they may clear it. When using debug build of Python, this causes an assertion at runtime, preventing use of Python.NET.

Does this close any currently open issues?

Partial fix for #1412

@filmor
Copy link
Member

filmor commented Apr 13, 2021

As there are probably a few more places like this, shouldn't we add a convenience IDisposable that does the fetching in startup and restores on Dispose?

@lostmsu
Copy link
Member Author

lostmsu commented Apr 13, 2021

@filmor I do not think it is justified at this moment: with just these two places I don't get any more related assertion failures of that nature with debug builds of Python throughout out test suite.

@@ -926,7 +926,9 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i
}

value.Append(": ");
Runtime.PyErr_Fetch(out var errType, out var errVal, out var errTrace);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might also be a fix for #1371

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might let us reenable the test case, but the issue that caused it will still be there.

Copy link
Contributor

@BadSingleton BadSingleton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. However this is something easy to miss. It'd be great if we had pythonnet in debug (without Py_Debug) be able to detect known cases.

@lostmsu lostmsu force-pushed the PR/PythonDebugBuild branch from 650ac77 to a95945b Compare April 14, 2021 00:33
@lostmsu lostmsu merged commit 16f04e9 into pythonnet:master Apr 14, 2021
@lostmsu lostmsu deleted the PR/PythonDebugBuild branch April 14, 2021 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants