Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use System.Version
  • Loading branch information
koubaa committed Aug 2, 2020
commit d2011972a267cc10d3f42c61da9a83e81ce3799b
8 changes: 4 additions & 4 deletions src/runtime/pybuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static char OrderStyleToChar(BufferOrderStyle order, bool eitherOneValid
/// </summary>
public static long SizeFromFormat(string format)
{
if (Runtime.pyversionnumber < 39)
if (Runtime.PyVersion.Minor < 9)
throw new NotSupportedException("SizeFromFormat requires at least Python 3.9");
return (long)Runtime.PyBuffer_SizeFromFormat(format);
}
Expand All @@ -111,7 +111,7 @@ public IntPtr GetPointer(long[] indices)
{
if (disposedValue)
throw new ObjectDisposedException(nameof(PyBuffer));
if (Runtime.pyversionnumber < 37)
if (Runtime.PyVersion.Minor < 7)
throw new NotSupportedException("GetPointer requires at least Python 3.7");
return Runtime.PyBuffer_GetPointer(ref _view, indices.Select(x => (IntPtr)x).ToArray());
}
Expand All @@ -123,7 +123,7 @@ public void FromContiguous(IntPtr buf, long len, BufferOrderStyle fort)
{
if (disposedValue)
throw new ObjectDisposedException(nameof(PyBuffer));
if (Runtime.pyversionnumber < 37)
if (Runtime.PyVersion.Minor < 7)
throw new NotSupportedException("FromContiguous requires at least Python 3.7");

if (Runtime.PyBuffer_FromContiguous(ref _view, buf, (IntPtr)len, OrderStyleToChar(fort, false)) < 0)
Expand All @@ -139,7 +139,7 @@ public void ToContiguous(IntPtr buf, BufferOrderStyle order)
{
if (disposedValue)
throw new ObjectDisposedException(nameof(PyBuffer));
if (Runtime.pyversionnumber < 36)
if (Runtime.PyVersion.Minor < 6)
throw new NotSupportedException("ToContiguous requires at least Python 3.6");

if (Runtime.PyBuffer_ToContiguous(buf, ref _view, _view.len, OrderStyleToChar(order, true)) < 0)
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,15 @@ public class Runtime

private static PyReferenceCollection _pyRefs = new PyReferenceCollection();

internal static int pyversionnumber
internal static Version PyVersion
{
get
{
var versionTuple = new PyTuple(PySys_GetObject("version_info"));
var major = versionTuple[0].As<int>();
var minor = versionTuple[1].As<int>();
return major * 10 + minor;
var micro = versionTuple[2].As<int>();
return new Version(major, minor, micro);
}
}

Expand Down