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

Commita21a388

Browse files
committed
added debug information for failures to create a derived type
1 parent44a36dc commita21a388

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

‎src/runtime/NewReference.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ public IntPtr DangerousMoveToPointerOrNull()
3636
returnresult;
3737
}
3838

39+
/// <summary>
40+
/// Moves ownership of this reference to a Python C API function,
41+
/// that steals reference passed to it.
42+
/// </summary>
43+
publicStolenReferenceSteal()
44+
{
45+
if(this.IsNull())thrownewNullReferenceException();
46+
47+
returnthis.StealOrNull();
48+
}
49+
/// <summary>
50+
/// Moves ownership of this reference to a Python C API function,
51+
/// that steals reference passed to it.
52+
/// </summary>
53+
publicStolenReferenceStealOrNull()
54+
{
55+
IntPtrrawPointer=this.pointer;
56+
this.pointer=IntPtr.Zero;
57+
returnnewStolenReference(rawPointer);
58+
}
59+
3960
/// <summary>
4061
/// Removes this reference to a Python object, and sets it to <c>null</c>.
4162
/// </summary>

‎src/runtime/StolenReference.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespacePython.Runtime
2+
{
3+
usingSystem;
4+
5+
/// <summary>
6+
/// Should only be used for the arguments of Python C API functions, that steal references
7+
/// </summary>
8+
[NonCopyable]
9+
readonlyrefstructStolenReference
10+
{
11+
readonlyIntPtrpointer;
12+
13+
internalStolenReference(IntPtrpointer)
14+
{
15+
this.pointer=pointer;
16+
}
17+
}
18+
}

‎src/runtime/exceptions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
usingSystem;
2+
usingSystem.Diagnostics;
23
usingSystem.Reflection;
34
usingSystem.Runtime.InteropServices;
45

@@ -374,6 +375,18 @@ internal static IntPtr RaiseTypeError(string message)
374375
returnIntPtr.Zero;
375376
}
376377

378+
internalstaticIntPtrSetCause(Exceptioncause){
379+
Runtime.PyErr_Fetch(outNewReferenceob,outNewReferenceval,outNewReferencetb);
380+
Debug.Assert(!ob.IsNull()||!val.IsNull());
381+
Runtime.PyErr_NormalizeException(refob,refval,reftb);
382+
383+
varcausePyObj=NewReference.DangerousFromPointer(Converter.ToPython(cause));
384+
Runtime.PyException_SetCause(ob,causePyObj.Steal());
385+
386+
Runtime.PyErr_Restore(ob.Steal(),val.StealOrNull(),tb.StealOrNull());
387+
returnIntPtr.Zero;
388+
}
389+
377390
// 2010-11-16: Arranged in python (2.6 & 2.7) source header file order
378391
/* Predefined exceptions are
379392
puplic static variables on the Exceptions class filled in from

‎src/runtime/runtime.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,23 +2034,32 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)
20342034
internalstaticexternint PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val);
20352035

20362036
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
2037-
internalstaticexternvoid PyErr_NormalizeException(IntPtrob,IntPtrval,IntPtr tb);
2037+
internalstaticexternvoid PyErr_NormalizeException(ref NewReferenceob,ref NewReferenceval,ref NewReference tb);
20382038

20392039
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
20402040
internalstaticextern IntPtr PyErr_Occurred();
20412041

20422042
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
20432043
internalstaticexternvoid PyErr_Fetch(out IntPtr ob,out IntPtr val,out IntPtr tb);
2044+
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
2045+
internalstaticexternvoid PyErr_Fetch(out NewReference ob,out NewReference val,out NewReference tb);
20442046

20452047
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
20462048
internalstaticexternvoid PyErr_Restore(IntPtr ob, IntPtr val, IntPtr tb);
2049+
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
2050+
internalstaticexternvoid PyErr_Restore(StolenReference ob, StolenReference val, StolenReference tb);
20472051

20482052
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
20492053
internalstaticexternvoid PyErr_Clear();
20502054

20512055
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
20522056
internalstaticexternvoid PyErr_Print();
20532057

2058+
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
2059+
internalstaticexternvoid PyException_SetCause(BorrowedReference ex, StolenReference cause);
2060+
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
2061+
internalstaticexternint PyException_SetTraceback(BorrowedReference ex, BorrowedReference cause);
2062+
20542063
//====================================================================
20552064
// Cell API
20562065
//====================================================================

‎src/runtime/typemanager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr
384384
}
385385
catch(Exceptione)
386386
{
387-
returnExceptions.RaiseTypeError(e.Message);
387+
Exceptions.RaiseTypeError("unable to create derived type");
388+
Exceptions.SetCause(e);
389+
returnIntPtr.Zero;
388390
}
389391
}
390392

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp