Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: remove private _Py symbols from pyo3-ffi #4379

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions pyo3-ffi/src/abstract_.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::object::*;
use crate::pyport::Py_ssize_t;
#[cfg(any(Py_3_12, all(Py_3_9, not(Py_LIMITED_API))))]
use libc::size_t;
use std::os::raw::{c_char, c_int};

#[inline]
Expand Down Expand Up @@ -47,22 +49,6 @@ extern "C" {
...
) -> *mut PyObject;

#[cfg(not(Py_3_13))]
#[cfg_attr(PyPy, link_name = "_PyPyObject_CallFunction_SizeT")]
pub fn _PyObject_CallFunction_SizeT(
callable_object: *mut PyObject,
format: *const c_char,
...
) -> *mut PyObject;
#[cfg(not(Py_3_13))]
#[cfg_attr(PyPy, link_name = "_PyPyObject_CallMethod_SizeT")]
pub fn _PyObject_CallMethod_SizeT(
o: *mut PyObject,
method: *const c_char,
format: *const c_char,
...
) -> *mut PyObject;

#[cfg_attr(PyPy, link_name = "PyPyObject_CallFunctionObjArgs")]
pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyObject_CallMethodObjArgs")]
Expand All @@ -71,6 +57,41 @@ extern "C" {
method: *mut PyObject,
...
) -> *mut PyObject;

#[cfg(all(Py_3_12, Py_LIMITED_API))] // used as a function on the stable abi
pub fn PyVectorcall_NARGS(nargsf: libc::size_t) -> Py_ssize_t;

#[cfg(any(Py_3_12, all(Py_3_9, not(Py_LIMITED_API))))]
#[cfg_attr(PyPy, link_name = "PyPyVectorcall_Call")]
pub fn PyVectorcall_Call(
callable: *mut PyObject,
tuple: *mut PyObject,
dict: *mut PyObject,
) -> *mut PyObject;
}

#[cfg(Py_3_12)]
pub const PY_VECTORCALL_ARGUMENTS_OFFSET: size_t =
1 << (8 * std::mem::size_of::<size_t>() as size_t - 1);

extern "C" {
#[cfg_attr(Py_3_9, link_name = "PyPyObject_Vectorcall")]
#[cfg(any(Py_3_12, all(Py_3_9, not(Py_LIMITED_API))))]
pub fn PyObject_Vectorcall(
callable: *mut PyObject,
args: *const *mut PyObject,
nargsf: size_t,
kwnames: *mut PyObject,
) -> *mut PyObject;

#[cfg(any(Py_3_12, all(Py_3_9, not(any(Py_LIMITED_API, PyPy, GraalPy)))))]
pub fn PyObject_VectorcallMethod(
name: *mut PyObject,
args: *const *mut PyObject,
nargsf: size_t,
kwnames: *mut PyObject,
) -> *mut PyObject;

#[cfg_attr(PyPy, link_name = "PyPyObject_Type")]
pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyObject_Size")]
Expand Down
1 change: 0 additions & 1 deletion pyo3-ffi/src/ceval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ extern "C" {
pub fn Py_SetRecursionLimit(arg1: c_int);
#[cfg_attr(PyPy, link_name = "PyPy_GetRecursionLimit")]
pub fn Py_GetRecursionLimit() -> c_int;
fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int;
}

extern "C" {
Expand Down
14 changes: 5 additions & 9 deletions pyo3-ffi/src/codecs.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::object::PyObject;
use std::os::raw::{c_char, c_int};

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyCodec_Register(search_function: *mut PyObject) -> c_int;
#[cfg(Py_3_10)]
#[cfg(not(PyPy))]
pub fn PyCodec_Unregister(search_function: *mut PyObject) -> c_int;
// skipped non-limited _PyCodec_Lookup from Include/codecs.h
// skipped non-limited _PyCodec_Forget from Include/codecs.h
pub fn PyCodec_KnownEncoding(encoding: *const c_char) -> c_int;
pub fn PyCodec_Encode(
object: *mut PyObject,
Expand All @@ -19,11 +18,6 @@ extern "C" {
encoding: *const c_char,
errors: *const c_char,
) -> *mut PyObject;
// skipped non-limited _PyCodec_LookupTextEncoding from Include/codecs.h
// skipped non-limited _PyCodec_EncodeText from Include/codecs.h
// skipped non-limited _PyCodec_DecodeText from Include/codecs.h
// skipped non-limited _PyCodecInfo_GetIncrementalDecoder from Include/codecs.h
// skipped non-limited _PyCodecInfo_GetIncrementalEncoder from Include/codecs.h
pub fn PyCodec_Encoder(encoding: *const c_char) -> *mut PyObject;
pub fn PyCodec_Decoder(encoding: *const c_char) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyCodec_IncrementalEncoder")]
Expand Down Expand Up @@ -53,6 +47,8 @@ extern "C" {
pub fn PyCodec_ReplaceErrors(exc: *mut PyObject) -> *mut PyObject;
pub fn PyCodec_XMLCharRefReplaceErrors(exc: *mut PyObject) -> *mut PyObject;
pub fn PyCodec_BackslashReplaceErrors(exc: *mut PyObject) -> *mut PyObject;
// skipped non-limited PyCodec_NameReplaceErrors from Include/codecs.h
// skipped non-limited Py_hexdigits from Include/codecs.h
pub fn PyCodec_NameReplaceErrors(exc: *mut PyObject) -> *mut PyObject;

#[cfg(not(Py_LIMITED_API))]
pub static mut Py_hexdigits: *const c_char;
}
34 changes: 1 addition & 33 deletions pyo3-ffi/src/complexobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,6 @@ use crate::object::*;
use std::os::raw::{c_double, c_int};
use std::ptr::addr_of_mut;

#[repr(C)]
#[derive(Copy, Clone)]
// non-limited
pub struct Py_complex {
pub real: c_double,
pub imag: c_double,
}

#[cfg(not(Py_LIMITED_API))]
extern "C" {
pub fn _Py_c_sum(left: Py_complex, right: Py_complex) -> Py_complex;
pub fn _Py_c_diff(left: Py_complex, right: Py_complex) -> Py_complex;
pub fn _Py_c_neg(complex: Py_complex) -> Py_complex;
pub fn _Py_c_prod(left: Py_complex, right: Py_complex) -> Py_complex;
pub fn _Py_c_quot(dividend: Py_complex, divisor: Py_complex) -> Py_complex;
pub fn _Py_c_pow(num: Py_complex, exp: Py_complex) -> Py_complex;
pub fn _Py_c_abs(arg: Py_complex) -> c_double;
#[cfg_attr(PyPy, link_name = "PyPyComplex_FromCComplex")]
pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyComplex_AsCComplex")]
pub fn PyComplex_AsCComplex(op: *mut PyObject) -> Py_complex;
}

#[repr(C)]
// non-limited
pub struct PyComplexObject {
pub ob_base: PyObject,
#[cfg(not(GraalPy))]
pub cval: Py_complex,
}

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyComplex_Type")]
Expand All @@ -53,10 +22,9 @@ extern "C" {
// skipped non-limited PyComplex_FromCComplex
#[cfg_attr(PyPy, link_name = "PyPyComplex_FromDoubles")]
pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject;

#[cfg_attr(PyPy, link_name = "PyPyComplex_RealAsDouble")]
pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double;
#[cfg_attr(PyPy, link_name = "PyPyComplex_ImagAsDouble")]
pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double;
// skipped non-limited PyComplex_AsCComplex
// skipped non-limited _PyComplex_FormatAdvancedWriter
}
Loading
Loading