Skip to content

Commit 62e193a

Browse files
committed
fixed bad equality comparisons
1 parent 4346d41 commit 62e193a

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

src/embed_tests/TestCustomMarshal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void GetManagedStringTwice()
2727
string s1 = Runtime.Runtime.GetManagedString(op.BorrowOrThrow());
2828
string s2 = Runtime.Runtime.GetManagedString(op.Borrow());
2929

30-
Assert.AreEqual(1, Runtime.Runtime.Refcount(op.Borrow()));
30+
Assert.AreEqual(1, Runtime.Runtime.Refcount32(op.Borrow()));
3131
Assert.AreEqual(expected, s1);
3232
Assert.AreEqual(expected, s2);
3333
}

src/embed_tests/TestPyObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void GetAttrDefault_IgnoresAttributeErrorOnly()
9292
var typeErrResult = Assert.Throws<PythonException>(
9393
() => ob.GetAttr(nameof(PyObjectTestMethods.RaisesTypeError), fallback)
9494
);
95-
Assert.AreEqual(Exceptions.TypeError, typeErrResult.Type.Handle);
95+
Assert.AreEqual(Exceptions.TypeError, typeErrResult.Type);
9696
}
9797
}
9898

src/embed_tests/TestPySequence.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public void TestIndex()
8787
{
8888
var t1 = new PyString("FooBar");
8989

90-
Assert.AreEqual(4, t1.Index(new PyString("a")));
91-
Assert.AreEqual(5, t1.Index(new PyString("r")));
92-
Assert.AreEqual(-1, t1.Index(new PyString("z")));
90+
Assert.AreEqual(4, t1.Index32(new PyString("a")));
91+
Assert.AreEqual(5L, t1.Index64(new PyString("r")));
92+
Assert.AreEqual(-(nint)1, t1.Index(new PyString("z")));
9393
}
9494
}
9595
}

src/embed_tests/TestRuntime.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,26 @@ public static void RefCountTest()
3939
using var op = Runtime.Runtime.PyString_FromString("FooBar");
4040

4141
// New object RefCount should be one
42-
Assert.AreEqual(1, Runtime.Runtime.Refcount(op.BorrowOrThrow()));
42+
Assert.AreEqual(1, Runtime.Runtime.Refcount32(op.BorrowOrThrow()));
4343

4444
// Checking refcount didn't change refcount
45-
Assert.AreEqual(1, Runtime.Runtime.Refcount(op.Borrow()));
45+
Assert.AreEqual(1, Runtime.Runtime.Refcount32(op.Borrow()));
4646

4747
// Borrowing a reference doesn't increase refcount
4848
BorrowedReference p = op.Borrow();
49-
Assert.AreEqual(1, Runtime.Runtime.Refcount(p));
49+
Assert.AreEqual(1, Runtime.Runtime.Refcount32(p));
5050

5151
// Py_IncRef/Py_DecRef increase and decrease RefCount
5252
Runtime.Runtime.Py_IncRef(op.Borrow());
53-
Assert.AreEqual(2, Runtime.Runtime.Refcount(p));
53+
Assert.AreEqual(2, Runtime.Runtime.Refcount32(p));
5454
Runtime.Runtime.Py_DecRef(StolenReference.DangerousFromPointer(op.DangerousGetAddress()));
55-
Assert.AreEqual(1, Runtime.Runtime.Refcount(p));
55+
Assert.AreEqual(1, Runtime.Runtime.Refcount32(p));
5656

5757
// XIncref/XDecref increase and decrease RefCount
5858
Runtime.Runtime.XIncref(p);
59-
Assert.AreEqual(2, Runtime.Runtime.Refcount(p));
59+
Assert.AreEqual(2, Runtime.Runtime.Refcount32(p));
6060
Runtime.Runtime.XDecref(p);
61-
Assert.AreEqual(1, Runtime.Runtime.Refcount(p));
61+
Assert.AreEqual(1, Runtime.Runtime.Refcount32(p));
6262

6363
op.Dispose();
6464

src/runtime/Codecs/TupleCodecs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public bool CanEncode(Type type)
4242
}
4343

4444
public bool CanDecode(PyType objectType, Type targetType)
45-
=> objectType == Runtime.PyTupleType && this.CanEncode(targetType);
45+
=> PythonReferenceComparer.Instance.Equals(objectType, Runtime.PyTupleType)
46+
&& this.CanEncode(targetType);
4647

4748
public bool TryDecode<T>(PyObject pyObj, out T? value)
4849
{

src/runtime/runtime.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ internal static unsafe nint Refcount(BorrowedReference op)
732732
var p = (nint*)(op.DangerousGetAddress() + ABI.RefCountOffset);
733733
return *p;
734734
}
735+
[Pure]
736+
internal static int Refcount32(BorrowedReference op) => checked((int)Refcount(op));
735737

736738
/// <summary>
737739
/// Call specified function, and handle PythonDLL-related failures.

0 commit comments

Comments
 (0)