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

Method load_raw

include/pybind11/cast.h:596–619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

594 // which supports loading a unicode from a str, doesn't take this path.
595 template <typename C = CharT>
596 bool load_raw(enable_if_t<std::is_same<C, char>::value, handle> src) {
597 if (PYBIND11_BYTES_CHECK(src.ptr())) {
598 // We were passed raw bytes; accept it into a std::string or char*
599 // without any encoding attempt.
600 const char *bytes = PYBIND11_BYTES_AS_STRING(src.ptr());
601 if (!bytes) {
602 pybind11_fail("Unexpected PYBIND11_BYTES_AS_STRING() failure.");
603 }
604 value = StringType(bytes, (size_t) PYBIND11_BYTES_SIZE(src.ptr()));
605 return true;
606 }
607 if (PyByteArray_Check(src.ptr())) {
608 // We were passed a bytearray; accept it into a std::string or char*
609 // without any encoding attempt.
610 const char *bytearray = PyByteArray_AsString(src.ptr());
611 if (!bytearray) {
612 pybind11_fail("Unexpected PyByteArray_AsString() failure.");
613 }
614 value = StringType(bytearray, (size_t) PyByteArray_Size(src.ptr()));
615 return true;
616 }
617
618 return false;
619 }
620
621 template <typename C = CharT>
622 bool load_raw(enable_if_t<!std::is_same<C, char>::value, handle>) {

Callers

nothing calls this directly

Calls 1

ptrMethod · 0.80

Tested by

no test coverage detected