MCPcopy Create free account
hub / github.com/pybind/pybind11 / bytes

Method bytes

include/pybind11/pytypes.h:1807–1825  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1805/// @} pytypes
1806
1807inline bytes::bytes(const pybind11::str &s) {
1808 object temp = s;
1809 if (PyUnicode_Check(s.ptr())) {
1810 temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(s.ptr()));
1811 if (!temp) {
1812 throw error_already_set();
1813 }
1814 }
1815 char *buffer = nullptr;
1816 ssize_t length = 0;
1817 if (PyBytes_AsStringAndSize(temp.ptr(), &buffer, &length) != 0) {
1818 throw error_already_set();
1819 }
1820 auto obj = reinterpret_steal<object>(PYBIND11_BYTES_FROM_STRING_AND_SIZE(buffer, length));
1821 if (!obj) {
1822 pybind11_fail("Could not allocate bytes object!");
1823 }
1824 m_ptr = obj.release().ptr();
1825}
1826
1827inline str::str(const bytes &b) {
1828 char *buffer = nullptr;

Callers

nothing calls this directly

Calls 2

ptrMethod · 0.80
releaseMethod · 0.80

Tested by

no test coverage detected