Skip to content
Merged
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
fix: incorrect length for buffer copy
  • Loading branch information
legomanww committed Mar 11, 2023
commit 796f3632ace016671a2856ed2352027cf2f12bba
8 changes: 4 additions & 4 deletions src/runtime/PythonTypes/PyBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class PyBuffer : IDisposable
private PyObject _exporter;
private Py_buffer _view;

unsafe internal PyBuffer(PyObject exporter, PyBUF flags)
internal PyBuffer(PyObject exporter, PyBUF flags)
{
_view = new Py_buffer();

Expand All @@ -25,17 +25,17 @@ unsafe internal PyBuffer(PyObject exporter, PyBUF flags)
var intPtrBuf = new IntPtr[_view.ndim];
if (_view.shape != IntPtr.Zero)
{
Marshal.Copy(_view.shape, intPtrBuf, 0, (int)_view.len * sizeof(IntPtr));
Marshal.Copy(_view.shape, intPtrBuf, 0, _view.ndim);
Shape = intPtrBuf.Select(x => (long)x).ToArray();
}

if (_view.strides != IntPtr.Zero) {
Marshal.Copy(_view.strides, intPtrBuf, 0, (int)_view.len * sizeof(IntPtr));
Marshal.Copy(_view.strides, intPtrBuf, 0, _view.ndim);
Strides = intPtrBuf.Select(x => (long)x).ToArray();
}

if (_view.suboffsets != IntPtr.Zero) {
Marshal.Copy(_view.suboffsets, intPtrBuf, 0, (int)_view.len * sizeof(IntPtr));
Marshal.Copy(_view.suboffsets, intPtrBuf, 0, _view.ndim);
SubOffsets = intPtrBuf.Select(x => (long)x).ToArray();
}
}
Expand Down