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

ffi: another batch of fixes from pyo3-ffi-check #2428

Merged
merged 2 commits into from Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add FFI definition `PyFrame_GetCode`. [#2406](https://github.com/PyO3/pyo3/pull/2406)
- Added `PyCode` and `PyFrame` high level objects. [#2408](https://github.com/PyO3/pyo3/pull/2408)
- Add FFI definitions `Py_fstring_input`, `sendfunc`, and `_PyErr_StackItem`. [#2423](https://github.com/PyO3/pyo3/pull/2423)
- Add `PyDateTime::new_with_fold`, `PyTime::new_with_fold`, `PyTime::get_fold`, `PyDateTime::get_fold` for PyPy. [#2428](https://github.com/PyO3/pyo3/pull/2428)

### Changed

Expand All @@ -39,14 +40,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Correct FFI definition `Py_tracefunc` to be `unsafe extern "C" fn` (was previously safe). [#2407](https://github.com/PyO3/pyo3/pull/2407)
- Fix case where `ValueError` without message could be raised by the `#[derive(FromPyObject)]` generated implementation for a tuple struct. [#2414](https://github.com/PyO3/pyo3/pull/2414)
- Fix compile failure when using `#[pyo3(from_py_with = "pouf")]` in on a field in a `#[derive(FromPyObject)]` struct. [#2414](https://github.com/PyO3/pyo3/pull/2414)
- Fix FFI definitions `_PyDateTime_BaseTime` lacking leading underscores in their names. [#2421](https://github.com/PyO3/pyo3/pull/2421)
- Fix FFI definitions `_PyDateTime_BaseTime` and `_PyDateTime_BaseDateTime` lacking leading underscores in their names. [#2421](https://github.com/PyO3/pyo3/pull/2421)
- Remove FFI definition `PyArena` on Python 3.10 and up. [#2421](https://github.com/PyO3/pyo3/pull/2421)
- Fix FFI definition `PyCompilerFlags` missing member `cf_feature_version` on Python 3.8 and up. [#2423](https://github.com/PyO3/pyo3/pull/2423)
- Fix FFI definition `PyAsyncMethods` missing member `am_send` on Python 3.10 and up. [#2423](https://github.com/PyO3/pyo3/pull/2423)
- Fix FFI definition `PyGenObject` having multiple incorrect members on various Python versions. [#2423](https://github.com/PyO3/pyo3/pull/2423)
- Fix FFI definition `PySyntaxErrorObject` missing members `end_lineno` and `end_offset` on Python 3.10 and up. [#2423](https://github.com/PyO3/pyo3/pull/2423)
- Fix FFI definition `PyHeapTypeObject` missing member `ht_module` on Python 3.9 and up. [#2423](https://github.com/PyO3/pyo3/pull/2423)
- Fix FFI definition `PyFrameObject` having multiple incorrect members on various Python versions. [#2424](https://github.com/PyO3/pyo3/pull/2424)
- Fix FFI definition `PyTypeObject` missing deprecated field `tp_print` on Python 3.8. [#2428](https://github.com/PyO3/pyo3/pull/2428)
- Fix FFI definitions `PyDateTime_CAPI`. `PyDateTime_Date`, `PyASCIIObject`, `PyBaseExceptionObject`, `PyListObject`, and `PyTypeObject` on PyPy. [#2428](https://github.com/PyO3/pyo3/pull/2428)

## [0.16.5] - 2022-05-15

Expand Down
10 changes: 8 additions & 2 deletions pyo3-ffi/src/cpython/code.rs
@@ -1,14 +1,17 @@
use crate::object::*;
use crate::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int, c_uchar, c_void};
#[cfg(not(PyPy))]
use std::os::raw::c_uchar;
use std::os::raw::{c_char, c_int, c_void};

// skipped _Py_CODEUNIT
// skipped _Py_OPCODE
// skipped _Py_OPARG

#[cfg(Py_3_8)]
#[cfg(all(Py_3_8, not(PyPy)))]
opaque_struct!(_PyOpcache);

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyCodeObject {
Expand Down Expand Up @@ -44,6 +47,9 @@ pub struct PyCodeObject {
pub co_opcache_size: c_uchar,
}

#[cfg(PyPy)]
opaque_struct!(PyCodeObject);

/* Masks for co_flags */
pub const CO_OPTIMIZED: c_int = 0x0001;
pub const CO_NEWLOCALS: c_int = 0x0002;
Expand Down
21 changes: 11 additions & 10 deletions pyo3-ffi/src/cpython/compile.rs
@@ -1,12 +1,12 @@
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
use crate::object::PyObject;
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
use crate::pyarena::*;
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
use crate::pythonrun::*;
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
use crate::PyCodeObject;
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
use std::os::raw::c_char;
use std::os::raw::c_int;

Expand All @@ -30,6 +30,7 @@ pub struct PyCompilerFlags {

// skipped non-limited _PyCompilerFlags_INIT

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyFutureFeatures {
Expand All @@ -49,10 +50,10 @@ pub const FUTURE_GENERATOR_STOP: &str = "generator_stop";
// skipped non-limited FUTURE_ANNOTATIONS

extern "C" {
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
pub fn PyNode_Compile(arg1: *mut _node, arg2: *const c_char) -> *mut PyCodeObject;

#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
pub fn PyAST_CompileEx(
_mod: *mut _mod,
filename: *const c_char,
Expand All @@ -61,7 +62,7 @@ extern "C" {
arena: *mut PyArena,
) -> *mut PyCodeObject;

#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
pub fn PyAST_CompileObject(
_mod: *mut _mod,
filename: *mut PyObject,
Expand All @@ -70,10 +71,10 @@ extern "C" {
arena: *mut PyArena,
) -> *mut PyCodeObject;

#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
pub fn PyFuture_FromAST(_mod: *mut _mod, filename: *const c_char) -> *mut PyFutureFeatures;

#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
pub fn PyFuture_FromASTObject(
_mod: *mut _mod,
filename: *mut PyObject,
Expand Down
13 changes: 8 additions & 5 deletions pyo3-ffi/src/cpython/frameobject.rs
@@ -1,14 +1,16 @@
use crate::cpython::code::PyCodeObject;
use crate::object::*;
use crate::pystate::PyThreadState;
use std::os::raw::{c_char, c_int};

// skipped _framestate
#[cfg(not(any(PyPy, Py_3_11)))]
use std::os::raw::c_char;
use std::os::raw::c_int;

#[cfg(not(any(PyPy, Py_3_11)))]
pub type PyFrameState = c_char;

#[repr(C)]
#[derive(Copy, Clone)]
#[cfg(not(any(PyPy, Py_3_11)))]
pub struct PyTryBlock {
pub b_type: c_int,
pub b_handler: c_int,
Expand All @@ -17,7 +19,7 @@ pub struct PyTryBlock {

#[repr(C)]
#[derive(Copy, Clone)]
#[cfg(not(Py_3_11))]
#[cfg(not(any(PyPy, Py_3_11)))]
pub struct PyFrameObject {
pub ob_base: PyVarObject,
pub f_back: *mut PyFrameObject,
Expand Down Expand Up @@ -46,7 +48,7 @@ pub struct PyFrameObject {
pub f_localsplus: [*mut PyObject; 1],
}

#[cfg(Py_3_11)]
#[cfg(any(PyPy, Py_3_11))]
opaque_struct!(PyFrameObject);

// skipped _PyFrame_IsRunnable
Expand Down Expand Up @@ -74,6 +76,7 @@ extern "C" {
// skipped _PyFrame_New_NoTrack

pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int);
#[cfg(not(any(PyPy, Py_3_11)))]
pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock;

pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int);
Expand Down
8 changes: 5 additions & 3 deletions pyo3-ffi/src/cpython/genobject.rs
@@ -1,8 +1,10 @@
use crate::object::*;
use crate::pyport::Py_ssize_t;
use crate::{PyFrameObject, _PyErr_StackItem};
use crate::PyFrameObject;
#[cfg(not(PyPy))]
use crate::{Py_ssize_t, _PyErr_StackItem};
use std::os::raw::c_int;

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyGenObject {
Expand Down Expand Up @@ -44,7 +46,7 @@ extern "C" {
// skipped _PyGen_FetchStopIterationValue
// skipped _PyGen_yf
// skipped _PyGen_Finalize
#[cfg(not(Py_3_9))]
#[cfg(not(any(Py_3_9, PyPy)))]
#[deprecated(note = "This function was never documented in the Python API.")]
pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int;
}
Expand Down
9 changes: 8 additions & 1 deletion pyo3-ffi/src/cpython/import.rs
@@ -1,5 +1,7 @@
use crate::{PyInterpreterState, PyObject};
use std::os::raw::{c_char, c_int, c_uchar};
#[cfg(not(PyPy))]
use std::os::raw::c_uchar;
use std::os::raw::{c_char, c_int};

// skipped PyInit__imp

Expand Down Expand Up @@ -27,6 +29,7 @@ extern "C" {
) -> c_int;
}

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct _inittab {
Expand All @@ -36,13 +39,16 @@ pub struct _inittab {

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
#[cfg(not(PyPy))]
pub static mut PyImport_Inittab: *mut _inittab;
}

extern "C" {
#[cfg(not(PyPy))]
pub fn PyImport_ExtendInittab(newtab: *mut _inittab) -> c_int;
}

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct _frozen {
Expand All @@ -53,5 +59,6 @@ pub struct _frozen {

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
#[cfg(not(PyPy))]
pub static mut PyImport_FrozenModules: *const _frozen;
}
7 changes: 7 additions & 0 deletions pyo3-ffi/src/cpython/listobject.rs
@@ -1,6 +1,8 @@
use crate::object::*;
#[cfg(not(PyPy))]
use crate::pyport::Py_ssize_t;

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyListObject {
Expand All @@ -9,6 +11,11 @@ pub struct PyListObject {
pub allocated: Py_ssize_t,
}

#[cfg(PyPy)]
pub struct PyListObject {
pub ob_base: PyObject,
}

// skipped _PyList_Extend
// skipped _PyList_DebugMallocStats
// skipped _PyList_CAST (used inline below)
Expand Down
2 changes: 2 additions & 0 deletions pyo3-ffi/src/cpython/object.rs
Expand Up @@ -276,6 +276,8 @@ pub struct PyTypeObject {
pub tp_finalize: Option<object::destructor>,
#[cfg(Py_3_8)]
pub tp_vectorcall: Option<super::vectorcallfunc>,
#[cfg(all(Py_3_8, not(Py_3_9)))]
pub tp_print: Option<printfunc>,
#[cfg(PyPy)]
pub tp_pypy_flags: std::os::raw::c_long,
#[cfg(py_sys_config = "COUNT_ALLOCS")]
Expand Down
15 changes: 14 additions & 1 deletion pyo3-ffi/src/cpython/pyerrors.rs
@@ -1,17 +1,26 @@
use crate::{PyObject, Py_ssize_t};
use crate::PyObject;
#[cfg(not(PyPy))]
use crate::Py_ssize_t;

#[repr(C)]
#[derive(Debug)]
pub struct PyBaseExceptionObject {
pub ob_base: PyObject,
#[cfg(not(PyPy))]
pub dict: *mut PyObject,
#[cfg(not(PyPy))]
pub args: *mut PyObject,
#[cfg(not(PyPy))]
pub traceback: *mut PyObject,
#[cfg(not(PyPy))]
pub context: *mut PyObject,
#[cfg(not(PyPy))]
pub cause: *mut PyObject,
#[cfg(not(PyPy))]
pub suppress_context: char,
}

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Debug)]
pub struct PySyntaxErrorObject {
Expand All @@ -28,6 +37,7 @@ pub struct PySyntaxErrorObject {
pub print_file_and_line: *mut PyObject,
}

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Debug)]
pub struct PyImportErrorObject {
Expand All @@ -37,6 +47,7 @@ pub struct PyImportErrorObject {
pub path: *mut PyObject,
}

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Debug)]
pub struct PyUnicodeErrorObject {
Expand All @@ -48,13 +59,15 @@ pub struct PyUnicodeErrorObject {
pub reason: *mut PyObject,
}

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Debug)]
pub struct PySystemExitObject {
pub exception_base: PyBaseExceptionObject,
pub code: *mut PyObject,
}

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Debug)]
pub struct PyOSErrorObject {
Expand Down
5 changes: 4 additions & 1 deletion pyo3-ffi/src/cpython/pymem.rs
Expand Up @@ -26,7 +26,7 @@ pub enum PyMemAllocatorDomain {
}

// skipped PyMemAllocatorName

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyMemAllocatorEx {
Expand All @@ -40,7 +40,10 @@ pub struct PyMemAllocatorEx {
}

extern "C" {
#[cfg(not(PyPy))]
pub fn PyMem_GetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx);
#[cfg(not(PyPy))]
pub fn PyMem_SetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx);
#[cfg(not(PyPy))]
pub fn PyMem_SetupDebugHooks();
}
1 change: 1 addition & 0 deletions pyo3-ffi/src/cpython/pystate.rs
Expand Up @@ -27,6 +27,7 @@ pub const PyTrace_OPCODE: c_int = 7;
// skipped PyTraceInfo
// skipped CFrame

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Clone, Copy)]
pub struct _PyErr_StackItem {
Expand Down