| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,15 @@ | |||
| 1 | 1 | <Project> | |
| 2 | 2 | <PropertyGroup> | |
| 3 | 3 | <VersionPrefix>3.0.0</VersionPrefix> | |
| 4 | - <AssemblyCopyright>Copyright (c) 2006-2020 The Contributors of the Python.NET Project</AssemblyCopyright> | ||
| 4 | + <AssemblyCopyright>Copyright (c) 2006-2021 The Contributors of the Python.NET Project</AssemblyCopyright> | ||
| 5 | 5 | <AssemblyCompany>pythonnet</AssemblyCompany> | |
| 6 | 6 | <AssemblyProduct>Python.NET</AssemblyProduct> | |
| 7 | - <LangVersion>9.0</LangVersion> | ||
| 7 | + <LangVersion>10.0</LangVersion> | ||
| 8 | 8 | <IsPackable>false</IsPackable> | |
| 9 | 9 | </PropertyGroup> | |
| 10 | 10 | <ItemGroup> | |
| 11 | 11 | <PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> | |
| 12 | - <PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.9.0-3.final"> | ||
| 12 | + <PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.0.0-5.final"> | ||
| 13 | 13 | <PrivateAssets>all</PrivateAssets> | |
| 14 | 14 | <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | |
| 15 | 15 | </PackageReference> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,8 @@ public override bool Equals(object obj) { | |||
| 46 | 46 | return false; | |
| 47 | 47 | } | |
| 48 | 48 | ||
| 49 | + public static implicit operator BorrowedReference(PyObject pyObject) => pyObject.Reference; | ||
| 50 | + | ||
| 49 | 51 | public override int GetHashCode() => pointer.GetHashCode(); | |
| 50 | 52 | } | |
| 51 | 53 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,14 +18,12 @@ public NewReference(BorrowedReference reference, bool canBeNull = false) | |||
| 18 | 18 | var address = canBeNull | |
| 19 | 19 | ? reference.DangerousGetAddressOrNull() | |
| 20 | 20 | : reference.DangerousGetAddress(); | |
| 21 | - Runtime.XIncref(address); | ||
| 21 | + #pragma warning disable CS0618 // Type or member is obsolete | ||
| 22 | + Runtime.XIncref(reference); | ||
| 23 | + #pragma warning restore CS0618 // Type or member is obsolete | ||
| 22 | 24 | this.pointer = address; | |
| 23 | 25 | } | |
| 24 | 26 | ||
| 25 | - [Pure] | ||
| 26 | - public static implicit operator BorrowedReference(in NewReference reference) | ||
| 27 | - => new BorrowedReference(reference.pointer); | ||
| 28 | - | ||
| 29 | 27 | /// <summary> | |
| 30 | 28 | /// Returns <see cref="PyObject"/> wrapper around this reference, which now owns | |
| 31 | 29 | /// the pointer. Sets the original reference to <c>null</c>, as it no longer owns it. | |
@@ -62,6 +60,12 @@ public IntPtr DangerousMoveToPointerOrNull() | |||
| 62 | 60 | /// the pointer. Sets the original reference to <c>null</c>, as it no longer owns it. | |
| 63 | 61 | /// </summary> | |
| 64 | 62 | public PyObject MoveToPyObjectOrNull() => this.IsNull() ? null : this.MoveToPyObject(); | |
| 63 | + | ||
| 64 | + [Pure] | ||
| 65 | + public BorrowedReference BorrowNullable() => new(pointer); | ||
| 66 | + [Pure] | ||
| 67 | + public BorrowedReference Borrow() => this.IsNull() ? throw new NullReferenceException() : this.BorrowNullable(); | ||
| 68 | + | ||
| 65 | 69 | /// <summary> | |
| 66 | 70 | /// Call this method to move ownership of this reference to a Python C API function, | |
| 67 | 71 | /// that steals reference passed to it. | |
@@ -88,14 +92,14 @@ public StolenReference Steal() | |||
| 88 | 92 | /// <summary> | |
| 89 | 93 | /// Removes this reference to a Python object, and sets it to <c>null</c>. | |
| 90 | 94 | /// </summary> | |
| 95 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| 91 | 96 | public void Dispose() | |
| 92 | 97 | { | |
| 93 | 98 | if (this.IsNull()) | |
| 94 | 99 | { | |
| 95 | 100 | return; | |
| 96 | 101 | } | |
| 97 | - Runtime.XDecref(pointer); | ||
| 98 | - pointer = IntPtr.Zero; | ||
| 102 | + Runtime.XDecref(this.Steal()); | ||
| 99 | 103 | } | |
| 100 | 104 | ||
| 101 | 105 | /// <summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | <PropertyGroup> | |
| 3 | 3 | <TargetFrameworks>netstandard2.0</TargetFrameworks> | |
| 4 | 4 | <Platforms>AnyCPU</Platforms> | |
| 5 | - <LangVersion>9.0</LangVersion> | ||
| 5 | + <LangVersion>10.0</LangVersion> | ||
| 6 | 6 | <RootNamespace>Python.Runtime</RootNamespace> | |
| 7 | 7 | <AssemblyName>Python.Runtime</AssemblyName> | |
| 8 | 8 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,10 @@ | |||
| 1 | 1 | #nullable enable | |
| 2 | 2 | using System; | |
| 3 | 3 | using System.Collections.Generic; | |
| 4 | + using System.Diagnostics; | ||
| 5 | + using System.Diagnostics.Contracts; | ||
| 4 | 6 | using System.IO; | |
| 7 | + using System.Runtime.CompilerServices; | ||
| 5 | 8 | using System.Runtime.InteropServices; | |
| 6 | 9 | ||
| 7 | 10 | namespace Python.Runtime | |
@@ -18,6 +21,21 @@ internal static class Util | |||
| 18 | 21 | internal const string UseOverloadWithReferenceTypes = | |
| 19 | 22 | "This API is unsafe, and will be removed in the future. Use overloads working with *Reference types"; | |
| 20 | 23 | ||
| 24 | + | ||
| 25 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| 26 | + internal unsafe static T* ReadPtr<T>(BorrowedReference @ref, int offset) | ||
| 27 | + where T: unmanaged | ||
| 28 | + { | ||
| 29 | + IntPtr ptr = Marshal.ReadIntPtr(@ref.DangerousGetAddress(), offset); | ||
| 30 | + return (T*)ptr; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| 34 | + internal unsafe static IntPtr ReadIntPtr(BorrowedReference @ref, int offset) | ||
| 35 | + { | ||
| 36 | + return Marshal.ReadIntPtr(@ref.DangerousGetAddress(), offset); | ||
| 37 | + } | ||
| 38 | + | ||
| 21 | 39 | internal static Int64 ReadCLong(IntPtr tp, int offset) | |
| 22 | 40 | { | |
| 23 | 41 | // On Windows, a C long is always 32 bits. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,7 +47,7 @@ static Converter() | |||
| 47 | 47 | /// <summary> | |
| 48 | 48 | /// Given a builtin Python type, return the corresponding CLR type. | |
| 49 | 49 | /// </summary> | |
| 50 | - internal static Type? GetTypeByAlias(IntPtr op) | ||
| 50 | + internal static Type? GetTypeByAlias(BorrowedReference op) | ||
| 51 | 51 | { | |
| 52 | 52 | if (op == Runtime.PyStringType) | |
| 53 | 53 | return stringType; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ internal class MetaType : ManagedType | |||
| 23 | 23 | /// <summary> | |
| 24 | 24 | /// Metatype initialization. This bootstraps the CLR metatype to life. | |
| 25 | 25 | /// </summary> | |
| 26 | - public static IntPtr Initialize() | ||
| 26 | + public static PyObject Initialize() | ||
| 27 | 27 | { | |
| 28 | 28 | PyCLRMetaType = TypeManager.CreateMetaType(typeof(MetaType), out _metaSlotsHodler); | |
| 29 | 29 | return PyCLRMetaType; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + namespace Python.Runtime.Native; | ||
| 2 | + | ||
| 3 | + /// <summary>Catch-all type for native function objects (to be pointed to)</summary> | ||
| 4 | + struct NativeFunc | ||
| 5 | + { | ||
| 6 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Runtime.InteropServices; | ||
| 3 | + | ||
| 4 | + namespace Python.Runtime.Native; | ||
| 5 | + | ||
| 6 | + /// <remarks><c>PyGILState_STATE</c></remarks> | ||
| 7 | + [StructLayout(LayoutKind.Sequential)] | ||
| 8 | + struct PyGILState | ||
| 9 | + { | ||
| 10 | + IntPtr handle; | ||
| 11 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments