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-86493: Modernize modules initialization code#106858

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

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedJul 18, 2023
edited by github-actionsbot
Loading

Use PyModule_Add() or PyModule_AddObjectRef() instead of soft deprecated PyModule_AddObject().

PyModule_AddObject() is only left in two modules:_testcapi and_testbuffer. But that code ignores any failures for now. They need more significant rewriting.


📚 Documentation preview 📚:https://cpython-previews--106858.org.readthedocs.build/

Use PyModule_Add() or PyModule_AddObjectRef() instead of soft deprecatedPyModule_AddObject().
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM, but a few compiler warnings should be fixed first: see GHA job results, especially the Ubuntu job which logged many warnings.

o = PyErr_NewException("_tkinter.TclError", NULL, NULL);
if (o == NULL) {
Tkinter_TclError = PyErr_NewException("_tkinter.TclError", NULL, NULL);
if (PyModule_AddObjectRef(m, "TclError", Tkinter_TclError)) {
Py_DECREF(m);
Copy link
Member

Choose a reason for hiding this comment

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

Note for later: i prefer "exec" functions which returns -1 on error, and the caller is responsible to manage the module refcount.

Comment on lines -1505 to -1509
if (PyModule_AddObject(m, name, o) == 0) {
return 0;
}
Py_DECREF(o);
return -1;
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It is very confusing code with inverse logic. I thought there was a bug.

@@ -193,7 +193,7 @@ _PyTestCapi_Init_Structmember(PyObject *m)
if (res < 0) {
return -1;
}
res =PyModule_AddObject(
res =PyModule_AddObjectRef(
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think there was a bug.

Py_INCREF(ErrorObject);
if (PyModule_AddObject(m, "error", ErrorObject) < 0) {
Py_DECREF(ErrorObject);
if (PyModule_AddObjectRef(m, "error", ErrorObject) < 0) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It is interesting, that the compiler complains aboutPyModule_Add, but not aboutPyModule_AddObjectRef. There is a bug inPyModule_AddObjectRef declaration.

Copy link
Member

@corona10corona10 left a comment

Choose a reason for hiding this comment

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

lgtm too

Copy link
Member

@vstinnervstinner 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 didn't check individual refcount, I rely on Refleaks buildbots for that and other reviewers 😁 Overall the change LGTM and makes the code shorter and more regular. The old code was really hard to understand with INCREF/DECREF dance.

@rhettingerrhettinger removed their request for reviewJuly 20, 2023 13:49
@serhiy-storchakaserhiy-storchaka merged commit329e4a1 intopython:mainJul 25, 2023
@serhiy-storchakaserhiy-storchaka deleted the use-PyModule_Add branchJuly 25, 2023 11:34
@vstinner
Copy link
Member

That's a big change, thanks.

jtcave pushed a commit to jtcave/cpython that referenced this pull requestJul 27, 2023
Use PyModule_Add() or PyModule_AddObjectRef() instead of soft deprecatedPyModule_AddObject().
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner approved these changes

@corona10corona10corona10 approved these changes

@pgansslepganssleAwaiting requested review from pgansslepganssle is a code owner

@abalkinabalkinAwaiting requested review from abalkinabalkin is a code owner

@tirantiranAwaiting requested review from tirantiran 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.

4 participants
@serhiy-storchaka@vstinner@corona10@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp