Skip to content

Add assertion to _PyTuple_CAST(op)#10712

Merged
vstinner merged 2 commits intopython:masterfrom
vstinner:tuple_cast_assert
Nov 26, 2018
Merged

Add assertion to _PyTuple_CAST(op)#10712
vstinner merged 2 commits intopython:masterfrom
vstinner:tuple_cast_assert

Conversation

@vstinner
Copy link
Copy Markdown
Member

Add "assert(PyTuple_Check(op))" to _PyTuple_CAST() to check that the
argument is a tuple object in debug mode.

PyTuple_GET_SIZE() now uses _PyTuple_CAST() to use its assertion.

Add "assert(PyTuple_Check(op))" to _PyTuple_CAST() to check that the
argument is a tuple object in debug mode.

PyTuple_GET_SIZE() now uses _PyTuple_CAST() to use its assertion.
@vstinner
Copy link
Copy Markdown
Member Author

@serhiy-storchaka: What do you think of checking that the first argument of PyTuple_*() macros is a tuple in debug mode? It should ease debug in case of a crash/bug.

@serhiy-storchaka
Copy link
Copy Markdown
Member

This LGTM. But I don't think that such verbose and trivial comment is needed. Other macros (like PyTuple_GET_ITEM) do not have comments, and adding similar comment to every macro would make headers less readable.

I would add an assert in _PyTuple_CAST and left PyTuple_GET_SIZE as is. The current definition is simple and self-explaining.

@vstinner
Copy link
Copy Markdown
Member Author

Ok, I removed the comment.

@vstinner vstinner merged commit df108dc into python:master Nov 26, 2018
@vstinner vstinner deleted the tuple_cast_assert branch November 26, 2018 12:40
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