From 5f4f9e0839ea2026080e3339d13da62b0cb0b936 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Sat, 14 Aug 2021 07:56:15 +0100 Subject: [PATCH] ffi: PyPy and Python 3.10 attributes for unicodeobject --- src/ffi/cpython/unicodeobject.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ffi/cpython/unicodeobject.rs b/src/ffi/cpython/unicodeobject.rs index 243c0ede3cd..044701debc7 100644 --- a/src/ffi/cpython/unicodeobject.rs +++ b/src/ffi/cpython/unicodeobject.rs @@ -228,11 +228,15 @@ pub unsafe fn PyUnicode_READY(op: *mut PyObject) -> c_int { // skipped PyUnicode_WSTR_LENGTH extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyUnicode_New")] pub fn PyUnicode_New(size: Py_ssize_t, maxchar: Py_UCS4) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPyUnicode_Ready")] pub fn _PyUnicode_Ready(unicode: *mut PyObject) -> c_int; // skipped _PyUnicode_Copy + #[cfg(not(PyPy))] + #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyUnicode_CopyCharacters( to: *mut PyObject, to_start: Py_ssize_t, @@ -243,6 +247,8 @@ extern "C" { // skipped _PyUnicode_FastCopyCharacters + #[cfg(not(PyPy))] + #[cfg_attr(docsrs, doc(cfg(not(PyPy))))] pub fn PyUnicode_Fill( unicode: *mut PyObject, start: Py_ssize_t, @@ -257,6 +263,7 @@ extern "C" { #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] pub fn PyUnicode_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromKindAndData")] pub fn PyUnicode_FromKindAndData( kind: c_int, buffer: *const c_void, @@ -551,7 +558,11 @@ mod tests { // This has potential to mutate object. But it should be a no-op since // we're already ready. - assert_eq!(PyUnicode_READY(ptr), 0); + assert_eq!( + #[cfg_attr(Py_3_10, allow(deprecated))] + PyUnicode_READY(ptr), + 0 + ); } }) } @@ -589,7 +600,11 @@ mod tests { // This has potential to mutate object. But it should be a no-op since // we're already ready. - assert_eq!(PyUnicode_READY(ptr), 0); + assert_eq!( + #[cfg_attr(Py_3_10, allow(deprecated))] + PyUnicode_READY(ptr), + 0 + ); } }) }