GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `PyBuffer.GetPointer` throws exception for N-dimensional buffer · Issue #2743 · pythonnet/pythonnet

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

New issue
Copy link
New issue
Copy link
Closed
#2745
Closed
PyBuffer.GetPointer throws exception for N-dimensional buffer#2743
#2745
Copy link
Labels
bug

Description

@Yosh31207
Yosh31207
opened on Sep 26, 2026
Issue body actions

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

  1. filmor
    added
    bug
    on Sep 28, 2026
  2. filmor commented on Sep 28, 2026

    @filmor
    filmor
    on Sep 28, 2026
    Member
    More actions

    I can confirm that I also see crashes in this function, but the proposed fix (fixed and nint*) does not seem to be enough. Will check further.

    Reacted by Yosh31207
  3. filmor commented on Sep 28, 2026

    @filmor
    filmor
    on Sep 28, 2026
    Member
    More actions

    I can't find any useful docs on this, but the issue is PyBUF.ND:

    https://github.com/python/cpython/blob/9e9c3c49b4a41eebb982891c3ccdc17ae5ab9963/Objects/abstract.c#L544-L557

    PyObject_GetPointer accesses view->strides, so you must use at least PyBUF.STRIDES to access it. I will introduce an exception for this on PyBuffer.GetPointer.

  4. filmor
    closed this as completedin #2745on Sep 29, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.