pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

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

Open sin3point14 opened this issue 7 months ago • 0 comments

Required prerequisites

  • [x] Make sure you've read the documentation. Your issue may be addressed there.
  • [x] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
  • [x] Consider asking first in the Gitter chat room or in a Discussion.

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

2.13.6

Problem description

https://github.com/pybind/pybind11/issues/731 makes me believe that pybind11 should be able to handle returning nullptr for all data types, hence, I think this is an issue

Reproducible example code

(.venv-linux) sin3point14@DESKTOP-D97C2FN:~/random/cpp/pybind11-test$ cat main.cpp
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include <pybind11/stl.h>

#include <Eigen/Eigen>

PYBIND11_MODULE(tsting, m)
{
    m.def("ret_nullptr", []() -> Eigen::MatrixXd* {return nullptr;});
}
(.venv-linux) sin3point14@DESKTOP-D97C2FN:~/random/cpp/pybind11-test$ python3
Python 3.12.3 (main, Feb  4 2025, 14:48:35) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tsting
>>> tsting.ret_nullptr()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: PyCapsule_New called with null pointer

I get a segmentation fault in the project where I discovered this. But i guess this should also not have errored.

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

Not a regression

sin3point14 avatar May 01 '25 18:05 sin3point14