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

Commita95945b

Browse files
committed
fixed __cause__ on overload bind failure and array conversion
also: added debug check
1 parent0775458 commita95945b

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

‎src/runtime/converter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,14 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
814814

815815
privatestaticvoidSetConversionError(IntPtrvalue,Typetarget)
816816
{
817+
// PyObject_Repr might clear the error
818+
Runtime.PyErr_Fetch(outvarcauseType,outvarcauseVal,outvarcauseTrace);
819+
817820
IntPtrob=Runtime.PyObject_Repr(value);
818821
stringsrc=Runtime.GetManagedString(ob);
819822
Runtime.XDecref(ob);
823+
824+
Runtime.PyErr_Restore(causeType,causeVal,causeTrace);
820825
Exceptions.RaiseTypeError($"Cannot convert{src} to{target}");
821826
}
822827

‎src/runtime/finalizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class IncorrectRefCountException : Exception
5454
publicIncorrectRefCountException(IntPtrptr)
5555
{
5656
PyPtr=ptr;
57-
IntPtrpyname=Runtime.PyObject_Unicode(PyPtr);
57+
IntPtrpyname=Runtime.PyObject_Str(PyPtr);
5858
stringname=Runtime.GetManagedString(pyname);
5959
Runtime.XDecref(pyname);
6060
_message=$"<{name}> may has a incorrect ref count";

‎src/runtime/methodbinder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ protected static void AppendArgumentTypes(StringBuilder to, IntPtr args)
876876
{
877877
try
878878
{
879-
vardescription=Runtime.PyObject_Unicode(type);
879+
vardescription=Runtime.PyObject_Str(type);
880880
if(description!=IntPtr.Zero)
881881
{
882882
to.Append(Runtime.GetManagedString(description));
@@ -926,7 +926,9 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i
926926
}
927927

928928
value.Append(": ");
929+
Runtime.PyErr_Fetch(outvarerrType,outvarerrVal,outvarerrTrace);
929930
AppendArgumentTypes(to:value,args);
931+
Runtime.PyErr_Restore(errType,errVal,errTrace);
930932
Exceptions.RaiseTypeError(value.ToString());
931933
returnIntPtr.Zero;
932934
}

‎src/runtime/pyobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ public string Repr()
10401040
/// </remarks>
10411041
publicoverridestringToString()
10421042
{
1043-
IntPtrstrval=Runtime.PyObject_Unicode(obj);
1043+
IntPtrstrval=Runtime.PyObject_Str(obj);
10441044
stringresult=Runtime.GetManagedString(strval);
10451045
Runtime.XDecref(strval);
10461046
returnresult;

‎src/runtime/runtime.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
usingSystem.Reflection.Emit;
21
usingSystem;
2+
usingSystem.Diagnostics;
33
usingSystem.Diagnostics.Contracts;
44
usingSystem.Runtime.InteropServices;
5-
usingSystem.Security;
65
usingSystem.Text;
76
usingSystem.Threading;
87
usingSystem.Collections.Generic;
@@ -1127,13 +1126,18 @@ internal static int PyObject_Compare(IntPtr value1, IntPtr value2)
11271126
internalstaticnintPyObject_Hash(IntPtrop)=>Delegates.PyObject_Hash(op);
11281127

11291128

1130-
internalstaticIntPtrPyObject_Repr(IntPtrpointer)=>Delegates.PyObject_Repr(pointer);
1131-
1132-
1133-
internalstaticIntPtrPyObject_Str(IntPtrpointer)=>Delegates.PyObject_Str(pointer);
1129+
internalstaticIntPtrPyObject_Repr(IntPtrpointer)
1130+
{
1131+
Debug.Assert(PyErr_Occurred()==IntPtr.Zero);
1132+
returnDelegates.PyObject_Repr(pointer);
1133+
}
11341134

11351135

1136-
internalstaticIntPtrPyObject_Unicode(IntPtrpointer)=>Delegates.PyObject_Unicode(pointer);
1136+
internalstaticIntPtrPyObject_Str(IntPtrpointer)
1137+
{
1138+
Debug.Assert(PyErr_Occurred()==IntPtr.Zero);
1139+
returnDelegates.PyObject_Str(pointer);
1140+
}
11371141

11381142

11391143
internalstaticIntPtrPyObject_Dir(IntPtrpointer)=>Delegates.PyObject_Dir(pointer);
@@ -2322,7 +2326,6 @@ static Delegates()
23222326
PyObject_Hash=(delegate* unmanaged[Cdecl]<IntPtr,IntPtr>)GetFunctionByName(nameof(PyObject_Hash),GetUnmanagedDll(_PythonDll));
23232327
PyObject_Repr=(delegate* unmanaged[Cdecl]<IntPtr,IntPtr>)GetFunctionByName(nameof(PyObject_Repr),GetUnmanagedDll(_PythonDll));
23242328
PyObject_Str=(delegate* unmanaged[Cdecl]<IntPtr,IntPtr>)GetFunctionByName(nameof(PyObject_Str),GetUnmanagedDll(_PythonDll));
2325-
PyObject_Unicode=(delegate* unmanaged[Cdecl]<IntPtr,IntPtr>)GetFunctionByName("PyObject_Str",GetUnmanagedDll(_PythonDll));
23262329
PyObject_Dir=(delegate* unmanaged[Cdecl]<IntPtr,IntPtr>)GetFunctionByName(nameof(PyObject_Dir),GetUnmanagedDll(_PythonDll));
23272330
PyObject_GetBuffer=(delegate* unmanaged[Cdecl]<IntPtr,refPy_buffer,int,int>)GetFunctionByName(nameof(PyObject_GetBuffer),GetUnmanagedDll(_PythonDll));
23282331
PyBuffer_Release=(delegate* unmanaged[Cdecl]<refPy_buffer,void>)GetFunctionByName(nameof(PyBuffer_Release),GetUnmanagedDll(_PythonDll));
@@ -2607,7 +2610,6 @@ static Delegates()
26072610
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,IntPtr>PyObject_Hash{get;}
26082611
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,IntPtr>PyObject_Repr{get;}
26092612
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,IntPtr>PyObject_Str{get;}
2610-
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,IntPtr>PyObject_Unicode{get;}
26112613
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,IntPtr>PyObject_Dir{get;}
26122614
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,refPy_buffer,int,int>PyObject_GetBuffer{get;}
26132615
internalstaticdelegate* unmanaged[Cdecl]<refPy_buffer,void>PyBuffer_Release{get;}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp