Skip to content

Commit

Permalink
string: enable use of PyUnicode_AsUTF8AndSize on all Python versions
Browse files Browse the repository at this point in the history
This API is available in all supported Python versions and isn't
deprecated.
  • Loading branch information
indygreg committed Aug 14, 2021
1 parent 974a782 commit f1ba3cb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl PyString {
pub fn to_str(&self) -> PyResult<&str> {
let utf8_slice = {
cfg_if::cfg_if! {
if #[cfg(any(not(Py_LIMITED_API), Py_3_10))] {
// PyUnicode_AsUTF8AndSize only available on limited API from Python 3.10 and up.
if #[cfg(Py_LIMITED_API)] {
// PyUnicode_AsUTF8AndSize only available on limited API.
let mut size: ffi::Py_ssize_t = 0;
let data = unsafe { ffi::PyUnicode_AsUTF8AndSize(self.as_ptr(), &mut size) };
if data.is_null() {
Expand Down

0 comments on commit f1ba3cb

Please sign in to comment.