Skip to content
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ chrono-local = ["chrono/clock", "dep:iana-time-zone"]


# Optimizes PyObject to Vec conversion and so on.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is now well out of date, let's re-write this to just link to https://pyo3.rs/latest/features#nightly

At the same time, please can we update the description of the nightly feature in features.md to include this? It is also possible there are other features in nightly missing from that description, I am not sure either way.

nightly = []
nightly = ["pyo3-ffi/nightly"]

# Activates all additional features
# This is mostly intended for testing purposes - activating *all* of these isn't particularly useful.
Expand Down
1 change: 1 addition & 0 deletions newsfragments/5789.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `c_variadic` bindings to `pyo3-ffi` on `nightly`.
3 changes: 3 additions & 0 deletions pyo3-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ libc = "0.2.62"

default = []

# Add support for va_list based apis on nightly Rust.
nightly = []

# deprecated
extension-module = ["pyo3-build-config/extension-module"]

Expand Down
8 changes: 4 additions & 4 deletions pyo3-ffi/src/bytesobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ extern "C" {
pub fn PyBytes_FromString(arg1: *const c_char) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyBytes_FromObject")]
pub fn PyBytes_FromObject(arg1: *mut PyObject) -> *mut PyObject;
// skipped PyBytes_FromFormatV
//#[cfg_attr(PyPy, link_name = "PyPyBytes_FromFormatV")]
//pub fn PyBytes_FromFormatV(arg1: *const c_char, arg2: va_list)
// -> *mut PyObject;
#[cfg(feature = "nightly")]
#[cfg_attr(PyPy, link_name = "PyPyBytes_FromFormatV")]
pub fn PyBytes_FromFormatV(format: *const c_char, vargs: std::ffi::VaList<'_>)
-> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyBytes_FromFormat")]
pub fn PyBytes_FromFormat(arg1: *const c_char, ...) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyBytes_Size")]
Expand Down
1 change: 1 addition & 0 deletions pyo3-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(feature = "nightly", feature(c_variadic))]
#![cfg_attr(docsrs, feature(doc_cfg))]
//! Raw FFI declarations for Python's C API.
//!
Expand Down
36 changes: 27 additions & 9 deletions pyo3-ffi/src/modsupport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,32 @@ extern "C" {
pub fn PyArg_ParseTuple(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int;
#[cfg_attr(PyPy, link_name = "PyPyArg_ParseTupleAndKeywords")]
pub fn PyArg_ParseTupleAndKeywords(
arg1: *mut PyObject,
arg2: *mut PyObject,
arg3: *const c_char,
#[cfg(not(Py_3_13))] arg4: *mut *mut c_char,
#[cfg(Py_3_13)] arg4: *const *const c_char,
args: *mut PyObject,
kw: *mut PyObject,
format: *const c_char,
#[cfg(not(Py_3_13))] keywords: *mut *mut c_char,
#[cfg(Py_3_13)] keywords: *const *const c_char,
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now confused, isn't this a variadic function declared on stable Rust? 😖

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused as well, but there is a clear difference in the signature. I'm not 100% fluent on this part of C I'm afraid.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are currently no plans for an api to create VaList's on the rust side. So these bindings are not useful without some c code calling into rust. That in mind, do we still want to move forward with this MR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you are correct, so I think we should unconditionally skip all FFI declarations taking VaList for now.

It looks like this MR cleans up some names on the variadic ... functions but doesn't add new ones. I'm open to proceeding with just those name cleanups, I guess we don't need the nightly feature stuff now.

(I wonder if we should add a Contributing.md inside pyo3-ffi with notes for ourselves on these kinds of details about what we do / do not support?)

) -> c_int;

// skipped PyArg_VaParse
// skipped PyArg_VaParseTupleAndKeywords
#[cfg(feature = "nightly")]
#[cfg_attr(PyPy, link_name = "PyPyArg_VaParse")]
pub fn PyArg_VaParse(
args: *mut PyObject,
format: *const c_char,
vargs: std::ffi::VaList<'_>,
) -> c_int;

#[cfg(feature = "nightly")]
#[cfg_attr(PyPy, link_name = "PyPyArg_VaParseTupleAndKeywords")]
pub fn PyArg_VaParseTupleAndKeywords(
args: *mut PyObject,
kw: *mut PyObject,
format: *const c_char,
#[cfg(not(Py_3_13))] keywords: *mut *mut c_char,
#[cfg(Py_3_13)] keywords: *const *const c_char,
vargs: std::ffi::VaList<'_>,
) -> c_int;

pub fn PyArg_ValidateKeywordArguments(arg1: *mut PyObject) -> c_int;
#[cfg_attr(PyPy, link_name = "PyPyArg_UnpackTuple")]
Expand All @@ -33,8 +49,10 @@ extern "C" {
) -> c_int;

#[cfg_attr(PyPy, link_name = "PyPy_BuildValue")]
pub fn Py_BuildValue(arg1: *const c_char, ...) -> *mut PyObject;
// skipped Py_VaBuildValue
pub fn Py_BuildValue(format: *const c_char, ...) -> *mut PyObject;
#[cfg(feature = "nightly")]
#[cfg_attr(PyPy, link_name = "PyPy_VaBuildValue")]
pub fn Py_VaBuildValue(format: *const c_char, vargs: std::ffi::VaList<'_>) -> *mut PyObject;

#[cfg(Py_3_13)]
pub fn PyModule_Add(module: *mut PyObject, name: *const c_char, value: *mut PyObject) -> c_int;
Expand Down
8 changes: 6 additions & 2 deletions pyo3-ffi/src/unicodeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ extern "C" {
) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")]
pub fn PyUnicode_FromObject(obj: *mut PyObject) -> *mut PyObject;
// #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromFormatV")]
// pub fn PyUnicode_FromFormatV(format: *const c_char, vargs: va_list) -> *mut PyObject;
#[cfg(feature = "nightly")]
#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromFormatV")]
pub fn PyUnicode_FromFormatV(
format: *const c_char,
vargs: std::ffi::VaList<'_>,
) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromFormat")]
pub fn PyUnicode_FromFormat(format: *const c_char, ...) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyUnicode_InternInPlace")]
Expand Down
Loading