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

Commit7a2b5e2

Browse files
committed
Simplify PyObj casting, logic of if blocks.
1 parent6d4dec7 commit7a2b5e2

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

‎src/embed_tests/TestOperator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public OperableObject(int num)
217217
using(Py.GIL())
218218
{
219219
// Assuming b is a tuple, take the first element.
220-
intbNum=(int)b.ToArray()[0].AsManagedObject(typeof(int));
220+
intbNum=b[0].As<int>();
221221
returna.Num>=bNum;
222222
}
223223
}
@@ -226,7 +226,7 @@ public OperableObject(int num)
226226
using(Py.GIL())
227227
{
228228
// Assuming b is a tuple, take the first element.
229-
intbNum=(int)b.ToArray()[0].AsManagedObject(typeof(int));
229+
intbNum=b[0].As<int>();
230230
returna.Num<=bNum;
231231
}
232232
}

‎src/runtime/classbase.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,10 @@ public static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op)
8989
// otherwise fallback to checking if an IComparable interface is handled.
9090
if(cls.richcompare.TryGetValue(op,outvarmethodObject))
9191
{
92-
IntPtrargs=other;
93-
varfree=false;
94-
if(true)
95-
{
96-
// Wrap the `other` argument of a binary comparison operator in a PyTuple.
97-
args=Runtime.PyTuple_New(1);
98-
Runtime.XIncref(other);
99-
Runtime.PyTuple_SetItem(args,0,other);
100-
free=true;
101-
}
92+
// Wrap the `other` argument of a binary comparison operator in a PyTuple.
93+
IntPtrargs=Runtime.PyTuple_New(1);
94+
Runtime.XIncref(other);
95+
Runtime.PyTuple_SetItem(args,0,other);
10296

10397
IntPtrvalue;
10498
try
@@ -107,10 +101,7 @@ public static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op)
107101
}
108102
finally
109103
{
110-
if(free)
111-
{
112-
Runtime.XDecref(args);// Free args pytuple
113-
}
104+
Runtime.XDecref(args);// Free args pytuple
114105
}
115106
returnvalue;
116107
}

‎src/runtime/operatormethod.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public static void FixupSlots(IntPtr pyType, Type clrType)
104104
Debug.Assert(_opType!=null);
105105
foreach(varmethodinclrType.GetMethods(flags))
106106
{
107-
// Wedon't want to override slots foreither non-operatorsor
107+
// Weonly want to override slots for operatorsexcluding
108108
// comparison operators, which are handled by ClassBase.tp_richcompare.
109-
if(!IsOperatorMethod(method)||IsComparisonOp(method))
109+
if(!OpMethodMap.ContainsKey(method.Name))
110110
{
111111
continue;
112112
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp