pybind / pybind11

Seamless operability between C++11 and Python
https://pybind11.readthedocs.io/
Other
15.09k stars 2.05k forks source link

"error_already_set at memory location" exception throws when python call pybind function with std::variant<> argument #4989

Closed aungkhant0911 closed 6 months ago

aungkhant0911 commented 6 months ago

Required prerequisites

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

latest release build

Problem description

The exception occurs in call() function's reinterpret_steal. As the title mentioned, the problem persist, as long as the argument of doS is variant. I am not sure what I am missing.

Reproducible example code

pybind code:

void doS(variant<bool, int> var) {
    cout << "value of 'b' is " << get<0>(var) << endl;
}

int main() {
    py::scoped_interpreter guard{};
    py::module_ te = py::module_::import("testing");    

    te.def("blah", &doS);
    te.attr("h")(); 
    return 0;   
}

testing.py :

def h(): 
    print("H H HH H ")
    blah(345)

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

Not a regression

aungkhant0911 commented 6 months ago

resolved