2772: fix PyUnicodeDecodeError_Create r=davidhewitt a=mejrs

Fixes https://github.com/PyO3/pyo3/issues/2770

Co-authored-by: mejrs <>
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
This commit is contained in:
bors[bot] 2022-12-27 16:22:58 +00:00 committed by GitHub
commit 1598991a05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -0,0 +1 @@
Fix `PyUnicodeDecodeError_Create` failing unconditionally with a TypeError on PyPy.

View file

@ -85,18 +85,17 @@ pub unsafe fn PyUnicodeDecodeError_Create(
length: Py_ssize_t, length: Py_ssize_t,
start: Py_ssize_t, start: Py_ssize_t,
end: Py_ssize_t, end: Py_ssize_t,
_reason: *const c_char, reason: *const c_char,
) -> *mut PyObject { ) -> *mut PyObject {
crate::PyObject_CallFunction( crate::PyObject_CallFunction(
PyExc_UnicodeDecodeError, PyExc_UnicodeDecodeError,
std::ffi::CStr::from_bytes_with_nul(b"sy#nns\0") b"sy#nns\0".as_ptr().cast::<c_char>(),
.unwrap()
.as_ptr(),
encoding, encoding,
object, object,
length, length,
start, start,
end, end,
reason,
) )
} }