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 module cleanup: context.h to frameobject.h #1341

Merged
merged 16 commits into from
Dec 28, 2020
Merged
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Deprecate FFI definition `PyCoro_Check` and `PyAsyncGen_Check` in favor of `PyCoro_CheckExact` and `PyAsyncGen_CheckExact` respectively, as these are the correct name in the Python headers. [#1341](https://github.com/PyO3/pyo3/pull/1341)
nw0 marked this conversation as resolved.
Show resolved Hide resolved
- Deprecate FFI definition `PyCoroWrapper_Check` and `PyGetSetDef_DICT` which have never been defined in the Python headers. [#1341](https://github.com/PyO3/pyo3/pull/1341)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also PyGetSetDef_INIT?

- Deprecate FFI definition `PyImport_Cleanup`, which was removed in 3.9 and previously marked "for internal use only". [#1341](https://github.com/PyO3/pyo3/pull/1341)
- Deprecate FFI definition `PyOS_InitInterrupts`, which was removed in 3.10 and previously undocumented. [#1341](https://github.com/PyO3/pyo3/pull/1341)
nw0 marked this conversation as resolved.
Show resolved Hide resolved
- Deprecate FFI definition `PyOS_AfterFork`; introduce `PyOS_BeforeFork`, `PyOS_AfterFork_Parent`, `PyOS_AfterFork_Child` when building for Python 3.7. [#1341](https://github.com/PyO3/pyo3/pull/1341)
Copy link
Member

Choose a reason for hiding this comment

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

The new methods should be in the Added section please :)

- Deprecate FFI definitions `PyEval_CallObjectWithKeywords`, `PyEval_CallObject`, `PyEval_CallFunction`, `PyEval_CallMethod` when building for Python 3.9. [#1338](https://github.com/PyO3/pyo3/pull/1338)
davidhewitt marked this conversation as resolved.
Show resolved Hide resolved

### Removed
- Remove FFI definition `PyImport_cleanup` when building for Python 3.9 or later, to mirror Python headers. [#1341](https://github.com/PyO3/pyo3/pull/1341)
- Remove FFI definition `PyOS_InitInterrupts` when building for Python 3.10 or later, to mirror Python headers. [#1341](https://github.com/PyO3/pyo3/pull/1341)
Copy link
Member

Choose a reason for hiding this comment

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

I think no need for these points in Removed because you've already mentioned the respective functions in Changed.


### Fixed
- Stop including `Py_TRACE_REFS` config setting automatically if `Py_DEBUG` is set on Python 3.8 and up. [#1334](https://github.com/PyO3/pyo3/pull/1334)
- Remove `#[deny(warnings)]` attribute (and instead refuse warnings only in CI). [#1340](https://github.com/PyO3/pyo3/pull/1340)
- Deprecate FFI definitions `PyEval_CallObjectWithKeywords`, `PyEval_CallObject`, `PyEval_CallFunction`, `PyEval_CallMethod` when building for Python 3.9. [#1338](https://github.com/PyO3/pyo3/pull/1338)
- Fix deprecation warning for missing `__module__` with `#[pyclass]`. [#1343](https://github.com/PyO3/pyo3/pull/1343)

## [0.13.0] - 2020-12-22
Expand Down
35 changes: 22 additions & 13 deletions src/ffi/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@ use std::os::raw::{c_char, c_int};

extern "C" {
pub static mut PyContext_Type: PyTypeObject;
// skipped non-limited opaque PyContext
pub static mut PyContextVar_Type: PyTypeObject;
// skipped non-limited opaque PyContextVar
pub static mut PyContextToken_Type: PyTypeObject;
pub fn PyContext_New() -> *mut PyObject;
pub fn PyContext_Copy(ctx: *mut PyObject) -> *mut PyObject;
pub fn PyContext_CopyCurrent() -> *mut PyObject;
pub fn PyContext_Enter(ctx: *mut PyObject) -> c_int;
pub fn PyContext_Exit(ctx: *mut PyObject) -> c_int;
pub fn PyContextVar_New(name: *const c_char, def: *mut PyObject) -> *mut PyObject;
pub fn PyContextVar_Get(
var: *mut PyObject,
default_value: *mut PyObject,
value: *mut *mut PyObject,
) -> c_int;
pub fn PyContextVar_Set(var: *mut PyObject, value: *mut PyObject) -> *mut PyObject;
pub fn PyContextVar_Reset(var: *mut PyObject, token: *mut PyObject) -> c_int;
// skipped non-limited opaque PyContextToken
davidhewitt marked this conversation as resolved.
Show resolved Hide resolved
}

#[inline]
Expand All @@ -34,3 +24,22 @@ pub unsafe fn PyContextVar_CheckExact(op: *mut PyObject) -> c_int {
pub unsafe fn PyContextToken_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyContextToken_Type) as c_int
}

extern "C" {
pub fn PyContext_New() -> *mut PyObject;
pub fn PyContext_Copy(ctx: *mut PyObject) -> *mut PyObject;
pub fn PyContext_CopyCurrent() -> *mut PyObject;

pub fn PyContext_Enter(ctx: *mut PyObject) -> c_int;
pub fn PyContext_Exit(ctx: *mut PyObject) -> c_int;

pub fn PyContextVar_New(name: *const c_char, def: *mut PyObject) -> *mut PyObject;
pub fn PyContextVar_Get(
var: *mut PyObject,
default_value: *mut PyObject,
value: *mut *mut PyObject,
) -> c_int;
pub fn PyContextVar_Set(var: *mut PyObject, value: *mut PyObject) -> *mut PyObject;
pub fn PyContextVar_Reset(var: *mut PyObject, token: *mut PyObject) -> c_int;
// skipped non-limited _PyContext_NewHamtForTests
davidhewitt marked this conversation as resolved.
Show resolved Hide resolved
}
63 changes: 63 additions & 0 deletions src/ffi/cpython/dictobject.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use crate::ffi::object::*;
use crate::ffi::pyport::Py_ssize_t;
use std::os::raw::c_int;

opaque_struct!(PyDictKeysObject);

#[repr(C)]
#[derive(Debug)]
// Not moved because dict.rs uses PyDictObject extensively.
pub struct PyDictObject {
pub ob_base: PyObject,
pub ma_used: Py_ssize_t,
pub ma_version_tag: u64,
pub ma_keys: *mut PyDictKeysObject,
pub ma_values: *mut *mut PyObject,
}

extern "C" {
// skipped _PyDict_GetItem_KnownHash
// skipped _PyDict_GetItemIdWithError
// skipped _PyDict_GetItemStringWithError
// skipped PyDict_SetDefault
pub fn _PyDict_SetItem_KnownHash(
mp: *mut PyObject,
key: *mut PyObject,
item: *mut PyObject,
hash: crate::ffi::Py_hash_t,
) -> c_int;
// skipped _PyDict_DelItem_KnownHash
// skipped _PyDict_DelItemIf
// skipped _PyDict_NewKeysForClass
pub fn _PyDict_Next(
mp: *mut PyObject,
pos: *mut Py_ssize_t,
key: *mut *mut PyObject,
value: *mut *mut PyObject,
hash: *mut crate::ffi::Py_hash_t,
) -> c_int;
// skipped PyDict_GET_SIZE
// skipped _PyDict_Contains_KnownHash
// skipped _PyDict_ContainsId
pub fn _PyDict_NewPresized(minused: Py_ssize_t) -> *mut PyObject;
// skipped _PyDict_MaybeUntrack
// skipped _PyDict_HasOnlyStringKeys
// skipped _PyDict_KeysSize
// skipped _PyDict_SizeOf
// skipped _PyDict_Pop
// skipped _PyDict_Pop_KnownHash
// skipped _PyDict_FromKeys
// skipped _PyDict_HasSplitTable
// skipped _PyDict_MergeEx
// skipped _PyDict_SetItemId
// skipped _PyDict_DelItemId
// skipped _PyDict_DebugMallocStats
// skipped _PyObjectDict_SetItem
// skipped _PyDict_LoadGlobal
// skipped _PyDict_GetItemHint
// skipped _PyDictViewObject
// skipped _PyDictView_New
// skipped _PyDictView_Intersect
// FIXME: PyDict_Contains is defined in dictobject.c
Copy link
Member

Choose a reason for hiding this comment

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

huh?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops -- I was in the middle of tracking this down, will update. Basically it's removed in 3.10, but not in the Python changelog (yet).

pub fn _PyDict_Contains(mp: *mut PyObject, key: *mut PyObject, hash: Py_ssize_t) -> c_int;
}
14 changes: 13 additions & 1 deletion src/ffi/frameobject.rs → src/ffi/cpython/frameobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use crate::ffi::object::*;
use crate::ffi::pystate::PyThreadState;
use std::os::raw::{c_char, c_int};

// skipped _framestate
// skipped PyFrameState

#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyTryBlock {
Expand All @@ -11,6 +14,7 @@ pub struct PyTryBlock {
pub b_level: c_int,
}

/// struct _frame as typedef'ed in pyframe.h
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyFrameObject {
Expand Down Expand Up @@ -45,6 +49,10 @@ pub struct PyFrameObject {
pub f_localsplus: [*mut PyObject; 1], /* locals+stack, dynamically sized */
}

// skipped _PyFrame_IsRunnable
// skipped _PyFrame_IsExecuting
// skipped _PyFrameHasCompleted

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyFrame_Type: PyTypeObject;
Expand All @@ -63,6 +71,7 @@ extern "C" {
globals: *mut PyObject,
locals: *mut PyObject,
) -> *mut PyFrameObject;
// skipped _PyFrame_New_NoTrack

pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int);
pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock;
Expand All @@ -71,6 +80,9 @@ extern "C" {
pub fn PyFrame_FastToLocalsWithError(f: *mut PyFrameObject) -> c_int;
pub fn PyFrame_FastToLocals(f: *mut PyFrameObject);

// skipped _PyFrame_DebugMallocStats
// skipped PyFrame_GetBack

// FIXME: PyFrame_ClearFreeList is defined in frameobject.c
Copy link
Member

Choose a reason for hiding this comment

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

Similarly not sure what the FIXME is asking us to do?

pub fn PyFrame_ClearFreeList() -> c_int;
pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int;
}
8 changes: 8 additions & 0 deletions src/ffi/cpython/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
pub mod abstract_;
// skipped bytearrayobject.h
#[cfg(not(PyPy))]
pub mod bytesobject;
pub mod ceval;
pub mod code;
#[cfg(not(PyPy))]
pub mod dictobject;
// skipped fileobject.h
pub mod frameobject;

pub use self::abstract_::*;
#[cfg(not(PyPy))]
pub use self::bytesobject::*;
pub use self::ceval::*;
pub use self::code::*;
#[cfg(not(PyPy))]
pub use self::dictobject::*;
pub use self::frameobject::*;
Loading