Created
September 21, 2017 21:02
-
-
Save ezyang/3edfe5f0f035d4f18c01d76c33ae6bd0 to your computer and use it in GitHub Desktop.
pybind11 cast to py::object subclass is lazy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pybind11/pybind11.h> | |
#include <iostream> | |
namespace py = pybind11; | |
int main() { | |
Py_Initialize(); | |
auto gil = PyGILState_Ensure(); | |
PyObject *l = PyFloat_FromDouble(3.14); | |
//PyObject *l = PyBytes_FromString("foo"); | |
auto n = py::cast<py::bytes>(l); | |
std::cerr << "No problem yet...\n"; | |
std::cerr << static_cast<std::string>(n); | |
PyGILState_Release(gil); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment