FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add test for `PyBuffer.GetPointer` · pythonnet/pythonnet@bec4ced · GitHub

Repository navigation

Commit bec4ced

Browse files
committed
Add test for PyBuffer.GetPointer
1 parent 72df9ae commit bec4ced

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎src/embed_tests/TestPyBuffer.cs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,22 @@ public void TestBufferRead()
5858
}
5959

6060
string result = new UTF8Encoding().GetString(managedArray);
61-
Assert.That(result == " " + bufferTestString.Substring(1), Is.True);
61+
Assert.That(result, Is.EqualTo($" {bufferTestString.Substring(1)}"));
62+
}
63+
64+
[Test]
65+
public void GetPointer()
66+
{
67+
// create 3D NumPy array
68+
int[] shape = [10, 10, 10];
69+
using PyObject ndArray = np.zeros(shape);
70+
71+
using PyBuffer buf = ndArray.GetBuffer(PyBUF.STRIDES);
72+
73+
// this throws System.ExecutionEngineException
74+
var ptr = buf.GetPointer([0, 0, 0]);
75+
76+
Assert.That(ptr, Is.Not.EqualTo(IntPtr.Zero));
6277
}
6378

6479
[Test]

‎src/runtime/Runtime.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,12 @@ internal static nint PyBuffer_SizeFromFormat(string format)
10181018

10191019

10201020
internal static IntPtr PyBuffer_GetPointer(ref Py_buffer view, nint[] indices) => Delegates.PyBuffer_GetPointer(ref view, indices);
1021+
// {
1022+
// fixed (nint* indicesPtr = indices)
1023+
// {
1024+
// return Delegates.PyBuffer_GetPointer(ref view, indicesPtr);
1025+
// }
1026+
// }
10211027

10221028

10231029
internal static int PyBuffer_FromContiguous(ref Py_buffer view, IntPtr buf, IntPtr len, char fort) => Delegates.PyBuffer_FromContiguous(ref view, buf, len, fort);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL