Skip to content

Commit 8754ed1

Browse files
authored
Merge pull request #1603 from losttech/precise-API-references
Use new references; redesign ManagedType to not hold Python references
2 parents a0e8cb3 + 3794fea commit 8754ed1

File tree

132 files changed

+4315
-5120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+4315
-5120
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ One must now either use enum members (e.g. `MyEnum.Option`), or use enum constru
6565
- BREAKING: Names of .NET types (e.g. `str(__class__)`) changed to better support generic types
6666
- BREAKING: overload resolution will no longer prefer basic types. Instead, first matching overload will
6767
be chosen.
68+
- BREAKING: `Exec` and `Eval` from `PythonEngine` no longer accept raw pointers.
6869
- BREAKING: .NET collections and arrays are no longer automatically converted to
6970
Python collections. Instead, they implement standard Python
7071
collection interfaces from `collections.abc`.
@@ -74,6 +75,7 @@ be of type `PyInt` instead of `System.Int32` due to possible loss of information
7475
Python `float` will continue to be converted to `System.Double`.
7576
- BREAKING: Python.NET will no longer implicitly convert types like `numpy.float64`, that implement `__float__` to
7677
`System.Single` and `System.Double`. An explicit conversion is required on Python or .NET side.
78+
- BREAKING: `PyObject.GetHashCode` can fail.
7779
- BREAKING: Python.NET will no longer implicitly convert any Python object to `System.Boolean`.
7880
- BREAKING: `PyObject.GetAttr(name, default)` now only ignores `AttributeError` (previously ignored all exceptions).
7981
- BREAKING: `PyObject` no longer implements `IEnumerable<PyObject>`.

pythonnet.sln

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Global
5454
Release|Any CPU = Release|Any CPU
5555
Release|x64 = Release|x64
5656
Release|x86 = Release|x86
57+
TraceAlloc|Any CPU = TraceAlloc|Any CPU
58+
TraceAlloc|x64 = TraceAlloc|x64
59+
TraceAlloc|x86 = TraceAlloc|x86
5760
EndGlobalSection
5861
GlobalSection(ProjectConfigurationPlatforms) = postSolution
5962
{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -68,6 +71,12 @@ Global
6871
{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}.Release|x64.Build.0 = Release|Any CPU
6972
{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}.Release|x86.ActiveCfg = Release|Any CPU
7073
{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}.Release|x86.Build.0 = Release|Any CPU
74+
{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}.TraceAlloc|Any CPU.ActiveCfg = TraceAlloc|Any CPU
75+
{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}.TraceAlloc|Any CPU.Build.0 = TraceAlloc|Any CPU
76+
{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}.TraceAlloc|x64.ActiveCfg = Debug|Any CPU
77+
{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}.TraceAlloc|x64.Build.0 = Debug|Any CPU
78+
{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}.TraceAlloc|x86.ActiveCfg = Debug|Any CPU
79+
{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}.TraceAlloc|x86.Build.0 = Debug|Any CPU
7180
{E6B01706-00BA-4144-9029-186AC42FBE9A}.Debug|Any CPU.ActiveCfg = Debug|x64
7281
{E6B01706-00BA-4144-9029-186AC42FBE9A}.Debug|Any CPU.Build.0 = Debug|x64
7382
{E6B01706-00BA-4144-9029-186AC42FBE9A}.Debug|x64.ActiveCfg = Debug|x64
@@ -80,6 +89,12 @@ Global
8089
{E6B01706-00BA-4144-9029-186AC42FBE9A}.Release|x64.Build.0 = Release|x64
8190
{E6B01706-00BA-4144-9029-186AC42FBE9A}.Release|x86.ActiveCfg = Release|x86
8291
{E6B01706-00BA-4144-9029-186AC42FBE9A}.Release|x86.Build.0 = Release|x86
92+
{E6B01706-00BA-4144-9029-186AC42FBE9A}.TraceAlloc|Any CPU.ActiveCfg = Debug|x64
93+
{E6B01706-00BA-4144-9029-186AC42FBE9A}.TraceAlloc|Any CPU.Build.0 = Debug|x64
94+
{E6B01706-00BA-4144-9029-186AC42FBE9A}.TraceAlloc|x64.ActiveCfg = Debug|x64
95+
{E6B01706-00BA-4144-9029-186AC42FBE9A}.TraceAlloc|x64.Build.0 = Debug|x64
96+
{E6B01706-00BA-4144-9029-186AC42FBE9A}.TraceAlloc|x86.ActiveCfg = Debug|x86
97+
{E6B01706-00BA-4144-9029-186AC42FBE9A}.TraceAlloc|x86.Build.0 = Debug|x86
8398
{819E089B-4770-400E-93C6-4F7A35F0EA12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
8499
{819E089B-4770-400E-93C6-4F7A35F0EA12}.Debug|Any CPU.Build.0 = Debug|Any CPU
85100
{819E089B-4770-400E-93C6-4F7A35F0EA12}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -92,6 +107,12 @@ Global
92107
{819E089B-4770-400E-93C6-4F7A35F0EA12}.Release|x64.Build.0 = Release|Any CPU
93108
{819E089B-4770-400E-93C6-4F7A35F0EA12}.Release|x86.ActiveCfg = Release|Any CPU
94109
{819E089B-4770-400E-93C6-4F7A35F0EA12}.Release|x86.Build.0 = Release|Any CPU
110+
{819E089B-4770-400E-93C6-4F7A35F0EA12}.TraceAlloc|Any CPU.ActiveCfg = Debug|Any CPU
111+
{819E089B-4770-400E-93C6-4F7A35F0EA12}.TraceAlloc|Any CPU.Build.0 = Debug|Any CPU
112+
{819E089B-4770-400E-93C6-4F7A35F0EA12}.TraceAlloc|x64.ActiveCfg = Debug|Any CPU
113+
{819E089B-4770-400E-93C6-4F7A35F0EA12}.TraceAlloc|x64.Build.0 = Debug|Any CPU
114+
{819E089B-4770-400E-93C6-4F7A35F0EA12}.TraceAlloc|x86.ActiveCfg = Debug|Any CPU
115+
{819E089B-4770-400E-93C6-4F7A35F0EA12}.TraceAlloc|x86.Build.0 = Debug|Any CPU
95116
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
96117
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.Debug|Any CPU.Build.0 = Debug|Any CPU
97118
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -104,6 +125,12 @@ Global
104125
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.Release|x64.Build.0 = Release|Any CPU
105126
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.Release|x86.ActiveCfg = Release|Any CPU
106127
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.Release|x86.Build.0 = Release|Any CPU
128+
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.TraceAlloc|Any CPU.ActiveCfg = Debug|Any CPU
129+
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.TraceAlloc|Any CPU.Build.0 = Debug|Any CPU
130+
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.TraceAlloc|x64.ActiveCfg = Debug|Any CPU
131+
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.TraceAlloc|x64.Build.0 = Debug|Any CPU
132+
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.TraceAlloc|x86.ActiveCfg = Debug|Any CPU
133+
{14EF9518-5BB7-4F83-8686-015BD2CC788E}.TraceAlloc|x86.Build.0 = Debug|Any CPU
107134
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.Debug|Any CPU.ActiveCfg = Debug|x64
108135
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.Debug|Any CPU.Build.0 = Debug|x64
109136
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.Debug|x64.ActiveCfg = Debug|x64
@@ -116,6 +143,12 @@ Global
116143
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.Release|x64.Build.0 = Release|x64
117144
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.Release|x86.ActiveCfg = Release|x86
118145
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.Release|x86.Build.0 = Release|x86
146+
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.TraceAlloc|Any CPU.ActiveCfg = Debug|x64
147+
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.TraceAlloc|Any CPU.Build.0 = Debug|x64
148+
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.TraceAlloc|x64.ActiveCfg = Debug|x64
149+
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.TraceAlloc|x64.Build.0 = Debug|x64
150+
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.TraceAlloc|x86.ActiveCfg = Debug|x86
151+
{4F2EA4A1-7ECA-48B5-8077-7A3C366F9931}.TraceAlloc|x86.Build.0 = Debug|x86
119152
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
120153
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
121154
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -128,6 +161,12 @@ Global
128161
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.Release|x64.Build.0 = Release|Any CPU
129162
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.Release|x86.ActiveCfg = Release|Any CPU
130163
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.Release|x86.Build.0 = Release|Any CPU
164+
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.TraceAlloc|Any CPU.ActiveCfg = Debug|Any CPU
165+
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.TraceAlloc|Any CPU.Build.0 = Debug|Any CPU
166+
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.TraceAlloc|x64.ActiveCfg = Debug|Any CPU
167+
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.TraceAlloc|x64.Build.0 = Debug|Any CPU
168+
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.TraceAlloc|x86.ActiveCfg = Debug|Any CPU
169+
{F2FB6DA3-318E-4F30-9A1F-932C667E38C5}.TraceAlloc|x86.Build.0 = Debug|Any CPU
131170
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
132171
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.Debug|Any CPU.Build.0 = Debug|Any CPU
133172
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -140,6 +179,12 @@ Global
140179
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.Release|x64.Build.0 = Release|Any CPU
141180
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.Release|x86.ActiveCfg = Release|Any CPU
142181
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.Release|x86.Build.0 = Release|Any CPU
182+
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.TraceAlloc|Any CPU.ActiveCfg = Debug|Any CPU
183+
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.TraceAlloc|Any CPU.Build.0 = Debug|Any CPU
184+
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.TraceAlloc|x64.ActiveCfg = Debug|Any CPU
185+
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.TraceAlloc|x64.Build.0 = Debug|Any CPU
186+
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.TraceAlloc|x86.ActiveCfg = Debug|Any CPU
187+
{35CBBDEB-FC07-4D04-9D3E-F88FC180110B}.TraceAlloc|x86.Build.0 = Debug|Any CPU
143188
EndGlobalSection
144189
GlobalSection(SolutionProperties) = preSolution
145190
HideSolutionNode = FALSE

src/embed_tests/CallableObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void SetUp()
1414
{
1515
PythonEngine.Initialize();
1616
using var locals = new PyDict();
17-
PythonEngine.Exec(CallViaInheritance.BaseClassSource, locals: locals.Handle);
17+
PythonEngine.Exec(CallViaInheritance.BaseClassSource, locals: locals);
1818
CustomBaseTypeProvider.BaseClass = new PyType(locals[CallViaInheritance.BaseClassName]);
1919
PythonEngine.InteropConfiguration.PythonBaseTypeProviders.Add(new CustomBaseTypeProvider());
2020
}

src/embed_tests/CodecGroups.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public void Encodes()
4949
};
5050

5151
var uri = group.TryEncode(new Uri("data:"));
52-
var clrObject = (CLRObject)ManagedType.GetManagedObject(uri.Handle);
52+
var clrObject = (CLRObject)ManagedType.GetManagedObject(uri);
5353
Assert.AreSame(encoder1, clrObject.inst);
5454
Assert.AreNotSame(encoder2, clrObject.inst);
5555

5656
var tuple = group.TryEncode(Tuple.Create(1));
57-
clrObject = (CLRObject)ManagedType.GetManagedObject(tuple.Handle);
57+
clrObject = (CLRObject)ManagedType.GetManagedObject(tuple);
5858
Assert.AreSame(encoder0, clrObject.inst);
5959
}
6060

src/embed_tests/Inheritance.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class Inheritance
1313
public void SetUp()
1414
{
1515
PythonEngine.Initialize();
16-
var locals = new PyDict();
17-
PythonEngine.Exec(InheritanceTestBaseClassWrapper.ClassSourceCode, locals: locals.Handle);
16+
using var locals = new PyDict();
17+
PythonEngine.Exec(InheritanceTestBaseClassWrapper.ClassSourceCode, locals: locals);
1818
ExtraBaseTypeProvider.ExtraBase = new PyType(locals[InheritanceTestBaseClassWrapper.ClassName]);
1919
var baseTypeProviders = PythonEngine.InteropConfiguration.PythonBaseTypeProviders;
2020
baseTypeProviders.Add(new ExtraBaseTypeProvider());
@@ -172,7 +172,7 @@ public int XProp
172172
{
173173
return scope.Eval<int>($"super(this.__class__, this).{nameof(XProp)}");
174174
}
175-
catch (PythonException ex) when (ex.Type.Handle == Exceptions.AttributeError)
175+
catch (PythonException ex) when (PythonReferenceComparer.Instance.Equals(ex.Type, Exceptions.AttributeError))
176176
{
177177
if (this.extras.TryGetValue(nameof(this.XProp), out object value))
178178
return (int)value;

src/embed_tests/References.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,9 @@ public void MoveToPyObject_SetsNull()
3939
public void CanBorrowFromNewReference()
4040
{
4141
var dict = new PyDict();
42-
NewReference reference = Runtime.PyDict_Items(dict.Reference);
43-
try
44-
{
45-
PythonException.ThrowIfIsNotZero(Runtime.PyList_Reverse(reference));
46-
}
47-
finally
48-
{
49-
reference.Dispose();
50-
}
42+
using NewReference reference = Runtime.PyDict_Items(dict.Reference);
43+
BorrowedReference borrowed = reference.BorrowOrThrow();
44+
PythonException.ThrowIfIsNotZero(Runtime.PyList_Reverse(borrowed));
5145
}
5246
}
5347
}

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/TestCustomMarshal.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public static void GetManagedStringTwice()
2323
{
2424
const string expected = "FooBar";
2525

26-
IntPtr op = Runtime.Runtime.PyString_FromString(expected);
27-
string s1 = Runtime.Runtime.GetManagedString(op);
28-
string s2 = Runtime.Runtime.GetManagedString(op);
26+
using var op = Runtime.Runtime.PyString_FromString(expected);
27+
string s1 = Runtime.Runtime.GetManagedString(op.BorrowOrThrow());
28+
string s2 = Runtime.Runtime.GetManagedString(op.Borrow());
2929

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

src/embed_tests/TestDomainReload.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ from Python.EmbeddingTest.Domain import MyClass
107107
{
108108
Debug.Assert(obj.AsManagedObject(type).GetType() == type);
109109
// We only needs its Python handle
110-
PyRuntime.XIncref(obj.Handle);
110+
PyRuntime.XIncref(obj);
111111
return obj.Handle;
112112
}
113113
}
@@ -127,16 +127,16 @@ public override ValueType Execute(ValueType arg)
127127
{
128128
// handle refering a clr object created in previous domain,
129129
// it should had been deserialized and became callable agian.
130-
IntPtr handle = (IntPtr)arg;
130+
using var handle = NewReference.DangerousFromPointer((IntPtr)arg);
131131
try
132132
{
133133
using (Py.GIL())
134134
{
135-
IntPtr tp = Runtime.Runtime.PyObject_TYPE(handle);
136-
IntPtr tp_clear = Marshal.ReadIntPtr(tp, TypeOffset.tp_clear);
135+
BorrowedReference tp = Runtime.Runtime.PyObject_TYPE(handle.Borrow());
136+
IntPtr tp_clear = Util.ReadIntPtr(tp, TypeOffset.tp_clear);
137137
Assert.That(tp_clear, Is.Not.Null);
138138

139-
using (PyObject obj = new PyObject(handle))
139+
using (PyObject obj = new PyObject(handle.Steal()))
140140
{
141141
obj.InvokeMethod("Method");
142142
obj.InvokeMethod("StaticMethod");

src/embed_tests/TestFinalizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void ValidateRefCount()
212212
Assert.AreEqual(ptr, e.Handle);
213213
Assert.AreEqual(2, e.ImpactedObjects.Count);
214214
// Fix for this test, don't do this on general environment
215-
Runtime.Runtime.XIncref(e.Handle);
215+
Runtime.Runtime.XIncref(e.Reference);
216216
return false;
217217
};
218218
Finalizer.Instance.IncorrectRefCntResolver += handler;

src/embed_tests/TestNamedArguments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def Test3(self, a1 = 1, a2 = 1, a3 = 1, a4 = 1):
5555
return a1 + a2 + a3 + a4
5656
5757
a = cmTest3()
58-
", null, locals.Handle);
58+
", null, locals);
5959

6060
return locals.GetItem("a");
6161
}

src/embed_tests/TestPyInt.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public void TestCtorSByte()
8686
public void TestCtorPyObject()
8787
{
8888
var i = new PyInt(5);
89-
Runtime.Runtime.XIncref(i.Handle);
9089
var a = new PyInt(i);
9190
Assert.AreEqual(5, a.ToInt32());
9291
}

src/embed_tests/TestPyObject.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def add(self, x, y):
4646
return x + y
4747
4848
a = MemberNamesTest()
49-
", null, locals.Handle);
49+
", null, locals);
5050

5151
PyObject a = locals.GetItem("a");
5252

@@ -92,13 +92,13 @@ 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

9999
public class PyObjectTestMethods
100100
{
101-
public string RaisesAttributeError => throw new PythonException(new PyType(new BorrowedReference(Exceptions.AttributeError)), value: null, traceback: null);
102-
public string RaisesTypeError => throw new PythonException(new PyType(new BorrowedReference(Exceptions.TypeError)), value: null, traceback: null);
101+
public string RaisesAttributeError => throw new PythonException(new PyType(Exceptions.AttributeError), value: null, traceback: null);
102+
public string RaisesTypeError => throw new PythonException(new PyType(Exceptions.TypeError), value: null, traceback: null);
103103
}
104104
}

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
}

0 commit comments

Comments
 (0)