From c0e68321fe21b77df163ea7d52f8f9957f18bee6 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Sat, 8 Sep 2018 04:12:03 -0600 Subject: [PATCH 1/2] tokenizer.c: Replace unneeded PyUnicode_READY() with an assertion In verify_identifier(), PyUnicode_READY(s) == -1 would never occur (PyUnicode_DecodeUTF8() always returns a ready string on success). Also, if PyUnicode_READY(s) == -1 did actually occur here, there would be a reference leak. --- Parser/tokenizer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 6566fdead3807f2..53856d2d60b308a 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -1324,7 +1324,7 @@ verify_identifier(struct tok_state *tok) if (tok->decoding_erred) return 0; s = PyUnicode_DecodeUTF8(tok->start, tok->cur - tok->start, NULL); - if (s == NULL || PyUnicode_READY(s) == -1) { + if (s == NULL) { if (PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) { PyErr_Clear(); tok->done = E_IDENTIFIER; @@ -1333,6 +1333,7 @@ verify_identifier(struct tok_state *tok) } return 0; } + assert(PyUnicode_IS_READY(s)); result = PyUnicode_IsIdentifier(s); Py_DECREF(s); if (result == 0) From 0ca06ff4ee2c1d2525162265590a5b14afa538ad Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Sun, 9 Sep 2018 21:05:04 -0600 Subject: [PATCH 2/2] Remove the assertion. --- Parser/tokenizer.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 53856d2d60b308a..fc75bae53766099 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -1333,7 +1333,6 @@ verify_identifier(struct tok_state *tok) } return 0; } - assert(PyUnicode_IS_READY(s)); result = PyUnicode_IsIdentifier(s); Py_DECREF(s); if (result == 0)