Skip to content

gh-106303: Use _PyObject_LookupAttr() instead of PyObject_GetAttr() #106304

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

Merged
merged 2 commits into from
Jul 9, 2023

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jul 1, 2023

It simplifies and speed up the code.

return -1;
PyObject *value;
int res = _PyObject_LookupAttr(wrapped, name, &value);
if (value != NULL) {
Copy link
Member

Choose a reason for hiding this comment

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

How about adding an assert before reassignment?

assert(res > 0);

Copy link
Member Author

Choose a reason for hiding this comment

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

This was not necessary in many other cases where a similar idiom is used.

@serhiy-storchaka serhiy-storchaka merged commit 93d292c into python:main Jul 9, 2023
@serhiy-storchaka serhiy-storchaka deleted the lookup-attr branch July 9, 2023 12:27
@serhiy-storchaka serhiy-storchaka added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jul 9, 2023
@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 93d292c2b3f8e85ef562c37f59678c639b9b8fcb 3.11

@miss-islington
Copy link
Contributor

Sorry @serhiy-storchaka, I had trouble checking out the 3.12 backport branch.
Please retry by removing and re-adding the "needs backport to 3.12" label.
Alternatively, you can backport using cherry_picker on the command line.
cherry_picker 93d292c2b3f8e85ef562c37f59678c639b9b8fcb 3.12

@AlexWaygood AlexWaygood added needs backport to 3.12 only security fixes and removed needs backport to 3.12 only security fixes labels Jul 9, 2023
@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-106568 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 only security fixes label Jul 9, 2023
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jul 9, 2023
…t_GetAttr() (pythonGH-106304)

It simplifies and speed up the code..
(cherry picked from commit 93d292c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot
Copy link

GH-106569 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jul 9, 2023
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jul 9, 2023
…t_GetAttr() (pythonGH-106304)

It simplifies and speed up the code.
(cherry picked from commit 93d292c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@serhiy-storchaka serhiy-storchaka removed their assignment Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants