Visitar URL original
`PyBuffer.GetPointer` throws exception for N-dimensional buffer · Issue #2743 · pythonnet/pythonnet · GitHub
Skip to content

PyBuffer.GetPointer throws exception for N-dimensional buffer #2743

Description

@Yosh31207

PyBuffer.GetPointer throws System.ExecutionEngineException when called with an N-dimensional array obtained with PyBUF.ND flag.

dynamic np = Py.Import("numpy");

// create 3D NumPy array
int[] shape = [10, 10, 10];
PyObject ndArray = np.zeros(shape);

PyBuffer buf = ndArray.GetBuffer(PyBUF.ND);

// this throws System.ExecutionEngineException
nint ptr = buf.GetPointer([0, 0, 0]);

I suspect that this may be caused by a mismatch of a type. The following code seems to pass a CLR array to native function pointer.

// src/runtime/Runtime.Delegates.cs

PyBuffer_GetPointer = (delegate* unmanaged[Cdecl]<ref Py_buffer, nint[], IntPtr>)GetFunctionByName(nameof(PyBuffer_GetPointer), GetUnmanagedDll(_PythonDll));

The second argument should be nint* obtained by fixed statement, isn't it?

My environment:

  • OS: Windows 11
  • Python: 3.14
  • Python.NET: 3.1.0
  • .NET 10
  • Visual Studio 2026

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions