Skip to content

fix: return None for null Eigen matrix pointers - #6184

Merged
henryiii merged 1 commit into
pybind:masterfrom
jad-fahmi:fix/eigen-null-matrix-pointer
Oct 7, 2026
Merged

henryiii merged 1 commit into
pybind:masterfrom
jad-fahmi:fix/eigen-null-matrix-pointer

Conversation

@jad-fahmi

Copy link
Copy Markdown
Contributor

Description

Fixes #5635.

The dense Eigen caster passed null pointers to capsule creation or dereferenced them, depending on the return policy. Return None before applying the policy, matching other pointer casters. The regression covers mutable and const matrix pointers with all seven return policies.

Validation with Eigen 3.4.0:

  • On bf21a6df with the regression tests added, python3 -m pytest /baseline/tests/test_eigen_matrix.py -k 'null_matrix and automatic and not reference' -q fails both cases with ValueError: PyCapsule_New called with null pointer.
  • Linux, GCC 13.3, C++11, Python 3.12: python3 -m pytest /baseline/tests/test_eigen_matrix.py -q passes all 46 tests. cmake --build /build --target check -j 6 passes: 1,328 Python tests (48 skipped), standalone C++ tests, embedded-interpreter tests, cross-module RTTI tests, and six CMake integration checks.
  • Windows, GCC 14.2, Python 3.13: the Eigen matrix suite passes all 46 tests using python -c "import os, pytest; dlls = os.add_dll_directory('C:/msys64/ucrt64/bin'); raise SystemExit(pytest.main(['../../tests/test_eigen_matrix.py', '-q']))" from build/tests.
  • prek run --all-files --quiet and git diff --check pass.

Suggested changelog entry:

  • Return None when a bound function returns a null pointer to a dense Eigen matrix.

@henryiii
henryiii merged commit bd99d60 into pybind:master Oct 7, 2026
80 checks passed
@github-actions github-actions Bot added the needs changelog Possibly needs a changelog entry label Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Possibly needs a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: returning nullptr from a function supposed to return Eigen...* gives errr

2 participants