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

Commit676fbb4

Browse files
committed
PyObject.Length raises an exception when object does not have a concept of length
1 parent6f10641 commit676fbb4

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ when .NET expects an integer [#1342][i1342]
3636
- BREAKING: Methods with`ref` or`out` parameters and void return type return a tuple of only the`ref` and`out` parameters.
3737
- BREAKING: to call Python from .NET`Runtime.PythonDLL` property must be set to Python DLL name
3838
or the DLL must be loaded in advance. This must be done before calling any other Python.NET functions.
39+
- BREAKING:`PyObject.Length()` now raises a`PythonException` when object does not support a concept of length.
3940
- Sign Runtime DLL with a strong name
4041
- Implement loading through`clr_loader` instead of the included`ClrModule`, enables
4142
support for .NET Core

‎src/runtime/pyobject.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -615,19 +615,15 @@ public virtual void DelItem(int index)
615615

616616

617617
/// <summary>
618-
/// Length Method
619-
/// </summary>
620-
/// <remarks>
621618
/// Returns the length for objects that support the Python sequence
622-
/// protocol, or 0 if the object does not support the protocol.
623-
/// </remarks>
619+
/// protocol.
620+
/// </summary>
624621
publicvirtuallongLength()
625622
{
626-
vars=Runtime.PyObject_Size(obj);
623+
vars=Runtime.PyObject_Size(Reference);
627624
if(s<0)
628625
{
629-
Runtime.PyErr_Clear();
630-
return0;
626+
thrownewPythonException();
631627
}
632628
returns;
633629
}

‎src/runtime/runtime.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,13 +1115,7 @@ internal static int PyObject_Compare(IntPtr value1, IntPtr value2)
11151115

11161116
internalstaticintPyObject_Not(IntPtrpointer)=>Delegates.PyObject_Not(pointer);
11171117

1118-
internalstaticlongPyObject_Size(IntPtrpointer)
1119-
{
1120-
return(long)_PyObject_Size(pointer);
1121-
}
1122-
1123-
1124-
privatestaticIntPtr_PyObject_Size(IntPtrpointer)=>Delegates._PyObject_Size(pointer);
1118+
internalstaticnintPyObject_Size(BorrowedReferencepointer)=>Delegates.PyObject_Size(pointer);
11251119

11261120

11271121
internalstaticnintPyObject_Hash(IntPtrop)=>Delegates.PyObject_Hash(op);
@@ -2317,7 +2311,7 @@ static Delegates()
23172311
PyCallable_Check=(delegate* unmanaged[Cdecl]<IntPtr,int>)GetFunctionByName(nameof(PyCallable_Check),GetUnmanagedDll(_PythonDll));
23182312
PyObject_IsTrue=(delegate* unmanaged[Cdecl]<BorrowedReference,int>)GetFunctionByName(nameof(PyObject_IsTrue),GetUnmanagedDll(_PythonDll));
23192313
PyObject_Not=(delegate* unmanaged[Cdecl]<IntPtr,int>)GetFunctionByName(nameof(PyObject_Not),GetUnmanagedDll(_PythonDll));
2320-
_PyObject_Size=(delegate* unmanaged[Cdecl]<IntPtr,IntPtr>)GetFunctionByName("PyObject_Size",GetUnmanagedDll(_PythonDll));
2314+
PyObject_Size=(delegate* unmanaged[Cdecl]<BorrowedReference,nint>)GetFunctionByName("PyObject_Size",GetUnmanagedDll(_PythonDll));
23212315
PyObject_Hash=(delegate* unmanaged[Cdecl]<IntPtr,IntPtr>)GetFunctionByName(nameof(PyObject_Hash),GetUnmanagedDll(_PythonDll));
23222316
PyObject_Repr=(delegate* unmanaged[Cdecl]<IntPtr,IntPtr>)GetFunctionByName(nameof(PyObject_Repr),GetUnmanagedDll(_PythonDll));
23232317
PyObject_Str=(delegate* unmanaged[Cdecl]<IntPtr,IntPtr>)GetFunctionByName(nameof(PyObject_Str),GetUnmanagedDll(_PythonDll));
@@ -2589,7 +2583,7 @@ static Delegates()
25892583
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,int>PyCallable_Check{get;}
25902584
internalstaticdelegate* unmanaged[Cdecl]<BorrowedReference,int>PyObject_IsTrue{get;}
25912585
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,int>PyObject_Not{get;}
2592-
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,IntPtr>_PyObject_Size{get;}
2586+
internalstaticdelegate* unmanaged[Cdecl]<BorrowedReference,nint>PyObject_Size{get;}
25932587
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,IntPtr>PyObject_Hash{get;}
25942588
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,IntPtr>PyObject_Repr{get;}
25952589
internalstaticdelegate* unmanaged[Cdecl]<IntPtr,IntPtr>PyObject_Str{get;}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp