Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Prevent crash during debugging when attempting to inspect PyObject#1483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lostmsu merged 2 commits intopythonnet:masterfromlosttech:Mini/DebugViewNoCrash
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletionssrc/runtime/Util.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@ internal static class Util
{
internal const string UnstableApiMessage =
"This API is unstable, and might be changed or removed in the next minor release";
internal const string MinimalPythonVersionRequired =
"Only Python 3.5 or newer is supported";

internal static Int64 ReadCLong(IntPtr tp, int offset)
{
Expand Down
1 change: 1 addition & 0 deletionssrc/runtime/clrobject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
namespace Python.Runtime
{
[Serializable]
[DebuggerDisplay("clrO: {inst}")]
internal class CLRObject : ManagedType
{
internal object inst;
Expand Down
8 changes: 8 additions & 0 deletionssrc/runtime/debughelper.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,5 +144,13 @@ public static void AssertHasReferences(IntPtr obj)
long refcount = Runtime.Refcount(obj);
Debug.Assert(refcount > 0, "Object refcount is 0 or less");
}

[Conditional("DEBUG")]
public static void EnsureGIL()
{
Debug.Assert(HaveInterpreterLock(), "GIL must be acquired");
}

public static bool HaveInterpreterLock() => Runtime.PyGILState_Check() == 1;
}
}
5 changes: 5 additions & 0 deletionssrc/runtime/pyobject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ namespace Python.Runtime
/// for details.
/// </summary>
[Serializable]
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public partial class PyObject : DynamicObject, IEnumerable<PyObject>, IDisposable
{
#if TRACE_ALLOC
Expand DownExpand Up@@ -1069,6 +1070,10 @@ public override string ToString()
return result;
}

string DebuggerDisplay => DebugUtil.HaveInterpreterLock()
? this.ToString()
: $"pyobj at 0x{this.obj:X} (get Py.GIL to see more info)";


/// <summary>
/// Equals Method
Expand Down
11 changes: 10 additions & 1 deletionsrc/runtime/runtime.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -832,7 +832,7 @@ internal static unsafe long Refcount(IntPtr op)

internal static IntPtr PyThreadState_Swap(IntPtr key) => Delegates.PyThreadState_Swap(key);


internal static int PyGILState_Check() => Delegates.PyGILState_Check();
internal static IntPtr PyGILState_Ensure() => Delegates.PyGILState_Ensure();


Expand DownExpand Up@@ -2302,6 +2302,14 @@ static Delegates()
PyThread_get_thread_ident = (delegate* unmanaged[Cdecl]<int>)GetFunctionByName(nameof(PyThread_get_thread_ident), GetUnmanagedDll(_PythonDll));
PyThread_set_key_value = (delegate* unmanaged[Cdecl]<IntPtr, IntPtr, int>)GetFunctionByName(nameof(PyThread_set_key_value), GetUnmanagedDll(_PythonDll));
PyThreadState_Swap = (delegate* unmanaged[Cdecl]<IntPtr, IntPtr>)GetFunctionByName(nameof(PyThreadState_Swap), GetUnmanagedDll(_PythonDll));
try
{
PyGILState_Check = (delegate* unmanaged[Cdecl]<int>)GetFunctionByName(nameof(PyGILState_Check), GetUnmanagedDll(_PythonDll));
}
catch (MissingMethodException e)
{
throw new NotSupportedException(Util.MinimalPythonVersionRequired, innerException: e);
}
PyGILState_Ensure = (delegate* unmanaged[Cdecl]<IntPtr>)GetFunctionByName(nameof(PyGILState_Ensure), GetUnmanagedDll(_PythonDll));
PyGILState_Release = (delegate* unmanaged[Cdecl]<IntPtr, void>)GetFunctionByName(nameof(PyGILState_Release), GetUnmanagedDll(_PythonDll));
PyGILState_GetThisThreadState = (delegate* unmanaged[Cdecl]<IntPtr>)GetFunctionByName(nameof(PyGILState_GetThisThreadState), GetUnmanagedDll(_PythonDll));
Expand DownExpand Up@@ -2605,6 +2613,7 @@ static Delegates()
internal static delegate* unmanaged[Cdecl]<int> PyThread_get_thread_ident { get; }
internal static delegate* unmanaged[Cdecl]<IntPtr, IntPtr, int> PyThread_set_key_value { get; }
internal static delegate* unmanaged[Cdecl]<IntPtr, IntPtr> PyThreadState_Swap { get; }
internal static delegate* unmanaged[Cdecl]<int> PyGILState_Check { get; }
internal static delegate* unmanaged[Cdecl]<IntPtr> PyGILState_Ensure { get; }
internal static delegate* unmanaged[Cdecl]<IntPtr, void> PyGILState_Release { get; }
internal static delegate* unmanaged[Cdecl]<IntPtr> PyGILState_GetThisThreadState { get; }
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp