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

bpo-35199: Add an internal _PyTuple_ITEMS() macro #10434

Merged
merged 1 commit into from
Nov 9, 2018
Merged

bpo-35199: Add an internal _PyTuple_ITEMS() macro #10434

merged 1 commit into from
Nov 9, 2018

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Nov 9, 2018

  • _PyTuple_ITEMS() gives access to the tuple->ob_item field; cast the
    first argument to PyTupleObject*. The macro is only usable if
    Py_BUILD_CORE is defined.
  • Replace &PyTuple_GET_ITEM(ob, 0) with _PyTuple_ITEMS(ob)
  • Replace PyTuple_GET_ITEM(op, 1) with &_PyTuple_ITEMS(ob)[1]

https://bugs.python.org/issue35199

* _PyTuple_ITEMS() gives access to the tuple->ob_item field; cast the
  first argument to PyTupleObject*. The macro is only usable if
  Py_BUILD_CORE is defined.
* Replace &PyTuple_GET_ITEM(ob, 0) with _PyTuple_ITEMS(ob)
* Replace PyTuple_GET_ITEM(op, 1) with &_PyTuple_ITEMS(ob)[1]
@vstinner vstinner merged commit d17a693 into python:master Nov 9, 2018
@vstinner vstinner deleted the tuple_items branch November 9, 2018 15:56
@jdemeyer
Copy link
Contributor

@rhettinger I am confused here... the bpo issue was closed saying that it wouldn't be merged but the PR was merged anyway.

@vstinner
Copy link
Member Author

@rhettinger I am confused here... the bpo issue was closed saying that it wouldn't be merged but the PR was merged anyway.

I rejected my experimental PR #10435. See https://bugs.python.org/issue35199#msg329577

@jdemeyer
Copy link
Contributor

I rejected my experimental PR #10435. See https://bugs.python.org/issue35199#msg329577

So then what is the purpose of this PR? Apart from just adding a new way to do something which can already be done using PyTuple_GET_ITEM?

Asking from the point of view of a CPython developer: when should I use PyTuple_GET_ITEM and when _PyTuple_ITEMS?

@vstinner
Copy link
Member Author

So then what is the purpose of this PR?

This change allows me to experiment changes on PyTuple_GET_ITEM() like https://bugs.python.org/issue35337

It's also related to my more long-term plan to making type structures like PyTupleObject opaque: https://pythoncapi.readthedocs.io/bad_api.html#c-structures

@vstinner
Copy link
Member Author

Asking from the point of view of a CPython developer: when should I use PyTuple_GET_ITEM and when _PyTuple_ITEMS?

_PyTuple_ITEMS is used for direct access to the internal PyObject** array, whereas PyTuple_GET_ITEM() is used to get a single item.

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.

4 participants