| 1825 | } |
| 1826 | |
| 1827 | inline str::str(const bytes &b) { |
| 1828 | char *buffer = nullptr; |
| 1829 | ssize_t length = 0; |
| 1830 | if (PyBytes_AsStringAndSize(b.ptr(), &buffer, &length) != 0) { |
| 1831 | throw error_already_set(); |
| 1832 | } |
| 1833 | auto obj = reinterpret_steal<object>(PyUnicode_FromStringAndSize(buffer, length)); |
| 1834 | if (!obj) { |
| 1835 | if (PyErr_Occurred()) { |
| 1836 | throw error_already_set(); |
| 1837 | } |
| 1838 | pybind11_fail("Could not allocate string object!"); |
| 1839 | } |
| 1840 | m_ptr = obj.release().ptr(); |
| 1841 | } |
| 1842 | |
| 1843 | /// \addtogroup pytypes |
| 1844 | /// @{ |