summaryrefslogtreecommitdiff
path: root/Parser/tokenizer.c
diff options
context:
space:
mode:
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r--Parser/tokenizer.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 8530723c26..c32a3bfd1c 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -31,7 +31,7 @@
|| c == '_'\
|| (c >= 128))
-extern char *PyOS_Readline(FILE *, FILE *, char *);
+extern char *PyOS_Readline(FILE *, FILE *, const char *);
/* Return malloc'ed string including trailing \n;
empty malloc'ed string for EOF;
NULL if interrupted */
@@ -47,7 +47,7 @@ static void tok_backup(struct tok_state *tok, int c);
/* Token names */
-char *_PyParser_TokenNames[] = {
+const char *_PyParser_TokenNames[] = {
"ENDMARKER",
"NAME",
"NUMBER",
@@ -681,7 +681,8 @@ translate_into_utf8(const char* str, const char* enc) {
static char *
translate_newlines(const char *s, int exec_input, struct tok_state *tok) {
- int skip_next_lf = 0, needed_length = strlen(s) + 2, final_length;
+ int skip_next_lf = 0;
+ size_t needed_length = strlen(s) + 2, final_length;
char *buf, *current;
char c = '\0';
buf = PyMem_MALLOC(needed_length);
@@ -789,7 +790,7 @@ PyTokenizer_FromString(const char *str, int exec_input)
struct tok_state *tok = tok_new();
if (tok == NULL)
return NULL;
- str = (char *)decode_str(str, exec_input, tok);
+ str = decode_str(str, exec_input, tok);
if (str == NULL) {
PyTokenizer_Free(tok);
return NULL;
@@ -832,7 +833,8 @@ PyTokenizer_FromUTF8(const char *str, int exec_input)
/* Set up tokenizer for file */
struct tok_state *
-PyTokenizer_FromFile(FILE *fp, char* enc, char *ps1, char *ps2)
+PyTokenizer_FromFile(FILE *fp, const char* enc,
+ const char *ps1, const char *ps2)
{
struct tok_state *tok = tok_new();
if (tok == NULL)
@@ -883,7 +885,7 @@ PyTokenizer_Free(struct tok_state *tok)
/* Get next char, updating state; error code goes into tok->done */
static int
-tok_nextc(register struct tok_state *tok)
+tok_nextc(struct tok_state *tok)
{
for (;;) {
if (tok->cur != tok->inp) {
@@ -1080,7 +1082,7 @@ tok_nextc(register struct tok_state *tok)
/* Back-up one character */
static void
-tok_backup(register struct tok_state *tok, register int c)
+tok_backup(struct tok_state *tok, int c)
{
if (c != EOF) {
if (--tok->cur < tok->buf)
@@ -1310,9 +1312,9 @@ verify_identifier(struct tok_state *tok)
/* Get next token, after space stripping etc. */
static int
-tok_get(register struct tok_state *tok, char **p_start, char **p_end)
+tok_get(struct tok_state *tok, char **p_start, char **p_end)
{
- register int c;
+ int c;
int blankline, nonascii;
*p_start = *p_end = NULL;
@@ -1322,8 +1324,8 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
/* Get indentation level */
if (tok->atbol) {
- register int col = 0;
- register int altcol = 0;
+ int col = 0;
+ int altcol = 0;
tok->atbol = 0;
for (;;) {
c = tok_nextc(tok);
@@ -1739,10 +1741,15 @@ PyTokenizer_FindEncodingFilename(int fd, PyObject *filename)
FILE *fp;
char *p_start =NULL , *p_end =NULL , *encoding = NULL;
+#ifndef PGEN
+ fd = _Py_dup(fd);
+#else
fd = dup(fd);
+#endif
if (fd < 0) {
return NULL;
}
+
fp = fdopen(fd, "r");
if (fp == NULL) {
return NULL;