(&'a self, py: Python, ptr: *const c_char)
| 55 | } |
| 56 | |
| 57 | unsafe fn str_from_ptr<'a>(&'a self, py: Python, ptr: *const c_char) -> PyResult<&'a str> { |
| 58 | if ptr.is_null() { |
| 59 | Err(PyErr::fetch(py)) |
| 60 | } else { |
| 61 | let slice = CStr::from_ptr(ptr).to_bytes(); |
| 62 | match std::str::from_utf8(slice) { |
| 63 | Ok(s) => Ok(s), |
| 64 | Err(e) => Err(PyErr::from_instance( |
| 65 | py, |
| 66 | exc::UnicodeDecodeError::new_utf8(py, slice, e)?, |
| 67 | )), |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /// Gets the module name. |
| 73 | /// |