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

Commitbec8b7d

Browse files
committed
fixed failure in ExceptionEncoded test case caused by ExceptionDispatchInfo masking exception object
1 parentd667998 commitbec8b7d

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

‎src/runtime/converter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ internal static bool ToManaged(IntPtr value, Type type,
293293
}
294294

295295

296+
internalstaticboolToManagedValue(BorrowedReferencevalue,TypeobType,outobjectresult,boolsetError)
297+
=>ToManagedValue(value.DangerousGetAddress(),obType,outresult,setError);
296298
internalstaticboolToManagedValue(IntPtrvalue,TypeobType,
297299
outobjectresult,boolsetError)
298300
{

‎src/runtime/exceptions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ public static void SetError(IntPtr ob, IntPtr value)
262262
Runtime.PyErr_SetObject(ob,value);
263263
}
264264

265+
internalconststringDispatchInfoAttribute="__dispatch_info__";
265266
/// <summary>
266267
/// SetError Method
267268
/// </summary>
@@ -288,8 +289,9 @@ public static void SetError(Exception e)
288289
IntPtretype=Runtime.PyObject_GetAttrString(op,"__class__");
289290
#ifNETSTANDARD
290291
varexceptionInfo=ExceptionDispatchInfo.Capture(e);
291-
Runtime.XDecref(op);
292-
op=Converter.ToPython(exceptionInfo);
292+
IntPtrpyInfo=Converter.ToPython(exceptionInfo);
293+
Runtime.PyObject_SetAttrString(op,DispatchInfoAttribute,pyInfo);
294+
Runtime.XDecref(pyInfo);
293295
#endif
294296

295297
Runtime.PyErr_SetObject(etype,op);

‎src/runtime/pythonexception.cs

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ internal static Exception ThrowLastAsClrException()
6969
Runtime.PyErr_Fetch(outvartype,outvarvalue,outvartraceback);
7070
try
7171
{
72-
varclrObject=ManagedType.GetManagedObject(value)asCLRObject;
7372
#ifNETSTANDARD
74-
if(clrObject?.instisExceptionDispatchInfostoredException)
73+
if(!value.IsNull())
7574
{
76-
storedException.Throw();
77-
throwstoredException.SourceException;// unreachable
75+
varexceptionInfo=TryGetDispatchInfo(value);
76+
if(exceptionInfo!=null)
77+
{
78+
exceptionInfo.Throw();
79+
throwexceptionInfo.SourceException;// unreachable
80+
}
7881
}
7982
#endif
83+
84+
varclrObject=ManagedType.GetManagedObject(value)asCLRObject;
8085
if(clrObject?.instisExceptione)
8186
{
8287
throwe;
@@ -98,6 +103,37 @@ internal static Exception ThrowLastAsClrException()
98103
}
99104
}
100105

106+
#ifNETSTANDARD
107+
staticExceptionDispatchInfoTryGetDispatchInfo(BorrowedReferenceexception)
108+
{
109+
if(exception.IsNull)returnnull;
110+
111+
varpyInfo=Runtime.PyObject_GetAttrString(exception,Exceptions.DispatchInfoAttribute);
112+
if(pyInfo.IsNull())
113+
{
114+
if(Exceptions.ExceptionMatches(Exceptions.AttributeError))
115+
{
116+
Exceptions.Clear();
117+
}
118+
returnnull;
119+
}
120+
121+
try
122+
{
123+
if(Converter.ToManagedValue(pyInfo,typeof(ExceptionDispatchInfo),outobjectresult,setError:false))
124+
{
125+
return(ExceptionDispatchInfo)result;
126+
}
127+
128+
returnnull;
129+
}
130+
finally
131+
{
132+
pyInfo.Dispose();
133+
}
134+
}
135+
#endif
136+
101137
/// <summary>
102138
/// Requires lock to be acquired elsewhere
103139
/// </summary>
@@ -106,19 +142,20 @@ static Exception FromPyErr(BorrowedReference typeHandle, BorrowedReference value
106142
Exceptioninner=null;
107143
stringpythonTypeName=null,msg="",tracebackText=null;
108144

109-
varclrObject=ManagedType.GetManagedObject(valueHandle)asCLRObject;
110-
if(clrObject?.instisExceptione)
111-
{
112-
returne;
113-
}
114-
115145
#ifNETSTANDARD
116-
if(clrObject?.instisExceptionDispatchInfoexceptionDispatchInfo)
146+
varexceptionDispatchInfo=TryGetDispatchInfo(valueHandle);
147+
if(exceptionDispatchInfo!=null)
117148
{
118149
returnexceptionDispatchInfo.SourceException;
119150
}
120151
#endif
121152

153+
varclrObject=ManagedType.GetManagedObject(valueHandle)asCLRObject;
154+
if(clrObject?.instisExceptione)
155+
{
156+
returne;
157+
}
158+
122159
vartype=PyObject.FromNullableReference(typeHandle);
123160
varvalue=PyObject.FromNullableReference(valueHandle);
124161
vartraceback=PyObject.FromNullableReference(tracebackHandle);

‎src/runtime/runtime.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,10 @@ internal static bool PyObject_IsIterable(IntPtr pointer)
937937
internalstaticexternintPyObject_HasAttrString(IntPtrpointer,stringname);
938938

939939
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
940+
[Obsolete("Use overload acceptingBorrowedReference")]
940941
internalstaticextern IntPtr PyObject_GetAttrString(IntPtr pointer,stringname);
942+
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
943+
internalstaticexternNewReference PyObject_GetAttrString(BorrowedReferencepointer,stringname);
941944

942945
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
943946
internalstaticexternintPyObject_SetAttrString(IntPtrpointer,stringname,IntPtrvalue);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp