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

Conversation

nw0
Copy link
Contributor

@nw0 nw0 commented Dec 27, 2020

Partial fix for #1289. This set seems relatively more straightforward, but touches a lot of files.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks again for continuing on with this, this is looking excellent! I see a few TODO comments so I'll give this another look through once this is resolved.

Regarding the CHANGELOG - we usually make the sections Added, Changed, Removed, Fixed in that order, so if you're adding a new section would be great to make it fit that ordering.


/// Helper initial value of [`PyGetSetDef`] for a Python class.
///
/// Not present in `cpython/Include/descrobject`.
Copy link
Member

Choose a reason for hiding this comment

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

By this, you mean it's something we have invented ourselves?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I don't find any obvious origin in cpython. If ffi is strictly for imports, we should probably move this, but it's up to you.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think this (and PyGetSetDef_DICT) should probably be moved to just be private variables in pyclass.rs.

For now please just mark these deprecated; I'll move them in a future breaking release.

src/ffi/fileobject.rs Outdated Show resolved Hide resolved
Copy link
Contributor Author

@nw0 nw0 left a comment

Choose a reason for hiding this comment

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

I see a few TODO comments so I'll give this another look through once this is resolved.

I've annotated these. Basically, these can't be moved as-is (or mark them non-limited), because we have code in dict.rs and floatob.rs (py_native_type invocations) that unconditionally uses these types. Could you advise on the appropriate action here?

src/ffi/dictobject.rs Outdated Show resolved Hide resolved
src/ffi/dictobject.rs Outdated Show resolved Hide resolved
src/ffi/floatobject.rs Show resolved Hide resolved
@davidhewitt
Copy link
Member

I think the right solution for PyDictObject and PyFloatObject is to use opaque_struct! with the limited API for now. You could also mark these with TODO to remove the opaque_struct! implementations later; we have to revisit this in the future anyway to enable subclassing builtin types with the abi3 feature:

unreachable!("Subclassing native types isn't support in limited API mode");

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

😍 thank you again, so pleasing to see these files getting some proper treatment!

I added a few minor suggestions for the CHANGELOG and also some minor nits on indentation. Otherwise, this one's looking close to merging?

src/ffi/context.rs Show resolved Hide resolved
CHANGELOG.md Outdated
Comment on lines 17 to 19
### 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.

CHANGELOG.md Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated
@@ -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)
- 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?

CHANGELOG.md Outdated
- 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)
- 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)
- 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 :)

src/ffi/context.rs Show resolved Hide resolved
// 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).

// 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?

src/ffi/fileobject.rs Show resolved Hide resolved
@nw0
Copy link
Contributor Author

nw0 commented Dec 28, 2020

Sorry about the mess. I've eyeballed the PR diff this time and think it's ready for review, if tests pass.

Copy link
Member

@kngwyu kngwyu left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thank you again for your continued work on this cleanup! 💯

@davidhewitt davidhewitt merged commit fb9ad1e into PyO3:master Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants