| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,13 +30,13 @@ public BorrowedReference(IntPtr pointer) | |||
| 30 | 30 | => a.pointer == b.pointer; | |
| 31 | 31 | public static bool operator !=(BorrowedReference a, BorrowedReference b) | |
| 32 | 32 | => a.pointer != b.pointer; | |
| 33 | - public static bool operator ==(BorrowedReference reference, NullOnly @null) | ||
| 33 | + public static bool operator ==(BorrowedReference reference, NullOnly? @null) | ||
| 34 | 34 | => reference.IsNull; | |
| 35 | - public static bool operator !=(BorrowedReference reference, NullOnly @null) | ||
| 35 | + public static bool operator !=(BorrowedReference reference, NullOnly? @null) | ||
| 36 | 36 | => !reference.IsNull; | |
| 37 | - public static bool operator ==(NullOnly @null, BorrowedReference reference) | ||
| 37 | + public static bool operator ==(NullOnly? @null, BorrowedReference reference) | ||
| 38 | 38 | => reference.IsNull; | |
| 39 | - public static bool operator !=(NullOnly @null, BorrowedReference reference) | ||
| 39 | + public static bool operator !=(NullOnly? @null, BorrowedReference reference) | ||
| 40 | 40 | => !reference.IsNull; | |
| 41 | 41 | ||
| 42 | 42 | public override bool Equals(object obj) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | <LangVersion>10.0</LangVersion> | |
| 6 | 6 | <RootNamespace>Python.Runtime</RootNamespace> | |
| 7 | 7 | <AssemblyName>Python.Runtime</AssemblyName> | |
| 8 | + <Nullable>enable</Nullable> | ||
| 8 | 9 | ||
| 9 | 10 | <PackageId>pythonnet</PackageId> | |
| 10 | 11 | <PackageLicenseFile>LICENSE</PackageLicenseFile> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - #nullable enable | ||
| 2 | 1 | using System.Collections.Generic; | |
| 3 | 2 | ||
| 4 | 3 | namespace Python.Runtime | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - #nullable enable | ||
| 2 | 1 | using System; | |
| 3 | 2 | using System.Collections.Generic; | |
| 4 | 3 | using System.Linq; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - #nullable enable | ||
| 2 | 1 | using System; | |
| 3 | 2 | using System.Collections.Generic; | |
| 4 | 3 | using System.Diagnostics; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - #nullable enable | ||
| 2 | 1 | using System; | |
| 3 | 2 | using System.Collections; | |
| 4 | 3 | using System.Collections.Generic; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,9 @@ | |||
| 1 | - #nullable enable | ||
| 2 | 1 | using System; | |
| 3 | 2 | using System.Collections; | |
| 4 | 3 | using System.Collections.Generic; | |
| 5 | 4 | using System.Diagnostics; | |
| 6 | 5 | using System.Linq; | |
| 7 | 6 | using System.Reflection; | |
| 8 | - using System.Runtime.InteropServices; | ||
| 9 | 7 | ||
| 10 | 8 | namespace Python.Runtime | |
| 11 | 9 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - #nullable enable | ||
| 2 | 1 | using System; | |
| 3 | 2 | using System.Collections.Generic; | |
| 4 | 3 | using System.ComponentModel; | |
@@ -56,7 +55,7 @@ internal ClassDerivedObject(Type tp) : base(tp) | |||
| 56 | 55 | var cls = (ClassDerivedObject)GetManagedObject(tp)!; | |
| 57 | 56 | ||
| 58 | 57 | // call the managed constructor | |
| 59 | - object obj = cls.binder.InvokeRaw(null, args, kw); | ||
| 58 | + object? obj = cls.binder.InvokeRaw(null, args, kw); | ||
| 60 | 59 | if (obj == null) | |
| 61 | 60 | { | |
| 62 | 61 | return default; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | - using System.Linq; | ||
| 2 | 1 | using System; | |
| 2 | + using System.Linq; | ||
| 3 | 3 | using System.Reflection; | |
| 4 | 4 | ||
| 5 | 5 | namespace Python.Runtime | |
@@ -43,16 +43,15 @@ internal NewReference GetDocString() | |||
| 43 | 43 | } | |
| 44 | 44 | str += t.ToString(); | |
| 45 | 45 | } | |
| 46 | - return NewReference.DangerousFromPointer(Runtime.PyString_FromString(str)); | ||
| 46 | + return Runtime.PyString_FromString(str); | ||
| 47 | 47 | } | |
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | 50 | /// <summary> | |
| 51 | 51 | /// Implements __new__ for reflected classes and value types. | |
| 52 | 52 | /// </summary> | |
| 53 | - public static IntPtr tp_new(IntPtr tpRaw, IntPtr args, IntPtr kw) | ||
| 53 | + public static NewReference tp_new(BorrowedReference tp, BorrowedReference args, BorrowedReference kw) | ||
| 54 | 54 | { | |
| 55 | - var tp = new BorrowedReference(tpRaw); | ||
| 56 | 55 | var self = GetManagedObject(tp) as ClassObject; | |
| 57 | 56 | ||
| 58 | 57 | // Sanity check: this ensures a graceful error if someone does | |
@@ -77,32 +76,32 @@ public static IntPtr tp_new(IntPtr tpRaw, IntPtr args, IntPtr kw) | |||
| 77 | 76 | if (Runtime.PyTuple_Size(args) != 1) | |
| 78 | 77 | { | |
| 79 | 78 | Exceptions.SetError(Exceptions.TypeError, "no constructors match given arguments"); | |
| 80 | - return IntPtr.Zero; | ||
| 79 | + return default; | ||
| 81 | 80 | } | |
| 82 | 81 | ||
| 83 | - IntPtr op = Runtime.PyTuple_GetItem(args, 0); | ||
| 82 | + BorrowedReference op = Runtime.PyTuple_GetItem(args, 0); | ||
| 84 | 83 | object result; | |
| 85 | 84 | ||
| 86 | 85 | if (!Converter.ToManaged(op, type, out result, true)) | |
| 87 | 86 | { | |
| 88 | - return IntPtr.Zero; | ||
| 87 | + return default; | ||
| 89 | 88 | } | |
| 90 | 89 | ||
| 91 | - return CLRObject.GetReference(result, tp).DangerousMoveToPointerOrNull(); | ||
| 90 | + return CLRObject.GetReference(result, tp); | ||
| 92 | 91 | } | |
| 93 | 92 | ||
| 94 | 93 | if (type.IsAbstract) | |
| 95 | 94 | { | |
| 96 | 95 | Exceptions.SetError(Exceptions.TypeError, "cannot instantiate abstract class"); | |
| 97 | - return IntPtr.Zero; | ||
| 96 | + return default; | ||
| 98 | 97 | } | |
| 99 | 98 | ||
| 100 | 99 | if (type.IsEnum) | |
| 101 | 100 | { | |
| 102 | - return NewEnum(type, new BorrowedReference(args), tp).DangerousMoveToPointerOrNull(); | ||
| 101 | + return NewEnum(type, args, tp); | ||
| 103 | 102 | } | |
| 104 | 103 | ||
| 105 | - object obj = self.binder.InvokeRaw(IntPtr.Zero, args, kw); | ||
| 104 | + object obj = self.binder.InvokeRaw(null, args, kw); | ||
| 106 | 105 | if (obj == null) | |
| 107 | 106 | { | |
| 108 | 107 | return IntPtr.Zero; | |
@@ -154,7 +153,7 @@ private static NewReference NewEnum(Type type, BorrowedReference args, BorrowedR | |||
| 154 | 153 | /// both to implement the Array[int] syntax for creating arrays and | |
| 155 | 154 | /// to support generic name overload resolution using []. | |
| 156 | 155 | /// </summary> | |
| 157 | - public override IntPtr type_subscript(IntPtr idx) | ||
| 156 | + public override NewReference type_subscript(BorrowedReference idx) | ||
| 158 | 157 | { | |
| 159 | 158 | if (!type.Valid) | |
| 160 | 159 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,7 @@ internal ConstructorBinder(Type containingType) | |||
| 29 | 29 | /// object - the reason is that only the caller knows the correct | |
| 30 | 30 | /// Python type to use when wrapping the result (may be a subclass). | |
| 31 | 31 | /// </summary> | |
| 32 | - internal object InvokeRaw(BorrowedReference inst, BorrowedReference args, BorrowedReference kw) | ||
| 32 | + internal object? InvokeRaw(BorrowedReference inst, BorrowedReference args, BorrowedReference kw) | ||
| 33 | 33 | { | |
| 34 | 34 | return InvokeRaw(inst, args, kw, null); | |
| 35 | 35 | } | |
@@ -49,7 +49,7 @@ internal object InvokeRaw(BorrowedReference inst, BorrowedReference args, Borrow | |||
| 49 | 49 | /// Binding binding = this.Bind(inst, args, kw, info); | |
| 50 | 50 | /// to take advantage of Bind()'s ability to use a single MethodBase (CI or MI). | |
| 51 | 51 | /// </remarks> | |
| 52 | - internal object InvokeRaw(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, MethodBase info) | ||
| 52 | + internal object? InvokeRaw(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, MethodBase? info) | ||
| 53 | 53 | { | |
| 54 | 54 | if (!_containingType.Valid) | |
| 55 | 55 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments