Skip to content

Commit 8cb90ab

Browse files
committed
Add PyBytes_AS_STRING, seen in ormsgpack
1 parent e39334f commit 8cb90ab

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

newsfragments/1.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Added `_PyLong_Sign`
2+
Add `PyBytes_AS_STRING`

pyo3-ffi/src/cpython/bytesobject.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::object::*;
22
use crate::Py_ssize_t;
3-
#[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))]
3+
#[cfg(not(any(PyPy, Py_LIMITED_API)))]
44
use std::os::raw::c_char;
55
use std::os::raw::c_int;
66

@@ -23,3 +23,11 @@ extern "C" {
2323
#[cfg_attr(PyPy, link_name = "_PyPyBytes_Resize")]
2424
pub fn _PyBytes_Resize(bytes: *mut *mut PyObject, newsize: Py_ssize_t) -> c_int;
2525
}
26+
27+
#[inline]
28+
pub unsafe fn PyBytes_AS_STRING(op: *mut PyObject) -> *const c_char {
29+
#[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))]
30+
return &(*op.cast::<PyBytesObject>()).ob_sval as *const c_char;
31+
#[cfg(any(PyPy, GraalPy, Py_LIMITED_API))]
32+
return crate::PyBytes_AsString(op);
33+
}

0 commit comments

Comments
 (0)