Skip to content

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

Merged
merged 1 commit into from
Sep 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

@vstinner vstinner Sep 21, 2020

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.

return Py_TYPE(ob) == type;
}
#define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type)

Expand Down