-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Py_IS_TYPE() macro uses Py_TYPE() #22341
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
Conversation
@@ -141,7 +141,7 @@ static inline PyTypeObject* _Py_TYPE(const PyObject *ob) { | |||
|
|||
|
|||
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { | |||
return ob->ob_type == type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, There have any benefit from this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My plan is to hide implementation details as much as possible: https://www.python.org/dev/peps/pep-0620/
Right now, Py_TYPE() is trivial: just read ob->ob_type, but it may be more complex tomorrow.
Example in my tagged pointer experiment:
https://github.com/vstinner/cpython/blob/tagged_ptr/Include/object.h#L203
static inline PyTypeObject* _Py_TYPE(const PyObject *ob)
{
if (!_Py_TAGPTR_IS_TAGGED(ob)) {
return ob->ob_type;
}
else {
return _Py_TAGPTR_TYPE(ob);
}
}
Experiment: vstinner#6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this PR, only Py_TYPE() has to be updated, Py_IS_TYPE() remains unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Thanks for your reviews @shihai1991 and @corona10 ;-) If you are curious about tagged pointers: https://mail.python.org/archives/list/[email protected]/thread/4ETF7H5COIZWTCXDRTITVMU4P5DLRDLU/ |
copy that, this is an interesting PR. |
No description provided.