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 — Introduce `mpl` buffer functions to replace `def_buffer()` by iccir · Pull Request #32576 · matplotlib/matplotlib

Conversation

@iccir

@iccir iccir commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

PR summary

Important

This PR depends on #32532 and will appear larger than it really is until #32532 is merged. To view the actual changes in this PR, compare pybind-mplarray-initial → pybind-mplbuffer.

This PR replaces our use of pybind11's buffer_protocol() and def_buffer() with our own functions. This is needed as nanobind does not provide a buffer protocol.

For now, these functions will live in "py_buffer.h". In a future PR, there will be a variant that uses nanobind API and lives in some variant of: "mplutils.h", "mpl_buffer.h", or "mplbuffer.h". Both variants can exist as we adopt nanobind.

Usage

Replace py::buffer_protocol() with py::custom_type_setup(mpl::buffer_setup<TheClass>).

The wrapped class needs to implement a create_buffer_info() function which returns a new mpl::buffer_info:

// FT2Image::create_buffer_info
auto *create_buffer_info() const
{
    using BufferInfo = mpl::buffer_info<uint8_t, mpl::shape<-1, -1>>;
    return new BufferInfo(m_buffer, m_height, m_width);
}

Use set_owner() on the BufferInfo if another PyObject owns the raw buffer:

// FT2Font::create_buffer_info
auto *create_buffer_info() const
{
    using BufferInfo = mpl::buffer_info<uint8_t, mpl::shape<-1, -1>>;
    auto result = new BufferInfo(image.data(), image.shape(0), image.shape(1));
    result->set_owner(image.pyarray().ptr());
    return result;
}

AI Disclosure

  • I use AI for web search due to search engines becoming less reliable.
  • I used AI to review py_buffer.h

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [/] Plotting related features are demonstrated in an example
  • [/] New features and API changes have release notes
  • [/] Documentation complies with general and docstring guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
iccir added 5 commits October 23, 2026 08:11
@iccir
Introduce mpl::defer and mpl::array. Use in qhull.
c82b28b
@iccir
Add more methods to mpl::array
5a547d8
@iccir
Merge branch 'main' of https://github.com/matplotlib/matplotlib into …
2d61980
…pybind-mplarray-initial
@iccir
Remove mpl::array_view, iterator support, new naming convention
a806d36
@iccir
Introduce mpl::buffer_info and buffer functions
d2a6838
@github-actions github-actions Bot added backend: agg topic: text/fonts topic: contour labels Nov 5, 2026
@iccir iccir added this to nanobind Nov 5, 2026
@github-project-automation github-project-automation Bot moved this to Todo in nanobind Nov 5, 2026
@iccir iccir moved this from Todo to In Progress in nanobind Nov 5, 2026
@iccir iccir moved this from In Progress to Blocked in nanobind Nov 5, 2026
@iccir iccir added the status: waiting for other PR label Nov 5, 2026
@iccir
iccir marked this pull request as ready for review November 5, 2026 19:46
@iccir iccir mentioned this pull request Nov 6, 2026
nanobind Umbrella #32560
Open
@iccir iccir moved this from Blocked to In Progress in nanobind Nov 8, 2026
@iccir iccir moved this from In Progress to Blocked in nanobind Nov 8, 2026

This branch has not been deployed

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

backend: agg status: waiting for other PR topic: contour topic: text/fonts

Projects

nanobind
Status: Blocked

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@iccir
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.