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

Commit9c6d882

Browse files
committed
got rid of a few deprecation warnings that pollute GitHub code review
1 parent43d1640 commit9c6d882

File tree

9 files changed

+23
-15
lines changed

9 files changed

+23
-15
lines changed

‎src/embed_tests/TestConverter.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void PyIntImplicit()
148148
{
149149
vari=newPyInt(1);
150150
varni=(PyObject)i.As<object>();
151-
Assert.AreEqual(i.rawPtr,ni.rawPtr);
151+
Assert.IsTrue(PythonReferenceComparer.Instance.Equals(i,ni));
152152
}
153153

154154
[Test]
@@ -178,8 +178,11 @@ public void RawPyObjectProxy()
178178
varclrObject=(CLRObject)ManagedType.GetManagedObject(pyObjectProxy);
179179
Assert.AreSame(pyObject,clrObject.inst);
180180

181-
varproxiedHandle=pyObjectProxy.GetAttr("Handle").As<IntPtr>();
182-
Assert.AreEqual(pyObject.Handle,proxiedHandle);
181+
#pragma warning disableCS0612// Type or member is obsolete
182+
conststringhandlePropertyName=nameof(PyObject.Handle);
183+
#pragma warning restoreCS0612// Type or member is obsolete
184+
varproxiedHandle=pyObjectProxy.GetAttr(handlePropertyName).As<IntPtr>();
185+
Assert.AreEqual(pyObject.DangerousGetAddressOrNull(),proxiedHandle);
183186
}
184187

185188
// regression for https://github.com/pythonnet/pythonnet/issues/451

‎src/embed_tests/TestDomainReload.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ from Python.EmbeddingTest.Domain import MyClass
9999
{
100100
Debug.Assert(obj.AsManagedObject(type).GetType()==type);
101101
// We only needs its Python handle
102-
PyRuntime.XIncref(obj);
103-
returnobj.Handle;
102+
returnnewNewReference(obj).DangerousMoveToPointer();
104103
}
105104
}
106105
}

‎src/embed_tests/TestFinalizer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ 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+
#pragma warning disableCS0618// Type or member is obsolete
215216
Runtime.Runtime.XIncref(e.Reference);
217+
#pragma warning restoreCS0618// Type or member is obsolete
216218
returnfalse;
217219
};
218220
Finalizer.Instance.IncorrectRefCntResolver+=handler;
@@ -234,8 +236,9 @@ private static IntPtr CreateStringGarbage()
234236
{
235237
PyStrings1=newPyString("test_string");
236238
// s2 steal a reference from s1
237-
PyStrings2=newPyString(StolenReference.DangerousFromPointer(s1.Handle));
238-
returns1.Handle;
239+
IntPtraddress=s1.Reference.DangerousGetAddress();
240+
PyStrings2=new(StolenReference.DangerousFromPointer(address));
241+
returnaddress;
239242
}
240243
}
241244
}

‎src/embed_tests/TestNativeTypeOffset.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public void LoadNativeTypeOffsetClass()
3333
{
3434
PyObjectsys=Py.Import("sys");
3535
// We can safely ignore the "m" abi flag
36-
varabiflags=sys.GetAttr("abiflags","".ToPython()).ToString().Replace("m","");
36+
varabiflags=sys.HasAttr("abiflags")?sys.GetAttr("abiflags").ToString():"";
37+
abiflags=abiflags.Replace("m","");
3738
if(!string.IsNullOrEmpty(abiflags))
3839
{
3940
stringtypeName="Python.Runtime.NativeTypeOffset, Python.Runtime";

‎src/embed_tests/TestPythonException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def __init__(self, val):
161161
usingvartbObj=tbPtr.MoveToPyObject();
162162
// the type returned from PyErr_NormalizeException should not be the same type since a new
163163
// exception was raised by initializing the exception
164-
Assert.AreNotEqual(type.Handle,typeObj.Handle);
164+
Assert.IsFalse(PythonReferenceComparer.Instance.Equals(type,typeObj));
165165
// the message should now be the string from the throw exception during normalization
166166
Assert.AreEqual("invalid literal for int() with base 10: 'dummy string'",strObj.ToString());
167167
}

‎src/runtime/InternString.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void Initialize()
4242
Debug.Assert(name==op.As<string>());
4343
SetIntern(name,op);
4444
varfield=type.GetField("f"+name,PyIdentifierFieldFlags)!;
45-
field.SetValue(null,op.rawPtr);
45+
field.SetValue(null,op.DangerousGetAddressOrNull());
4646
}
4747
}
4848

@@ -76,7 +76,7 @@ public static bool TryGetInterned(BorrowedReference op, out string s)
7676
privatestaticvoidSetIntern(strings,PyStringop)
7777
{
7878
_string2interns.Add(s,op);
79-
_intern2strings.Add(op.rawPtr,s);
79+
_intern2strings.Add(op.Reference.DangerousGetAddress(),s);
8080
}
8181
}
8282
}

‎src/runtime/PythonTypes/PyObject.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class PyObject : DynamicObject, IDisposable, ISerializable
2727
publicStackTraceTraceback{get;}=newStackTrace(1);
2828
#endif
2929

30-
protectedinternalIntPtrrawPtr=IntPtr.Zero;
30+
protectedIntPtrrawPtr=IntPtr.Zero;
3131
internalreadonlyintrun=Runtime.GetRun();
3232

3333
internalBorrowedReferenceobj=>new(rawPtr);
@@ -252,6 +252,8 @@ internal void Leak()
252252
rawPtr=IntPtr.Zero;
253253
}
254254

255+
internalIntPtrDangerousGetAddressOrNull()=>rawPtr;
256+
255257
internalvoidCheckRun()
256258
{
257259
if(run!=Runtime.GetRun())

‎src/runtime/Types/ReflectedClrType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ static ReflectedClrType AllocateClass(Type clrType)
117117
returnnewReflectedClrType(type.Steal());
118118
}
119119

120-
publicoverrideboolEquals(PyObject?other)=>other!=null&&rawPtr==other.rawPtr;
120+
publicoverrideboolEquals(PyObject?other)=>rawPtr==other?.DangerousGetAddressOrNull();
121121
publicoverrideintGetHashCode()=>rawPtr.GetHashCode();
122122
}

‎src/runtime/Util/PythonReferenceComparer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public sealed class PythonReferenceComparer : IEqualityComparer<PyObject>
1313
publicstaticPythonReferenceComparerInstance{get;}=newPythonReferenceComparer();
1414
publicboolEquals(PyObject?x,PyObject?y)
1515
{
16-
returnx?.rawPtr==y?.rawPtr;
16+
returnx?.DangerousGetAddressOrNull()==y?.DangerousGetAddressOrNull();
1717
}
1818

19-
publicintGetHashCode(PyObjectobj)=>obj.rawPtr.GetHashCode();
19+
publicintGetHashCode(PyObjectobj)=>obj.DangerousGetAddressOrNull().GetHashCode();
2020

2121
privatePythonReferenceComparer(){}
2222
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp