Skip to content

test: add regression test for PYBIND11_MAKE_OPAQUE with std::array (issue #5988)#6006

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-crash-with-std-containers
Draft

test: add regression test for PYBIND11_MAKE_OPAQUE with std::array (issue #5988)#6006
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-crash-with-std-containers

Conversation

Copy link

Copilot AI commented Mar 7, 2026

Description

pybind11 3.0.2 crashes on Windows (Python 3.11/MSVC) during module initialization when PYBIND11_MAKE_OPAQUE is used with std::array types. The crash trace shows a null pointer access violation inside pybind11::detail::get_internals()Thrd_yield (MSVCP140.dll), triggered at import time.

This PR adds a regression test exercising PYBIND11_MAKE_OPAQUE with std::array<double, 3> and the nested std::vector<std::array<double, 3>> — types not currently covered by any test and safe from ODR conflicts (unlike std::array<int, 3> which is used as a converted type in test_stl.cpp):

// Reproduces the reported usage pattern from issue #5988
PYBIND11_MAKE_OPAQUE(std::array<double, 3>)
PYBIND11_MAKE_OPAQUE(std::vector<std::array<double, 3>>)
  • tests/test_opaque_types.cpp: Adds PYBIND11_MAKE_OPAQUE declarations for std::array<double, 3> and std::vector<std::array<double, 3>>, with py::class_ bindings exposing indexing, mutation, and length operations.
  • tests/test_opaque_types.py: Adds test_issue_5988_opaque_std_array() covering element access, bounds checking (IndexError), and vector-of-array operations.

Suggested changelog entry:

Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG]: 3.0.2 is crashing when binding with std containers</issue_title>
<issue_description>### Required prerequisites

What version (or hash if on master) of pybind11 are you using?

3.0.2

Problem description

I updated from 3.0.1 to 3.0.2 and now pybind11 is crashing when the compiled and loaded in Python. I am currently trying it in windows with VS2026 and intel oneAPI compiler. I haven't tried Linux or g++ yet. I also have not narrowed down which container binding is crashing.
version 3.0.1 is working fine. I have attached the crash report. It is coming from Blender. Blender is using python 3.11. The crash is from python.

blender.crash.txt

Reproducible example code

C++

#include <pybind11/pybind11.h>
namespace py = pybind11;

PYBIND11_MAKE_OPAQUE(std::array<double, 3>)
PYBIND11_MAKE_OPAQUE(std::array<int, 3>)
PYBIND11_MAKE_OPAQUE(std::vector<double>)
PYBIND11_MAKE_OPAQUE(std::vector<int>)
PYBIND11_MAKE_OPAQUE(std::vector<uint8_t>)
PYBIND11_MAKE_OPAQUE(std::vector<std::array<double, 3>>)
PYBIND11_MAKE_OPAQUE(std::vector<std::array<int, 3>>)
PYBIND11_MAKE_OPAQUE(std::vector<std::string>)

PYBIND11_MODULE(TestAPI, m, py::mod_gil_not_used())
{
}

Python:

if (os.name == "nt"):
    try:
        ctypes.CDLL(os.path.join(addon_dir, "cAPI\SimulationAPI.cp311-win_amd64.pyd"))
    except OSError as e:
        print(f"Error loading .pyd file: {e}")

from .cAPI import TestAPI

Is this a regression? Put the last known working version here if it is.

3.0.1</issue_description>

<agent_instructions>Make a test case with the example to see if CI does crash with it.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix crash in pybind11 when using std containers test: add regression test for PYBIND11_MAKE_OPAQUE with std::array (issue #5988) Mar 7, 2026
@henryiii
Copy link
Collaborator

henryiii commented Mar 7, 2026

pre-commit.ci autofix

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: 3.0.2 is crashing when binding with std containers

2 participants