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

GH-90699: use statically allocated interned strings in typeobject's slotdefs #94706

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Jul 9, 2022

@kumaraditya303 kumaraditya303 added skip news 🔨 test-with-buildbots labels Jul 9, 2022
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Jul 9, 2022

🤖 New build scheduled with the buildbot fleet by @kumaraditya303 for commit bf84334 🤖

If you want to schedule another build, you need to add the "🔨 test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots label Jul 9, 2022
@kumaraditya303 kumaraditya303 marked this pull request as ready for review Jul 9, 2022
@kumaraditya303 kumaraditya303 requested a review from markshannon as a code owner Jul 9, 2022
@kumaraditya303
Copy link
Contributor Author

@kumaraditya303 kumaraditya303 commented Jul 9, 2022

Webassembly buildbots failures are unrelated.

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

This is great! I literally wrote a note to myself yesterday to do this, so thanks for noticing and picking this up.

There's really only one thing I'd suggest you change.

#define TPSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC, NAMEOBJ) \
{NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \
PyDoc_STR(DOC)}
#define FLSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC, FLAGS) \
PyDoc_STR(DOC), .name_strobj = NAMEOBJ}
Copy link
Member

@ericsnowcurrently ericsnowcurrently Jul 9, 2022

Choose a reason for hiding this comment

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

The extra macro argument is unnecessary (and the duplication is avoidable):

#define TPSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
    {#NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \
     PyDoc_STR(DOC), .name_strobj = &_Py_ID(NAME)}

(You could also use _Py_XSTRINGIFY() from pymacro.h.)

Note that this requires that the quotation marks be dropped in all the uses of this macro. I'll leave a separate comment to show an example.

Copy link
Member

@ericsnowcurrently ericsnowcurrently Jul 9, 2022

Choose a reason for hiding this comment

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

One consequence of this change is that Tools/scripts/generate_global_objects.py cannot automatically detect these names. So the script would need to be updated. This includes making sure all the names are in the IDENTIFIERS list at the top of the file. I think this is worth doing.

Copy link
Member

@ericsnowcurrently ericsnowcurrently Jul 9, 2022

Choose a reason for hiding this comment

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

FYI, I opened gh-94715 to separately consider the idea of detecting the indirect uses of _Py_ID() as well. That can be dealt with in a separate PR (if desirable), though.

TPSLOT("__getattr__", tp_getattr, NULL, NULL, ""),
TPSLOT("__setattr__", tp_setattr, NULL, NULL, ""),
TPSLOT("__delattr__", tp_setattr, NULL, NULL, ""),
TPSLOT("__getattribute__", tp_getattr, NULL, NULL, "", &_Py_ID(__getattribute__)),
Copy link
Member

@ericsnowcurrently ericsnowcurrently Jul 9, 2022

Choose a reason for hiding this comment

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

Suggested change
TPSLOT("__getattribute__", tp_getattr, NULL, NULL, "", &_Py_ID(__getattribute__)),
TPSLOT(__getattribute__, tp_getattr, NULL, NULL, ""),

Copy link
Contributor Author

@kumaraditya303 kumaraditya303 Jul 9, 2022

Choose a reason for hiding this comment

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

I am not sure about this, the regex currently searches for _Py_ID(...) so it will not pick this up.

Copy link
Member

@ericsnowcurrently ericsnowcurrently Jul 9, 2022

Choose a reason for hiding this comment

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

Yeah, see #94706 (comment).

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Jul 9, 2022

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

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.

None yet

3 participants