Index: tokenizer.c =================================================================== --- tokenizer.c (revision 76689) +++ tokenizer.c (revision 76139) @@ -105,7 +105,6 @@ tok->buf = tok->cur = tok->end = tok->inp = tok->start = NULL; tok->done = E_OK; tok->fp = NULL; - tok->input = NULL; tok->tabsize = TABSIZE; tok->indent = 0; tok->indstack[0] = 0; @@ -131,17 +130,6 @@ return tok; } -static char * -new_string(const char *s, Py_ssize_t len) -{ - char* result = (char *)PyMem_MALLOC(len + 1); - if (result != NULL) { - memcpy(result, s, len); - result[len] = '\0'; - } - return result; -} - #ifdef PGEN static char * @@ -156,10 +144,10 @@ return feof(tok->fp); } -static char * -decode_str(const char *str, int exec_input, struct tok_state *tok) +static const char * +decode_str(const char *str, struct tok_state *tok) { - return new_string(str, strlen(str)); + return str; } #else /* PGEN */ @@ -174,6 +162,16 @@ return NULL; /* as if it were EOF */ } +static char * +new_string(const char *s, Py_ssize_t len) +{ + char* result = (char *)PyMem_MALLOC(len + 1); + if (result != NULL) { + memcpy(result, s, len); + result[len] = '\0'; + } + return result; +} static char * get_normal_name(char *s) /* for utf-8 and latin-1 */ @@ -588,62 +586,17 @@ } #endif - -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; - char *buf, *current; - char c = '\0'; - buf = PyMem_MALLOC(needed_length); - if (buf == NULL) { - tok->done = E_NOMEM; - return NULL; - } - for (current = buf; *s; s++, current++) { - c = *s; - if (skip_next_lf) { - skip_next_lf = 0; - if (c == '\n') { - c = *++s; - if (!c) - break; - } - } - if (c == '\r') { - skip_next_lf = 1; - c = '\n'; - } - *current = c; - } - /* If this is exec input, add a newline to the end of the string if - there isn't one already. */ - if (exec_input && c != '\n') { - *current = '\n'; - current++; - } - *current = '\0'; - final_length = current - buf + 1; - if (final_length < needed_length && final_length) - /* should never fail */ - buf = PyMem_REALLOC(buf, final_length); - return buf; -} - /* Decode a byte string STR for use as the buffer of TOK. Look for encoding declarations inside STR, and record them inside TOK. */ static const char * -decode_str(const char *input, int single, struct tok_state *tok) +decode_str(const char *str, struct tok_state *tok) { PyObject* utf8 = NULL; - const char *str; const char *s; const char *newl[2] = {NULL, NULL}; int lineno = 0; - tok->input = str = translate_newlines(input, single, tok); - if (str == NULL) - return NULL; tok->enc = NULL; tok->str = str; if (!check_bom(buf_getc, buf_ungetc, buf_setreadl, tok)) @@ -698,12 +651,12 @@ /* Set up tokenizer for string */ struct tok_state * -PyTokenizer_FromString(const char *str, int exec_input) +PyTokenizer_FromString(const char *str) { struct tok_state *tok = tok_new(); if (tok == NULL) return NULL; - str = (char *)decode_str(str, exec_input, tok); + str = (char *)decode_str(str, tok); if (str == NULL) { PyTokenizer_Free(tok); return NULL; @@ -749,8 +702,6 @@ #endif if (tok->fp != NULL && tok->buf != NULL) PyMem_FREE(tok->buf); - if (tok->input) - PyMem_FREE((char *)tok->input); PyMem_FREE(tok); } Index: tokenizer.h =================================================================== --- tokenizer.h (revision 76689) +++ tokenizer.h (revision 76139) @@ -52,10 +52,9 @@ #endif const char* enc; const char* str; - const char* input; /* Tokenizer's newline translated copy of the string. */ }; -extern struct tok_state *PyTokenizer_FromString(const char *, int); +extern struct tok_state *PyTokenizer_FromString(const char *); extern struct tok_state *PyTokenizer_FromFile(FILE *, char *, char *); extern void PyTokenizer_Free(struct tok_state *); extern int PyTokenizer_Get(struct tok_state *, char **, char **); Index: parsetok.c =================================================================== --- parsetok.c (revision 76689) +++ parsetok.c (revision 76139) @@ -51,7 +51,7 @@ initerr(err_ret, filename); - if ((tok = PyTokenizer_FromString(s, start == file_input)) == NULL) { + if ((tok = PyTokenizer_FromString(s)) == NULL) { err_ret->error = PyErr_Occurred() ? E_DECODE : E_NOMEM; return NULL; }