Skip to content

Commit

Permalink
ffi: many fixes to pypy definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Jun 4, 2022
1 parent 0d78e88 commit 1141326
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 94 deletions.
4 changes: 3 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 Down Expand Up @@ -47,7 +48,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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. [#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(all(Py_3_8, not(Py_3_11)))]
#[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};
#[cfg(not(any(PyPy, Py_3_11)))]
use std::os::raw::c_char;
use std::os::raw::c_int;

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

#[repr(C)]
#[derive(Copy, Clone)]
#[cfg(not(Py_3_11))]
#[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
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
18 changes: 9 additions & 9 deletions pyo3-ffi/src/cpython/pythonrun.rs
@@ -1,8 +1,8 @@
use crate::object::*;
#[cfg(all(not(Py_LIMITED_API), not(Py_3_10)))]
#[cfg(not(any(PyPy, Py_LIMITED_API, Py_3_10)))]
use crate::pyarena::PyArena;
use crate::PyCompilerFlags;
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
use crate::{_mod, _node};
use libc::FILE;
use std::os::raw::{c_char, c_int};
Expand Down Expand Up @@ -54,23 +54,23 @@ extern "C" {
flags: *mut PyCompilerFlags,
) -> c_int;

#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
pub fn PyParser_ASTFromString(
s: *const c_char,
filename: *const c_char,
start: c_int,
flags: *mut PyCompilerFlags,
arena: *mut PyArena,
) -> *mut _mod;
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
pub fn PyParser_ASTFromStringObject(
s: *const c_char,
filename: *mut PyObject,
start: c_int,
flags: *mut PyCompilerFlags,
arena: *mut PyArena,
) -> *mut _mod;
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
pub fn PyParser_ASTFromFile(
fp: *mut FILE,
filename: *const c_char,
Expand All @@ -82,7 +82,7 @@ extern "C" {
errcode: *mut c_int,
arena: *mut PyArena,
) -> *mut _mod;
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
pub fn PyParser_ASTFromFileObject(
fp: *mut FILE,
filename: *mut PyObject,
Expand Down Expand Up @@ -218,22 +218,22 @@ extern "C" {
// skipped macro PyRun_AnyFileFlags

extern "C" {
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
#[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))]
pub fn PyParser_SimpleParseStringFlags(
arg1: *const c_char,
arg2: c_int,
arg3: c_int,
) -> *mut _node;
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
#[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))]
pub fn PyParser_SimpleParseStringFlagsFilename(
arg1: *const c_char,
arg2: *const c_char,
arg3: c_int,
arg4: c_int,
) -> *mut _node;
#[cfg(not(Py_3_10))]
#[cfg(not(any(PyPy, Py_3_10)))]
#[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))]
pub fn PyParser_SimpleParseFileFlags(
arg1: *mut FILE,
Expand Down

0 comments on commit 1141326

Please sign in to comment.