aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-12-13 02:10:36 +0000
committerBenjamin Peterson <benjamin@python.org>2009-12-13 02:10:36 +0000
commit8f326b23695dc4996327da8477e11aad42c61953 (patch)
tree4e958dc9812fe6417eb75ea30a1bd409e2341c73 /Parser/tokenizer.c
parentregenerate Python-ast.c (diff)
downloadcpython-8f326b23695dc4996327da8477e11aad42c61953.tar.gz
cpython-8f326b23695dc4996327da8477e11aad42c61953.tar.bz2
cpython-8f326b23695dc4996327da8477e11aad42c61953.zip
Merged revisions 76052,76522,76591,76689,76697,76733 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r76052 | gregory.p.smith | 2009-11-01 20:02:38 -0600 (Sun, 01 Nov 2009) | 5 lines see issue1006238, this merges in the following patch to ease cross compiling the printf %zd check. http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-lang/python/files/python-2.5-cross-printf.patch?rev=1.1&view=markup ........ r76522 | barry.warsaw | 2009-11-25 12:38:32 -0600 (Wed, 25 Nov 2009) | 2 lines Add mktime_tz to __all__. It's documented as being available in email.utils. ........ r76591 | benjamin.peterson | 2009-11-29 16:26:26 -0600 (Sun, 29 Nov 2009) | 4 lines now that deepcopy can handle instance methods, this hack can be removed #7409 Thanks Robert Collins ........ r76689 | benjamin.peterson | 2009-12-06 11:37:48 -0600 (Sun, 06 Dec 2009) | 1 line rewrite translate_newlines for clarity ........ r76697 | benjamin.peterson | 2009-12-06 15:24:30 -0600 (Sun, 06 Dec 2009) | 2 lines fix test_parser from tokenizer tweak ........ r76733 | benjamin.peterson | 2009-12-09 21:37:59 -0600 (Wed, 09 Dec 2009) | 1 line substitute PyDict_Check() for PyObject_IsInstance ........
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r--Parser/tokenizer.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index f3ef1cbc6c1..5a1c268378c 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -652,20 +652,20 @@ 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, length = strlen(s), final_length;
+ int skip_next_lf = 0, needed_length = strlen(s) + 2, final_length;
char *buf, *current;
- char c;
- buf = PyMem_MALLOC(length + 2);
+ char c = '\0';
+ buf = PyMem_MALLOC(needed_length);
if (buf == NULL) {
tok->done = E_NOMEM;
return NULL;
}
- for (current = buf; (c = *s++);) {
+ for (current = buf; *s; s++, current++) {
+ c = *s;
if (skip_next_lf) {
skip_next_lf = 0;
if (c == '\n') {
- c = *s;
- s++;
+ c = *++s;
if (!c)
break;
}
@@ -675,19 +675,18 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) {
c = '\n';
}
*current = c;
- current++;
}
- /* If this is exec input, add a newline to the end of the file if
+ /* If this is exec input, add a newline to the end of the string if
there isn't one already. */
- if (exec_input && *current != '\n') {
+ if (exec_input && c != '\n') {
*current = '\n';
current++;
}
*current = '\0';
- final_length = current - buf;
- if (final_length < length && final_length)
+ final_length = current - buf + 1;
+ if (final_length < needed_length && final_length)
/* should never fail */
- buf = PyMem_REALLOC(buf, final_length + 1);
+ buf = PyMem_REALLOC(buf, final_length);
return buf;
}