diff --git a/newsfragments/6041.added.md b/newsfragments/6041.added.md new file mode 100644 index 00000000000..17f1277aa15 --- /dev/null +++ b/newsfragments/6041.added.md @@ -0,0 +1 @@ +Add FFI definition `Py_UNICODE_TODECIMAL`. diff --git a/newsfragments/6041.fixed.md b/newsfragments/6041.fixed.md new file mode 100644 index 00000000000..e007ffdc39d --- /dev/null +++ b/newsfragments/6041.fixed.md @@ -0,0 +1,12 @@ +Mark FFI definitions no longer available on 3.11 and up: `PyUnicode_Encode`, `PyUnicode_EncodeASCII`, `PyUnicode_EncodeCharmap`, `PyUnicode_EncodeDecimal`, +`PyUnicode_EncodeLatin1`, + `PyUnicode_EncodeRawUnicodeEscape`, + `PyUnicode_EncodeUTF7`, + `PyUnicode_EncodeUTF8`, + `PyUnicode_EncodeUTF16`, + `PyUnicode_EncodeUTF32`, + `PyUnicode_EncodeUnicodeEscape`, + `PyUnicode_TransformDecimalToASCII`, and + `PyUnicode_TranslateCharmap`. + +Mark FFI definition `PyUnicode_ClearFreeList` no longer avaialable on 3.9 and up. diff --git a/pyo3-ffi-check/macro/src/lib.rs b/pyo3-ffi-check/macro/src/lib.rs index 399e87b9270..80de280c481 100644 --- a/pyo3-ffi-check/macro/src/lib.rs +++ b/pyo3-ffi-check/macro/src/lib.rs @@ -430,6 +430,7 @@ const MACRO_EXCLUSIONS: &[(&str, &str)] = &[ ("Py_REFCNT", "not(Py_3_14)"), ("Py_True", ""), ("Py_TYPE", "not(Py_3_14)"), + ("Py_UNICODE_TODECIMAL", ""), ("Py_XDECREF", ""), ("Py_XINCREF", ""), // These functions were only added in 3.10, but pyo3-ffi defines them for @@ -459,20 +460,6 @@ const EXCLUDED_SYMBOLS: &[&str] = &[ "PySys_AddXOption", "PySys_HasWarnOptions", "PySys_SetPath", - "PyUnicode_ClearFreeList", - "PyUnicode_Encode", - "PyUnicode_EncodeASCII", - "PyUnicode_EncodeCharmap", - "PyUnicode_EncodeDecimal", - "PyUnicode_EncodeLatin1", - "PyUnicode_EncodeRawUnicodeEscape", - "PyUnicode_EncodeUTF7", - "PyUnicode_EncodeUTF8", - "PyUnicode_EncodeUTF16", - "PyUnicode_EncodeUTF32", - "PyUnicode_EncodeUnicodeEscape", - "PyUnicode_TransformDecimalToASCII", - "PyUnicode_TranslateCharmap", // This symbol was not in headers but still public until Python 3.10, // should be able to remove this exclusion once support for 3.9 dropped "Py_GetArgcArgv", diff --git a/pyo3-ffi/src/cpython/unicodeobject.rs b/pyo3-ffi/src/cpython/unicodeobject.rs index 39315534786..bc256348c2b 100644 --- a/pyo3-ffi/src/cpython/unicodeobject.rs +++ b/pyo3-ffi/src/cpython/unicodeobject.rs @@ -4,25 +4,15 @@ use crate::{PyObject, Py_UCS1, Py_UCS2, Py_UCS4, Py_ssize_t}; use core::ffi::{c_char, c_int, c_uint, c_void}; use libc::wchar_t; -// skipped Py_UNICODE_ISSPACE() -// skipped Py_UNICODE_ISLOWER() -// skipped Py_UNICODE_ISUPPER() -// skipped Py_UNICODE_ISTITLE() -// skipped Py_UNICODE_ISLINEBREAK -// skipped Py_UNICODE_TOLOWER -// skipped Py_UNICODE_TOUPPER -// skipped Py_UNICODE_TOTITLE -// skipped Py_UNICODE_ISDECIMAL -// skipped Py_UNICODE_ISDIGIT -// skipped Py_UNICODE_ISNUMERIC -// skipped Py_UNICODE_ISPRINTABLE -// skipped Py_UNICODE_TODECIMAL -// skipped Py_UNICODE_TODIGIT -// skipped Py_UNICODE_TONUMERIC -// skipped Py_UNICODE_ISALPHA -// skipped Py_UNICODE_ISALNUM -// skipped Py_UNICODE_COPY -// skipped Py_UNICODE_FILL +// skipped PY_UNICODE_TYPE + +#[cfg(not(Py_LIMITED_API))] +#[cfg_attr( + Py_3_13, + deprecated(note = "Deprecated since Python 3.13. Use `libc::wchar_t` instead.") +)] +pub type Py_UNICODE = wchar_t; + // skipped Py_UNICODE_IS_SURROGATE // skipped Py_UNICODE_IS_HIGH_SURROGATE // skipped Py_UNICODE_IS_LOW_SURROGATE @@ -458,10 +448,9 @@ pub struct PyUnicodeObject { pub data: PyUnicodeObjectData, } -// skipped PyUnicode_GET_SIZE -// skipped PyUnicode_GET_DATA_SIZE -// skipped PyUnicode_AS_UNICODE -// skipped PyUnicode_AS_DATA +// skipped private _PyASCIIObject_CAST +// skipped private _PyCompactUnicodeObject_CAST +// skipped private _PyUnicodeObject_CAST pub const SSTATE_NOT_INTERNED: c_uint = 0; pub const SSTATE_INTERNED_MORTAL: c_uint = 1; @@ -469,6 +458,28 @@ pub const SSTATE_INTERNED_IMMORTAL: c_uint = 2; #[cfg(Py_3_12)] pub const SSTATE_INTERNED_IMMORTAL_STATIC: c_uint = 3; +// skipped PyUnicode_CHECK_INTERNED + +#[cfg(any(Py_3_12, GraalPy))] +#[cfg_attr( + Py_3_14, + deprecated(note = "Deprecated since Python 3.14. This API does nothing since Python 3.12.") +)] +#[inline] +pub unsafe fn PyUnicode_IS_READY(_op: *mut PyObject) -> c_uint { + // kept in CPython for backwards compatibility + 1 +} + +#[cfg(not(any(GraalPy, Py_3_12)))] +#[inline] +pub unsafe fn PyUnicode_IS_READY(op: *mut PyObject) -> c_uint { + (*(op as *mut PyASCIIObject)).ready() +} + +// The following functions depend on the bitfield, which we don't support +// from 3.14 onwards + #[cfg(not(any(GraalPy, Py_3_14)))] #[inline] pub unsafe fn PyUnicode_IS_ASCII(op: *mut PyObject) -> c_uint { @@ -499,24 +510,6 @@ pub const PyUnicode_1BYTE_KIND: c_uint = 1; pub const PyUnicode_2BYTE_KIND: c_uint = 2; pub const PyUnicode_4BYTE_KIND: c_uint = 4; -#[cfg(not(any(GraalPy, PyPy)))] -#[inline] -pub unsafe fn PyUnicode_1BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS1 { - PyUnicode_DATA(op) as *mut Py_UCS1 -} - -#[cfg(not(any(GraalPy, PyPy)))] -#[inline] -pub unsafe fn PyUnicode_2BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS2 { - PyUnicode_DATA(op) as *mut Py_UCS2 -} - -#[cfg(not(any(GraalPy, PyPy)))] -#[inline] -pub unsafe fn PyUnicode_4BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS4 { - PyUnicode_DATA(op) as *mut Py_UCS4 -} - #[cfg(all(not(GraalPy), Py_3_14))] extern_libpython! { #[cfg_attr(PyPy, link_name = "PyPyUnicode_KIND")] @@ -570,9 +563,23 @@ extern_libpython! { pub fn PyUnicode_DATA(op: *mut PyObject) -> *mut c_void; } -// skipped PyUnicode_WRITE -// skipped PyUnicode_READ -// skipped PyUnicode_READ_CHAR +#[cfg(not(any(GraalPy, PyPy)))] +#[inline] +pub unsafe fn PyUnicode_1BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS1 { + PyUnicode_DATA(op) as *mut Py_UCS1 +} + +#[cfg(not(any(GraalPy, PyPy)))] +#[inline] +pub unsafe fn PyUnicode_2BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS2 { + PyUnicode_DATA(op) as *mut Py_UCS2 +} + +#[cfg(not(any(GraalPy, PyPy)))] +#[inline] +pub unsafe fn PyUnicode_4BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS4 { + PyUnicode_DATA(op) as *mut Py_UCS4 +} #[cfg(not(GraalPy))] #[inline] @@ -584,17 +591,15 @@ pub unsafe fn PyUnicode_GET_LENGTH(op: *mut PyObject) -> Py_ssize_t { (*(op as *mut PyASCIIObject)).length } -#[cfg(any(Py_3_12, GraalPy))] -#[inline] -pub unsafe fn PyUnicode_IS_READY(_op: *mut PyObject) -> c_uint { - // kept in CPython for backwards compatibility - 1 -} +// skipped PyUnstable_Unicode_GET_CACHED_HASH +// skipped PyUnicode_WRITE +// skipped PyUnicode_READ +// skipped PyUnicode_READ_CHAR +// skipped PyUnicode_MAX_CHAR_VALUE -#[cfg(not(any(GraalPy, Py_3_12)))] -#[inline] -pub unsafe fn PyUnicode_IS_READY(op: *mut PyObject) -> c_uint { - (*(op as *mut PyASCIIObject)).ready() +extern_libpython! { + #[cfg_attr(PyPy, link_name = "PyPyUnicode_New")] + pub fn PyUnicode_New(size: Py_ssize_t, maxchar: Py_UCS4) -> *mut PyObject; } #[cfg(any(Py_3_12, GraalPy))] @@ -615,18 +620,11 @@ pub unsafe fn PyUnicode_READY(op: *mut PyObject) -> c_int { } } -// skipped PyUnicode_MAX_CHAR_VALUE -// skipped _PyUnicode_get_wstr_length -// skipped PyUnicode_WSTR_LENGTH - extern_libpython! { - #[cfg_attr(PyPy, link_name = "PyPyUnicode_New")] - pub fn PyUnicode_New(size: Py_ssize_t, maxchar: Py_UCS4) -> *mut PyObject; + #[cfg(not(any(Py_3_12, GraalPy)))] #[cfg_attr(PyPy, link_name = "_PyPyUnicode_Ready")] fn _PyUnicode_Ready(unicode: *mut PyObject) -> c_int; - // skipped _PyUnicode_Copy - #[cfg(not(PyPy))] pub fn PyUnicode_CopyCharacters( to: *mut PyObject, @@ -636,8 +634,6 @@ extern_libpython! { how_many: Py_ssize_t, ) -> Py_ssize_t; - // skipped _PyUnicode_FastCopyCharacters - #[cfg(not(PyPy))] pub fn PyUnicode_Fill( unicode: *mut PyObject, @@ -646,8 +642,6 @@ extern_libpython! { fill_char: Py_UCS4, ) -> Py_ssize_t; - // skipped _PyUnicode_FastFill - #[cfg(not(Py_3_12))] #[deprecated] #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] @@ -660,16 +654,11 @@ extern_libpython! { size: Py_ssize_t, ) -> *mut PyObject; - // skipped _PyUnicode_FromASCII - // skipped _PyUnicode_FindMaxChar - #[cfg(not(Py_3_12))] #[deprecated] #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] pub fn PyUnicode_AsUnicode(unicode: *mut PyObject) -> *mut wchar_t; - // skipped _PyUnicode_AsUnicode - #[cfg(not(Py_3_12))] #[deprecated] #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeAndSize")] @@ -677,8 +666,6 @@ extern_libpython! { unicode: *mut PyObject, size: *mut Py_ssize_t, ) -> *mut wchar_t; - - // skipped PyUnicode_GetMax } #[cfg(Py_3_14)] @@ -688,9 +675,10 @@ extern_libpython! { #[cfg(Py_3_14)] pub fn PyUnicodeWriter_Create(length: Py_ssize_t) -> *mut PyUnicodeWriter; #[cfg(Py_3_14)] - pub fn PyUnicodeWriter_Finish(writer: *mut PyUnicodeWriter) -> *mut PyObject; - #[cfg(Py_3_14)] pub fn PyUnicodeWriter_Discard(writer: *mut PyUnicodeWriter); + #[cfg(Py_3_14)] + pub fn PyUnicodeWriter_Finish(writer: *mut PyUnicodeWriter) -> *mut PyObject; + #[cfg(Py_3_14)] pub fn PyUnicodeWriter_WriteChar(writer: *mut PyUnicodeWriter, ch: Py_UCS4) -> c_int; #[cfg(Py_3_14)] @@ -699,31 +687,40 @@ extern_libpython! { str: *const c_char, size: Py_ssize_t, ) -> c_int; -} - -// skipped _PyUnicodeWriter -// skipped _PyUnicodeWriter_Init -// skipped _PyUnicodeWriter_Prepare -// skipped _PyUnicodeWriter_PrepareInternal -// skipped _PyUnicodeWriter_PrepareKind -// skipped _PyUnicodeWriter_PrepareKindInternal -// skipped _PyUnicodeWriter_WriteChar -// skipped _PyUnicodeWriter_WriteStr -// skipped _PyUnicodeWriter_WriteSubstring -// skipped _PyUnicodeWriter_WriteASCIIString -// skipped _PyUnicodeWriter_WriteLatin1String -// skipped _PyUnicodeWriter_Finish -// skipped _PyUnicodeWriter_Dealloc -// skipped _PyUnicode_FormatAdvancedWriter + // skipped PyUnicodeWriter_WriteASCII + // skipped PyUnicodeWriter_WriteWideChar + // skipped PyUnicodeWriter_WriteUCS4 + + // skipped PyUnicodeWriter_WriteStr + // skipped PyUnicodeWriter_WriteRepr + // skipped PyUnicodeWriter_WriteSubstring + // skipped PyUnicodeWriter_Format + // skipped PyUnicodeWriter_DecodeUTF8Stateful +} + +// skipped private _PyUnicodeWriter +// skipped private _PyUnicodeWriter_Init +// skipped private _PyUnicodeWriter_Prepare +// skipped private _PyUnicodeWriter_PrepareInternal +// skipped private _PyUnicodeWriter_PrepareKind +// skipped private _PyUnicodeWriter_PrepareKindInternal +// skipped private _PyUnicodeWriter_WriteChar +// skipped private _PyUnicodeWriter_WriteStr +// skipped private _PyUnicodeWriter_WriteSubstring +// skipped private _PyUnicodeWriter_WriteASCIIString +// skipped private _PyUnicodeWriter_WriteLatin1String +// skipped private _PyUnicodeWriter_Finish +// skipped private _PyUnicodeWriter_Dealloc extern_libpython! { - // skipped _PyUnicode_AsStringAndSize #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8")] pub fn PyUnicode_AsUTF8(unicode: *mut PyObject) -> *const c_char; // skipped _PyUnicode_AsString + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_AsEncodedString` instead")] pub fn PyUnicode_Encode( s: *const wchar_t, size: Py_ssize_t, @@ -731,6 +728,8 @@ extern_libpython! { errors: *const c_char, ) -> *mut PyObject; + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_AsEncodedString` instead")] pub fn PyUnicode_EncodeUTF7( data: *const wchar_t, length: Py_ssize_t, @@ -739,9 +738,8 @@ extern_libpython! { errors: *const c_char, ) -> *mut PyObject; - // skipped _PyUnicode_EncodeUTF7 - // skipped _PyUnicode_AsUTF8String - + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_AsUTF8String` instead")] #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] pub fn PyUnicode_EncodeUTF8( data: *const wchar_t, @@ -749,6 +747,8 @@ extern_libpython! { errors: *const c_char, ) -> *mut PyObject; + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_AsUTF32String` instead")] pub fn PyUnicode_EncodeUTF32( data: *const wchar_t, length: Py_ssize_t, @@ -756,8 +756,8 @@ extern_libpython! { byteorder: c_int, ) -> *mut PyObject; - // skipped _PyUnicode_EncodeUTF32 - + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_AsUTF16String` instead")] pub fn PyUnicode_EncodeUTF16( data: *const wchar_t, length: Py_ssize_t, @@ -765,19 +765,20 @@ extern_libpython! { byteorder: c_int, ) -> *mut PyObject; - // skipped _PyUnicode_EncodeUTF16 - // skipped _PyUnicode_DecodeUnicodeEscape - + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_AsUnicodeEscapeString` instead")] pub fn PyUnicode_EncodeUnicodeEscape(data: *const wchar_t, length: Py_ssize_t) -> *mut PyObject; + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_AsRawUnicodeEscapeString` instead")] pub fn PyUnicode_EncodeRawUnicodeEscape( data: *const wchar_t, length: Py_ssize_t, ) -> *mut PyObject; - // skipped _PyUnicode_AsLatin1String - + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_AsLatin1String` instead")] #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] pub fn PyUnicode_EncodeLatin1( data: *const wchar_t, @@ -785,8 +786,8 @@ extern_libpython! { errors: *const c_char, ) -> *mut PyObject; - // skipped _PyUnicode_AsASCIIString - + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_AsASCIIString` instead")] #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] pub fn PyUnicode_EncodeASCII( data: *const wchar_t, @@ -794,6 +795,8 @@ extern_libpython! { errors: *const c_char, ) -> *mut PyObject; + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_AsCharmapString` instead")] pub fn PyUnicode_EncodeCharmap( data: *const wchar_t, length: Py_ssize_t, @@ -801,8 +804,8 @@ extern_libpython! { errors: *const c_char, ) -> *mut PyObject; - // skipped _PyUnicode_EncodeCharmap - + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `PyUnicode_Translate` instead")] pub fn PyUnicode_TranslateCharmap( data: *const wchar_t, length: Py_ssize_t, @@ -810,8 +813,8 @@ extern_libpython! { errors: *const c_char, ) -> *mut PyObject; - // skipped PyUnicode_EncodeMBCS - + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `Py_UNICODE_TODECIMAL` instead")] #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] pub fn PyUnicode_EncodeDecimal( s: *mut wchar_t, @@ -820,54 +823,57 @@ extern_libpython! { errors: *const c_char, ) -> c_int; + #[cfg(not(Py_3_11))] + #[deprecated(note = "use `Py_UNICODE_TODECIMAL` instead")] #[cfg_attr(PyPy, link_name = "PyPyUnicode_TransformDecimalToASCII")] pub fn PyUnicode_TransformDecimalToASCII(s: *mut wchar_t, length: Py_ssize_t) -> *mut PyObject; - // skipped _PyUnicode_TransformDecimalAndSpaceToASCII -} + // skipped _PyUnicode_IsLowercase + // skipped _PyUnicode_IsUppercase + // skipped _PyUnicode_IsTitlecase + // skipped _PyUnicode_IsWhitespace + // skipped _PyUnicode_IsLinebreak + // skipped _PyUnicode_ToLowercase + // skipped _PyUnicode_ToUppercase + // skipped _PyUnicode_ToTitlecase + + fn _PyUnicode_ToDecimalDigit(ch: Py_UCS4) -> c_int; + + // skipped _PyUnicode_ToDigit + // skipped _PyUnicode_ToNumeric + // skipped _PyUnicode_IsDecimalDigit + // skipped _PyUnicode_IsDigit + // skipped _PyUnicode_IsNumeric + // skipped _PyUnicode_IsPrintable + // skipped _PyUnicode_IsAlpha -// skipped _PyUnicode_JoinArray -// skipped _PyUnicode_EqualToASCIIId -// skipped _PyUnicode_EqualToASCIIString -// skipped _PyUnicode_XStrip -// skipped _PyUnicode_InsertThousandsGrouping +} // skipped _Py_ascii_whitespace +// skipped Py_UNICODE_ISSPACE + +// skipped Py_UNICODE_ISLOWER +// skipped Py_UNICODE_ISUPPER +// skipped Py_UNICODE_ISTITLE +// skipped Py_UNICODE_ISLINEBREAK + +// skipped Py_UNICODE_TOLOWER +// skipped Py_UNICODE_TOUPPER +// skipped Py_UNICODE_TOTITLE + +// skipped Py_UNICODE_ISDECIMAL +// skipped Py_UNICODE_ISDIGIT +// skipped Py_UNICODE_ISNUMERIC +// skipped Py_UNICODE_ISPRINTABLE + +pub unsafe extern "C" fn Py_UNICODE_TODECIMAL(ch: Py_UCS4) -> c_int { + _PyUnicode_ToDecimalDigit(ch) +} +// skipped Py_UNICODE_TODIGIT +// skipped Py_UNICODE_TONUMERIC + +// skipped Py_UNICODE_ISALPHA + +// skipped Py_UNICODE_ISALNUM -// skipped _PyUnicode_IsLowercase -// skipped _PyUnicode_IsUppercase -// skipped _PyUnicode_IsTitlecase -// skipped _PyUnicode_IsXidStart -// skipped _PyUnicode_IsXidContinue -// skipped _PyUnicode_IsWhitespace -// skipped _PyUnicode_IsLinebreak -// skipped _PyUnicode_ToLowercase -// skipped _PyUnicode_ToUppercase -// skipped _PyUnicode_ToTitlecase -// skipped _PyUnicode_ToLowerFull -// skipped _PyUnicode_ToTitleFull -// skipped _PyUnicode_ToUpperFull -// skipped _PyUnicode_ToFoldedFull -// skipped _PyUnicode_IsCaseIgnorable -// skipped _PyUnicode_IsCased -// skipped _PyUnicode_ToDecimalDigit -// skipped _PyUnicode_ToDigit -// skipped _PyUnicode_ToNumeric -// skipped _PyUnicode_IsDecimalDigit -// skipped _PyUnicode_IsDigit -// skipped _PyUnicode_IsNumeric -// skipped _PyUnicode_IsPrintable -// skipped _PyUnicode_IsAlpha -// skipped Py_UNICODE_strlen -// skipped Py_UNICODE_strcpy -// skipped Py_UNICODE_strcat -// skipped Py_UNICODE_strncpy -// skipped Py_UNICODE_strcmp -// skipped Py_UNICODE_strncmp -// skipped Py_UNICODE_strchr -// skipped Py_UNICODE_strrchr -// skipped _PyUnicode_FormatLong -// skipped PyUnicode_AsUnicodeCopy -// skipped _PyUnicode_FromId -// skipped _PyUnicode_EQ -// skipped _PyUnicode_ScanIdentifier +// skipped private _PyUnicode_FromId diff --git a/pyo3-ffi/src/impl_/macros.rs b/pyo3-ffi/src/impl_/macros.rs index 2481d584072..8984f4aae97 100644 --- a/pyo3-ffi/src/impl_/macros.rs +++ b/pyo3-ffi/src/impl_/macros.rs @@ -116,6 +116,12 @@ macro_rules! extern_libpython_maybe_private_fn { ) => { extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? } }; + ( + [_PyUnicode_ToDecimalDigit] + $(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)? + ) => { + extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? } + }; ( [_PyLong_NumBits] $(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)? diff --git a/pyo3-ffi/src/unicodeobject.rs b/pyo3-ffi/src/unicodeobject.rs index e4a78f8caee..fba7e964059 100644 --- a/pyo3-ffi/src/unicodeobject.rs +++ b/pyo3-ffi/src/unicodeobject.rs @@ -3,13 +3,6 @@ use crate::pyport::Py_ssize_t; use core::ffi::{c_char, c_int, c_void}; use libc::wchar_t; -#[cfg(not(Py_LIMITED_API))] -#[cfg_attr( - Py_3_13, - deprecated(note = "Deprecated since Python 3.13. Use `libc::wchar_t` instead.") -)] -pub type Py_UNICODE = wchar_t; - pub type Py_UCS4 = u32; pub type Py_UCS2 = u16; pub type Py_UCS1 = u8; @@ -110,6 +103,7 @@ extern_libpython! { ) -> *mut wchar_t; #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromOrdinal")] pub fn PyUnicode_FromOrdinal(ordinal: c_int) -> *mut PyObject; + #[cfg(not(Py_3_9))] pub fn PyUnicode_ClearFreeList() -> c_int; #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] pub fn PyUnicode_GetDefaultEncoding() -> *const c_char; @@ -255,6 +249,11 @@ extern_libpython! { unicode: *mut PyObject, mapping: *mut PyObject, ) -> *mut PyObject; + // skipped PyUnicode_DecodeMBCS + // skipped PyUnicode_DecodeMBCSStateful + // skipped PyUnicode_DecodeCodePageStateful + // skipped PyUnicode_AsMBCSString + // skipped PyUnicode_EncodeCodePage pub fn PyUnicode_DecodeLocaleAndSize( str: *const c_char, len: Py_ssize_t, @@ -347,7 +346,7 @@ extern_libpython! { string: *const c_char, size: Py_ssize_t, ) -> c_int; - + // skipped PyUnicode_Equal pub fn PyUnicode_RichCompare( left: *mut PyObject, right: *mut PyObject, diff --git a/src/ffi/tests.rs b/src/ffi/tests.rs index 142166c153b..5bc09f2a643 100644 --- a/src/ffi/tests.rs +++ b/src/ffi/tests.rs @@ -203,10 +203,12 @@ fn ascii() { assert!(!PyUnicode_DATA(ptr).is_null()); assert_eq!(PyUnicode_GET_LENGTH(ptr), s.len().unwrap() as Py_ssize_t); + #[cfg(not(Py_3_12))] assert_eq!(PyUnicode_IS_READY(ptr), 1); // This has potential to mutate object. But it should be a no-op since // we're already ready. + #[cfg(not(Py_3_12))] assert_eq!(PyUnicode_READY(ptr), 0); } }) @@ -246,10 +248,12 @@ fn ucs4() { PyUnicode_GET_LENGTH(ptr), py_string.len().unwrap() as Py_ssize_t ); + #[cfg(not(Py_3_12))] assert_eq!(PyUnicode_IS_READY(ptr), 1); // This has potential to mutate object. But it should be a no-op since // we're already ready. + #[cfg(not(Py_3_12))] assert_eq!(PyUnicode_READY(ptr), 0); } })