diff options
author | Andy Lester <andy@petdance.com> | 2020-02-28 02:44:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 02:44:52 (GMT) |
commit | 384f3c536dd15ba33ea7e8afb4087ae359d4c12e (patch) | |
tree | 06c9a69e7b273165ae9c583b12beaf5c53332584 /Parser/tokenizer.h | |
parent | 766b7546a564c8e386a3c31eb06fc1b55e8f5a25 (diff) | |
download | cpython-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/tokenizer.h')
-rw-r--r-- | Parser/tokenizer.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Parser/tokenizer.h b/Parser/tokenizer.h index 92669bf..5660ea3 100644 --- a/Parser/tokenizer.h +++ b/Parser/tokenizer.h @@ -26,8 +26,8 @@ struct tok_state { char *buf; /* Input buffer, or NULL; malloc'ed if fp != NULL */ char *cur; /* Next character in buffer */ char *inp; /* End of data in buffer */ - char *end; /* End of input buffer if buf != NULL */ - char *start; /* Start of current token if not NULL */ + const char *end; /* End of input buffer if buf != NULL */ + const char *start; /* Start of current token if not NULL */ int done; /* E_OK normally, E_EOF at EOF, otherwise error code */ /* NB If done != E_OK, cur must be == inp!!! */ FILE *fp; /* Rest of input; NULL if tokenizing a string */ @@ -60,8 +60,8 @@ struct tok_state { PyObject *decoding_readline; /* open(...).readline */ PyObject *decoding_buffer; const char* enc; /* Encoding for the current str. */ - const char* str; - const char* input; /* Tokenizer's newline translated copy of the string. */ + char* str; + char* input; /* Tokenizer's newline translated copy of the string. */ int type_comments; /* Whether to look for type comments */ @@ -78,7 +78,7 @@ extern struct tok_state *PyTokenizer_FromUTF8(const char *, int); extern struct tok_state *PyTokenizer_FromFile(FILE *, const char*, const char *, const char *); extern void PyTokenizer_Free(struct tok_state *); -extern int PyTokenizer_Get(struct tok_state *, char **, char **); +extern int PyTokenizer_Get(struct tok_state *, const char **, const char **); #define tok_dump _Py_tok_dump |