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

Commitc3fc7f0

Browse files
committed
allow comparing BorrowedReference to null
1 parentc4f2ad7 commitc3fc7f0

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

‎src/runtime/BorrowedReference.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public BorrowedReference(IntPtr pointer)
2828
=>a.pointer==b.pointer;
2929
publicstaticbooloperator!=(BorrowedReferencea,BorrowedReferenceb)
3030
=>a.pointer!=b.pointer;
31+
publicstaticbooloperator==(BorrowedReferencereference,NullOnly@null)
32+
=>reference.IsNull;
33+
publicstaticbooloperator!=(BorrowedReferencereference,NullOnly@null)
34+
=>!reference.IsNull;
35+
publicstaticbooloperator==(NullOnly@null,BorrowedReferencereference)
36+
=>reference.IsNull;
37+
publicstaticbooloperator!=(NullOnly@null,BorrowedReferencereference)
38+
=>!reference.IsNull;
3139

3240
publicoverrideboolEquals(objectobj){
3341
if(objisIntPtrptr)

‎src/runtime/importhook.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static unsafe NewReference GetCLRModule(BorrowedReference fromList = defa
155155

156156
// find any items from the from list and get them from the root if they're not
157157
// already in the module dictionary
158-
if(fromList!=null&&fromList!=default)
158+
if(fromList!=null)
159159
{
160160
if(Runtime.PyTuple_Check(fromList))
161161
{
@@ -224,7 +224,7 @@ public static IntPtr __import__(IntPtr self, IntPtr argsRaw, IntPtr kw)
224224
if(num_args>=4)
225225
{
226226
fromList=Runtime.PyTuple_GetItem(args,3);
227-
if(fromList!=default&&
227+
if(fromList!=null&&
228228
Runtime.PyObject_IsTrue(fromList)==1)
229229
{
230230
fromlist=true;
@@ -297,7 +297,7 @@ public static IntPtr __import__(IntPtr self, IntPtr argsRaw, IntPtr kw)
297297
BorrowedReferencemodules=Runtime.PyImport_GetModuleDict();
298298
BorrowedReferencemodule=Runtime.PyDict_GetItem(modules,py_mod_name);
299299

300-
if(module!=default)
300+
if(module!=null)
301301
{
302302
if(fromlist)
303303
{

‎src/runtime/tricks/NullOnly.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespacePython.Runtime
2+
{
3+
/// <summary>
4+
/// An utility class, that can only have one value: <c>null</c>.
5+
/// <para>Useful for overloading operators on structs,
6+
/// that have meaningful concept of <c>null</c> value (e.g. pointers and references).</para>
7+
/// </summary>
8+
classNullOnly
9+
{
10+
privateNullOnly(){}
11+
}
12+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp