summaryrefslogtreecommitdiffstats
path: root/Parser/parsetok.c
diff options
context:
space:
mode:
authorAndy Lester <andy@petdance.com>2020-02-28 02:44:52 (GMT)
committerGitHub <noreply@github.com>2020-02-28 02:44:52 (GMT)
commit384f3c536dd15ba33ea7e8afb4087ae359d4c12e (patch)
tree06c9a69e7b273165ae9c583b12beaf5c53332584 /Parser/parsetok.c
parent766b7546a564c8e386a3c31eb06fc1b55e8f5a25 (diff)
downloadcpython-384f3c536dd15ba33ea7e8afb4087ae359d4c12e.zip
cpython-384f3c536dd15ba33ea7e8afb4087ae359d4c12e.tar.gz
cpython-384f3c536dd15ba33ea7e8afb4087ae359d4c12e.tar.bz2
closes bpo-39721: Fix constness of members of tok_state struct. (GH-18600)
The function PyTokenizer_FromUTF8 from Parser/tokenizer.c had a comment: /* XXX: constify members. */ This patch addresses that. In the tok_state struct: * end and start were non-const but could be made const * str and input were const but should have been non-const Changes to support this include: * decode_str() now returns a char * since it is allocated. * PyTokenizer_FromString() and PyTokenizer_FromUTF8() each creates a new char * for an allocate string instead of reusing the input const char *. * PyTokenizer_Get() and tok_get() now take const char ** arguments. * Various local vars are const or non-const accordingly. I was able to remove five casts that cast away constness.
Diffstat (limited to 'Parser/parsetok.c')
-rw-r--r--Parser/parsetok.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/Parser/parsetok.c b/Parser/parsetok.c
index b0b1bd3..554455d 100644
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -240,7 +240,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
#endif
for (;;) {
- char *a, *b;
+ const char *a, *b;
int type;
size_t len;
char *str;
@@ -371,7 +371,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
buffer after parsing. Trailing whitespace and comments
are OK. */
if (err_ret->error == E_DONE && start == single_input) {
- char *cur = tok->cur;
+ const char *cur = tok->cur;
char c = *tok->cur;
for (;;) {