| 42 | }; |
| 43 | |
| 44 | struct ustring_from_python_str |
| 45 | { |
| 46 | ustring_from_python_str() { |
| 47 | boost::python::converter::registry::push_back( |
| 48 | &convertible, |
| 49 | &construct, |
| 50 | boost::python::type_id<ustring>()); |
| 51 | } |
| 52 | |
| 53 | static void* convertible(PyObject* obj_ptr) { |
| 54 | #if PY_MAJOR_VERSION >= 3 |
| 55 | if (!PyUnicode_Check(obj_ptr)) return 0; |
| 56 | #else |
| 57 | if (!PyString_Check(obj_ptr)) return 0; |
| 58 | #endif |
| 59 | return obj_ptr; |
| 60 | } |
| 61 | |
| 62 | static void construct( |
| 63 | PyObject* obj_ptr, |
| 64 | boost::python::converter::rvalue_from_python_stage1_data* data) { |
| 65 | #if PY_MAJOR_VERSION >= 3 |
| 66 | PyObject* pyStr = PyUnicode_AsUTF8String(obj_ptr); |
| 67 | const char* value = PyBytes_AsString(pyStr); |
| 68 | #else |
| 69 | const char* value = PyString_AsString(obj_ptr); |
| 70 | #endif |
| 71 | if (value == 0) boost::python::throw_error_already_set(); |
| 72 | void* storage = ( |
| 73 | (boost::python::converter::rvalue_from_python_storage<ustring>*) |
| 74 | data)->storage.bytes; |
| 75 | new (storage) ustring(value); |
| 76 | data->convertible = storage; |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | |
| 81 |
no outgoing calls
no test coverage detected