| 8 | using namespace boost::python; |
| 9 | |
| 10 | struct unicode_from_python |
| 11 | { |
| 12 | unicode_from_python() |
| 13 | { |
| 14 | converter::registry::push_back( |
| 15 | &convertible, &construct, type_id<std::string>() |
| 16 | ); |
| 17 | } |
| 18 | |
| 19 | static void* convertible(PyObject* x) |
| 20 | { |
| 21 | #if PY_VERSION_HEX >= 0x03020000 |
| 22 | return PyUnicode_Check(x) ? x : nullptr; |
| 23 | #else |
| 24 | return PyString_Check(x) ? x : PyUnicode_Check(x) ? x : nullptr; |
| 25 | #endif |
| 26 | } |
| 27 | |
| 28 | static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data) |
| 29 | { |
| 30 | void* storage = ((converter::rvalue_from_python_storage< |
| 31 | std::string>*)data)->storage.bytes; |
| 32 | |
| 33 | #if PY_VERSION_HEX < 0x03000000 |
| 34 | if (PyString_Check(x)) |
| 35 | { |
| 36 | data->convertible = new (storage) std::string(PyString_AsString(x) |
| 37 | , PyString_Size(x)); |
| 38 | } |
| 39 | else |
| 40 | #endif |
| 41 | { |
| 42 | Py_ssize_t size = 0; |
| 43 | char const* unicode = PyUnicode_AsUTF8AndSize(x, &size); |
| 44 | data->convertible = new (storage) std::string(unicode, size); |
| 45 | } |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | void bind_unicode_string_conversion() |
| 50 | { |
no outgoing calls
no test coverage detected