Skip to content

Commit

Permalink
Merge #3031
Browse files Browse the repository at this point in the history
3031: mangle exported functions for PyPy r=davidhewitt a=mattip

I run HEAD of PyO3 with HEAD of some PyPy branches, and noticed that the py3.10 branch (which implements python3.10) [fails to properly build](https://github.com/pypy/binary-testing/actions/runs/4334873617/jobs/7569059852#step:6:179). The failure was a missing export:
```
 /home/runner/work/binary-testing/binary-testing/pyo3/src/exceptions.rs:715: \
    undefined reference to `PyExc_EncodingWarning'
          collect2: error: ld returned 1 exit status
```

So I grepped around in the code for `Py_3_10` to see what new functions were added and found a few that needed PyPy-specific exports.

Co-authored-by: Matti Picus <[email protected]>
  • Loading branch information
bors[bot] and mattip authored Mar 10, 2023
2 parents b8bf93b + 232f9fb commit 2e0bde0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions newsfragments/3031.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mangle exported function names for PyPy
2 changes: 2 additions & 0 deletions pyo3-ffi/src/abstract_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern "C" {
not(PyPy),
any(Py_3_10, all(not(Py_LIMITED_API), Py_3_9)) // Added to python in 3.9 but to limited API in 3.10
))]
#[cfg_attr(PyPy, link_name = "PyPyObject_CallNoArgs")]
pub fn PyObject_CallNoArgs(func: *mut PyObject) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyObject_Call")]
pub fn PyObject_Call(
Expand Down Expand Up @@ -113,6 +114,7 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyIter_Next")]
pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject;
#[cfg(all(not(PyPy), Py_3_10))]
#[cfg_attr(PyPy, link_name = "PyPyIter_Send")]
pub fn PyIter_Send(iter: *mut PyObject, arg: *mut PyObject, presult: *mut *mut PyObject);

#[cfg_attr(PyPy, link_name = "PyPyNumber_Check")]
Expand Down
1 change: 1 addition & 0 deletions pyo3-ffi/src/modsupport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern "C" {
// skipped non-limited _PyArg_Fini

#[cfg(Py_3_10)]
#[cfg_attr(PyPy, link_name = "PyPyModule_AddObjectRef")]
pub fn PyModule_AddObjectRef(
module: *mut PyObject,
name: *const c_char,
Expand Down
3 changes: 3 additions & 0 deletions pyo3-ffi/src/objimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ extern "C" {
pub fn PyGC_Collect() -> Py_ssize_t;

#[cfg(Py_3_10)]
#[cfg_attr(PyPy, link_name = "PyPyGC_Enable")]
pub fn PyGC_Enable() -> c_int;

#[cfg(Py_3_10)]
#[cfg_attr(PyPy, link_name = "PyPyGC_Disable")]
pub fn PyGC_Disable() -> c_int;

#[cfg(Py_3_10)]
#[cfg_attr(PyPy, link_name = "PyPyGC_IsEnabled")]
pub fn PyGC_IsEnabled() -> c_int;
}

Expand Down
5 changes: 5 additions & 0 deletions pyo3-ffi/src/pyerrors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyExc_ResourceWarning")]
pub static mut PyExc_ResourceWarning: *mut PyObject;
#[cfg(Py_3_10)]
#[cfg_attr(PyPy, link_name = "PyPyExc_EncodingWarning")]
pub static mut PyExc_EncodingWarning: *mut PyObject;
}

Expand Down Expand Up @@ -305,9 +306,13 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyErr_SetInterrupt")]
pub fn PyErr_SetInterrupt();
#[cfg(Py_3_10)]
#[cfg_attr(PyPy, link_name = "PyPyErr_SetInterruptEx")]
pub fn PyErr_SetInterruptEx(signum: c_int);
#[cfg_attr(PyPy, link_name = "PyPyErr_SyntaxLocation")]
pub fn PyErr_SyntaxLocation(filename: *const c_char, lineno: c_int);
#[cfg_attr(PyPy, link_name = "PyPyErr_SyntaxLocationEx")]
pub fn PyErr_SyntaxLocationEx(filename: *const c_char, lineno: c_int, col_offset: c_int);
#[cfg_attr(PyPy, link_name = "PyPyErr_ProgramText")]
pub fn PyErr_ProgramText(filename: *const c_char, lineno: c_int) -> *mut PyObject;
#[cfg(not(PyPy))]
pub fn PyUnicodeDecodeError_Create(
Expand Down

0 comments on commit 2e0bde0

Please sign in to comment.