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

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

Merged
merged 6 commits into from
Dec 8, 2020

Conversation

encukou
Copy link
Member

@encukou encukou commented Nov 10, 2020

  • 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

Copy link
Member

@vstinner vstinner left a comment

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 :-)

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
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
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.

define_macros=[('Py_LIMITED_API', '0x03100000')]))
else:
# Debug mode: Build xxlimited with the full API
# (which is compatible with the limited one)
Copy link
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
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
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.

self.add(Extension('xxlimited', ['xxlimited.c'],
define_macros=[('Py_LIMITED_API', '0x03050000')]))
define_macros=[('Py_LIMITED_API', '0x03100000')]))
Copy link
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
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
Member

Choose a reason for hiding this comment

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

Ok.

@encukou
Copy link
Member Author

encukou commented Dec 8, 2020

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!

Copy link
Member

@vstinner vstinner left a comment

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
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.

define_macros=[('Py_LIMITED_API', '0x03100000')]))
else:
# Debug mode: Build xxlimited with the full API
# (which is compatible with the limited one)
Copy link
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.

self.add(Extension('xxlimited', ['xxlimited.c'],
define_macros=[('Py_LIMITED_API', '0x03050000')]))
define_macros=[('Py_LIMITED_API', '0x03100000')]))
Copy link
Member

Choose a reason for hiding this comment

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

Ok.

@encukou
Copy link
Member Author

encukou commented Dec 8, 2020

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