Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

gh-140550: Update xxlimited with 3.15 limited API & PEP 697#142827

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
encukou wants to merge13 commits intopython:main
base:main
Choose a base branch
Loading
fromencukou:xxlimited-3.15

Conversation

@encukou
Copy link
Member

@encukouencukou commentedDec 16, 2025
edited by bedevere-appbot
Loading

  • Copy the existingxxlimited toxxlimited_3_13: this module serves as a rudimentary check that we don't break older Limited API. This is similar toxxlimited_35. (Nowadays we know that it's good to have a separator between the major/minor versions, but renaming toxxlimited_3_5 isn't worth the churn.)
  • Reorganizetest_xxlimited to make similar copies easier in the future
  • Switchxxlimited to Limited API 3.15,PyModExport (PEP-793), standalone instance struct with extended basicsize (PEP-697)
  • treat PyObject as opaque, asproposed inPEP-803 andPEP-809, using a private knob (_Py_OPAQUE_PYOBJECT) for now to ensure we don't rely onPyObject layout details accidentally. (I'll replace/remove the private API in 3.15 beta at latest.)

@erlend-aaslanderlend-aasland removed their request for reviewDecember 16, 2025 14:45
XxoObject*self=XxoObject_CAST(op);
Py_VISIT(self->x_attr);
XxoObject_Data*data=Xxo_get_data(self);
if (data==NULL) {

Choose a reason for hiding this comment

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

Xxo_get_data will set an exception on failure, which will probably break the GC. Same forXxo_clear below.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah; thenewly documented requirements fortp_traverse are breaking the design; I'll need to add some new borrowing+infallible APIs :/

ZeroIntensity reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Maybe call PyErr_WriteUnraisable()?

Same for Xxo_finalize(), no? Py_tp_finalize is not supposed to exit with an exception set._Py_Dealloc() (tp_del) checks if an exception is set if Python is built in debug mode, butPyObject_CallFinalizer() (tp_finalize) doesn't.

Copy link
MemberAuthor

@encukouencukouDec 17, 2025
edited
Loading

Choose a reason for hiding this comment

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

PyErr_WriteUnraisable won't work, becausetp_finalize can't create an exception object at all. It mustnot touch any refcounts; it's not enough to restore them to the previous state.

This is a problem. See:https://discuss.python.org/t/adding-c-api-for-use-in-tp-traverse/105331

Comment on lines 597 to 599
/* TODO: This is not quite true yet: there is a race in Xxo_setattro
* for example.
*/

Choose a reason for hiding this comment

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

Wouldn't it be better to mark this asPy_MOD_GIL_USED in the meantime, or are you trying to avoid the warning?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

AFAIK, the situation is unchanged sincePy_MOD_GIL_NOT_USED was added everywhere in#116882.

I think the intention is/was to make everything thread-safe beforesome stage of free-threading implementation?

Choose a reason for hiding this comment

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

I think we added that everywhere under the assumption that everything was already thread-safe, and anything that should be reported to us as a bug. I'm not sure that applies with our own test suite.

Copy link
MemberAuthor

@encukouencukouDec 16, 2025
edited
Loading

Choose a reason for hiding this comment

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

This is not really a test suite, it supposed to be an example/template showing how to use the Limited API.
The limited API was never compatible with free-threading (yet), so I don't think there's a bug?

There's an earlier PR,#110764, which did this (Py_NOGIL was later renamed toPy_GIL_DISABLED):

+#ifndef Py_NOGIL #define Py_LIMITED_API 0x030d0000+#endif

... but that seems to defeat the point of this module :/

Maybe we should have not built these modules at all in free-threading builds, and skip the relevant tests?
Doing thatnow seems like wasted effort though, when mutexes/critical sections are a genuine TODO item for the limited API.

Choose a reason for hiding this comment

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

If it's a template, I'm a little concerned that people will see this and think "oh, this module is thread-safe", when it's really not. The comment helps, but I don't know what percentage of people will ignore it.

@encukou
Copy link
MemberAuthor

I'll mark this draft -- this PR makes some shortcomings quite visible, and I guess it's better to address them before suggesting the new API :)

@encukouencukou marked this pull request as draftDecember 16, 2025 17:58
newXxoObject(PyObject*module)
// Xxo initialization
// This is the implementation of Xxo.__new__; it takes arbitrary positional
// and keyword arguments.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand "it takes arbitrary positional and keyword arguments" since the error message below is "Xxo.__new__() takes no arguments".

encukou reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Thetp_new calling convention takes args&kwargs, so we need to check.
I agree the comment was misleading. Also the situation should be clear without the comment, so I removed it.

XxoObject*self=XxoObject_CAST(op);
Py_VISIT(self->x_attr);
XxoObject_Data*data=Xxo_get_data(self);
if (data==NULL) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe call PyErr_WriteUnraisable()?

Same for Xxo_finalize(), no? Py_tp_finalize is not supposed to exit with an exception set._Py_Dealloc() (tp_del) checks if an exception is set if Python is built in debug mode, butPyObject_CallFinalizer() (tp_finalize) doesn't.

if (self->x_attr==NULL) {
// filter a specific attribute name
intis_reserved=PyUnicode_EqualToUTF8(name,"reserved");
if (is_reserved<0) {
Copy link
Member

Choose a reason for hiding this comment

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

encukou reacted with thumbs up emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@vstinnervstinnervstinner left review comments

@ZeroIntensityZeroIntensityZeroIntensity left review comments

@gpsheadgpsheadAwaiting requested review from gpshead

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

@AA-TurnerAA-TurnerAwaiting requested review from AA-TurnerAA-Turner is a code owner

@emmatypingemmatypingAwaiting requested review from emmatypingemmatyping is a code owner

@corona10corona10Awaiting requested review from corona10corona10 is a code owner

@erlend-aaslanderlend-aaslandAwaiting requested review from erlend-aaslanderlend-aasland will be requested when the pull request is marked ready for reviewerlend-aasland is a code owner

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@encukou@vstinner@ZeroIntensity

[8]ページ先頭

©2009-2025 Movatter.jp