Skip to content

Commit

Permalink
Merge pull request #1341 from nw0/ffi-1
Browse files Browse the repository at this point in the history
ffi module cleanup: context.h to frameobject.h
  • Loading branch information
davidhewitt committed Dec 28, 2020
2 parents acbfaf4 + f26a1ea commit fb9ad1e
Show file tree
Hide file tree
Showing 17 changed files with 652 additions and 480 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Expand Up @@ -9,10 +9,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Add support for `#[pyclass(dict)]` and `#[pyclass(weakref)]` with the `abi3` feature on Python 3.9 and up. [#1342](https://github.com/PyO3/pyo3/pull/1342)

### Changed
- 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)
- Deprecate FFI definitions `PyGetSetDef_DICT` and `PyGetSetDef_INIT` which have never been in the Python API. [#1341](https://github.com/PyO3/pyo3/pull/1341)

### Removed
- Remove FFI definition `PyFrame_ClearFreeList` when building for Python 3.9. [#1341](https://github.com/PyO3/pyo3/pull/1341)
- Remove FFI definition `_PyDict_Contains` when building for Python 3.10. [#1341](https://github.com/PyO3/pyo3/pull/1341)

### 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
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
}

#[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
}
63 changes: 63 additions & 0 deletions src/ffi/cpython/dictobject.rs
@@ -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
#[cfg(not(Py_3_10))]
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
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

#[cfg(not(Py_3_9))]
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
@@ -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::*;

0 comments on commit fb9ad1e

Please sign in to comment.