Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-42111: Make the xxlimited module an example of best extension module practices#23226

Merged
miss-islington merged 6 commits into
python:masterpython/cpython:masterfrom
encukou:xxlimited-faceliftencukou/cpython:xxlimited-faceliftCopy head branch name to clipboard
Dec 8, 2020
Merged

bpo-42111: Make the xxlimited module an example of best extension module practices#23226
miss-islington merged 6 commits into
python:masterpython/cpython:masterfrom
encukou:xxlimited-faceliftencukou/cpython:xxlimited-faceliftCopy head branch name to clipboard

Conversation

@encukou

@encukou encukou commented Nov 10, 2020

Copy link
Copy Markdown
Member
  • Copy existing xxlimited to xxlimited53 (named for the limited API version it uses)
  • Build both modules, both in debug and release
  • Test both modules

https://bugs.python.org/issue42111

Automerge-Triggered-By: GH:encukou

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm curious why you picked Python 3.5 rather than 3.6 :-)

Comment thread setup.py Outdated
define_macros=[('Py_LIMITED_API', '0x03050000')]))
define_macros=[('Py_LIMITED_API', '0x03100000')]))
self.add(Extension('xxlimited_35', ['xxlimited_35.c'],
define_macros=[('Py_LIMITED_API', '0x03100000')]))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hum, it should be 3.5 rather than 3.10 no?

Why Python 3.5 in specific and not 3.6 for example? Nowadays, 3.6 became the minimum version of many projects, and it's also the Python 3 version of RHEL8 ;-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch!

The module uses limited API from Python 3.5. The corresponding stable ABI needs to be still compatible with current Python versions.

Comment thread setup.py
define_macros=[('Py_LIMITED_API', '0x03100000')]))
else:
# Debug mode: Build xxlimited with the full API
# (which is compatible with the limited one)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not also building with the limited C API?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

./Include/object.h:61:2: error: #error Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, and Py_REF_DEBUG

I guess that can be fixed, but that's out of scope here (and I don't know what the situation around this is on Windows)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh. Maybe it was needed when the debug build was not ABI compatible with the release build. It has been fixed in Python 3.8. But yeah, it can be addressed in a separated PR.

Comment thread setup.py
# Non-debug mode: Build xxlimited with limited API
self.add(Extension('xxlimited', ['xxlimited.c'],
define_macros=[('Py_LIMITED_API', '0x03050000')]))
define_macros=[('Py_LIMITED_API', '0x03100000')]))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it supposed to be updated when the python version is increased? If yes, maybe PEP 101 should be updated for release managers. (after this PR is merged)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No. When new things are needed, we should copy xxlimited to e.g. xxlimited_310, add tests, and update xxlimited to the newest version. If new stuff isn't needed in a release, this can stay on the old limited API version.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok.

Comment thread Modules/xxlimited_35.c
Comment thread Modules/xxlimited_35.c
Comment thread Modules/xxlimited.c
Comment thread Modules/xxlimited.c Outdated
Comment thread Modules/xxlimited.c Outdated
Comment thread Modules/xxlimited_35.c
Comment thread Lib/test/test_xxlimited.py
@encukou

encukou commented Dec 8, 2020

Copy link
Copy Markdown
Member Author

xxlimited_35.c is a copy of the historical code; I don't want to change it.
But I'll definitely look at your other suggestions!

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

I checked ./python -m test test_xxlimited -R 3:3: there is no leak.

def test_null(self):
null1 = self.module.Null()
null2 = self.module.Null()
self.assertNotEqual(null1, null2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, it's not a requirement. It's just that other test_xxx.py files have it. You can leave this file as it is.

Comment thread setup.py
define_macros=[('Py_LIMITED_API', '0x03100000')]))
else:
# Debug mode: Build xxlimited with the full API
# (which is compatible with the limited one)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh. Maybe it was needed when the debug build was not ABI compatible with the release build. It has been fixed in Python 3.8. But yeah, it can be addressed in a separated PR.

Comment thread setup.py
# Non-debug mode: Build xxlimited with limited API
self.add(Extension('xxlimited', ['xxlimited.c'],
define_macros=[('Py_LIMITED_API', '0x03050000')]))
define_macros=[('Py_LIMITED_API', '0x03100000')]))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok.

@encukou

encukou commented Dec 8, 2020

Copy link
Copy Markdown
Member Author

Thank you for the review!

@encukou encukou deleted the xxlimited-facelift branch December 8, 2020 16:37
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
…ule practices (pythonGH-23226)

- Copy existing xxlimited to xxlimited53 (named for the limited API version it uses)
- Build both modules, both in debug and release
- Test both modules
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.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.