Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e295679

Browse files
committed
switched to new references in some tests
1 parent bb84c48 commit e295679

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

src/embed_tests/TestConverter.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void TestConvertSingleToManaged(
4242
var pyFloat = new PyFloat(testValue);
4343

4444
object convertedValue;
45-
var converted = Converter.ToManaged(pyFloat.Handle, typeof(float), out convertedValue, false);
45+
var converted = Converter.ToManaged(pyFloat, typeof(float), out convertedValue, false);
4646

4747
Assert.IsTrue(converted);
4848
Assert.IsTrue(((float) convertedValue).Equals(testValue));
@@ -56,7 +56,7 @@ public void TestConvertDoubleToManaged(
5656
var pyFloat = new PyFloat(testValue);
5757

5858
object convertedValue;
59-
var converted = Converter.ToManaged(pyFloat.Handle, typeof(double), out convertedValue, false);
59+
var converted = Converter.ToManaged(pyFloat, typeof(double), out convertedValue, false);
6060

6161
Assert.IsTrue(converted);
6262
Assert.IsTrue(((double) convertedValue).Equals(testValue));
@@ -77,7 +77,7 @@ public void CovertTypeError()
7777
object value;
7878
try
7979
{
80-
bool res = Converter.ToManaged(s.Handle, type, out value, true);
80+
bool res = Converter.ToManaged(s, type, out value, true);
8181
Assert.IsFalse(res);
8282
var bo = Exceptions.ExceptionMatches(Exceptions.TypeError);
8383
Assert.IsTrue(Exceptions.ExceptionMatches(Exceptions.TypeError)
@@ -96,13 +96,13 @@ public void ConvertOverflow()
9696
{
9797
using (var num = new PyInt(ulong.MaxValue))
9898
{
99-
IntPtr largeNum = PyRuntime.PyNumber_Add(num.Handle, num.Handle);
99+
using var largeNum = PyRuntime.PyNumber_Add(num, num);
100100
try
101101
{
102102
object value;
103103
foreach (var type in _numTypes)
104104
{
105-
bool res = Converter.ToManaged(largeNum, type, out value, true);
105+
bool res = Converter.ToManaged(largeNum.BorrowOrThrow(), type, out value, true);
106106
Assert.IsFalse(res);
107107
Assert.IsTrue(Exceptions.ExceptionMatches(Exceptions.OverflowError));
108108
Exceptions.Clear();
@@ -111,7 +111,6 @@ public void ConvertOverflow()
111111
finally
112112
{
113113
Exceptions.Clear();
114-
PyRuntime.XDecref(largeNum);
115114
}
116115
}
117116
}
@@ -147,7 +146,7 @@ public void RawListProxy()
147146
{
148147
var list = new List<string> {"hello", "world"};
149148
var listProxy = PyObject.FromManagedObject(list);
150-
var clrObject = (CLRObject)ManagedType.GetManagedObject(listProxy.Handle);
149+
var clrObject = (CLRObject)ManagedType.GetManagedObject(listProxy);
151150
Assert.AreSame(list, clrObject.inst);
152151
}
153152

@@ -156,7 +155,7 @@ public void RawPyObjectProxy()
156155
{
157156
var pyObject = "hello world!".ToPython();
158157
var pyObjectProxy = PyObject.FromManagedObject(pyObject);
159-
var clrObject = (CLRObject)ManagedType.GetManagedObject(pyObjectProxy.Handle);
158+
var clrObject = (CLRObject)ManagedType.GetManagedObject(pyObjectProxy);
160159
Assert.AreSame(pyObject, clrObject.inst);
161160

162161
var proxiedHandle = pyObjectProxy.GetAttr("Handle").As<IntPtr>();

src/embed_tests/pyimport.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ public void SetUp()
3232
string testPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "fixtures");
3333
TestContext.Out.WriteLine(testPath);
3434

35-
IntPtr str = Runtime.Runtime.PyString_FromString(testPath);
36-
Assert.IsFalse(str == IntPtr.Zero);
35+
using var str = Runtime.Runtime.PyString_FromString(testPath);
36+
Assert.IsFalse(str.IsNull());
3737
BorrowedReference path = Runtime.Runtime.PySys_GetObject("path");
3838
Assert.IsFalse(path.IsNull);
39-
Runtime.Runtime.PyList_Append(path, new BorrowedReference(str));
40-
Runtime.Runtime.XDecref(str);
39+
Runtime.Runtime.PyList_Append(path, str.Borrow());
4140
}
4241

4342
[OneTimeTearDown]

0 commit comments

Comments
 (0)