summaryrefslogtreecommitdiffstats
path: root/Parser/tokenizer.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-04-11 08:19:15 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-04-11 08:19:15 (GMT)
commit08062d6665b6a0c30559eb8a064356ca86151caf (patch)
treebd3aefcf6dd68268466453621dfd6c6b74b090bb /Parser/tokenizer.c
parent01b810106c348db2e3242126adf655b686aa2a1c (diff)
downloadcpython-08062d6665b6a0c30559eb8a064356ca86151caf.zip
cpython-08062d6665b6a0c30559eb8a064356ca86151caf.tar.gz
cpython-08062d6665b6a0c30559eb8a064356ca86151caf.tar.bz2
As discussed on python-dev, really fix the PyMem_*/PyObject_* memory API
mismatches. At least I hope this fixes them all. This reverts part of my change from yesterday that converted everything in Parser/*.c to use PyObject_* API. The encoding doesn't really need to use PyMem_*, however, it uses new_string() which must return PyMem_* for handling the result of PyOS_Readline() which returns PyMem_* memory. If there were 2 versions of new_string() one that returned PyMem_* for tokens and one that return PyObject_* for encodings that could also fix this problem. I'm not sure which version would be clearer. This seems to fix both Guido's and Phillip's problems, so it's good enough for now. After this change, it would be good to review Parser/*.c for consistent use of the 2 memory APIs.
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r--Parser/tokenizer.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 5fcf49e..10e5253 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -164,7 +164,7 @@ error_ret(struct tok_state *tok) /* XXX */
{
tok->decoding_erred = 1;
if (tok->fp != NULL && tok->buf != NULL) /* see PyTokenizer_Free */
- PyObject_FREE(tok->buf);
+ PyMem_FREE(tok->buf);
tok->buf = NULL;
return NULL; /* as if it were EOF */
}
@@ -172,7 +172,7 @@ error_ret(struct tok_state *tok) /* XXX */
static char *
new_string(const char *s, Py_ssize_t len)
{
- char* result = (char *)PyObject_MALLOC(len + 1);
+ char* result = (char *)PyMem_MALLOC(len + 1);
if (result != NULL) {
memcpy(result, s, len);
result[len] = '\0';
@@ -237,7 +237,7 @@ get_coding_spec(const char *s, Py_ssize_t size)
char* r = new_string(begin, t - begin);
char* q = get_normal_name(r);
if (r != q) {
- PyObject_FREE(r);
+ PyMem_FREE(r);
r = new_string(q, strlen(q));
}
return r;
@@ -278,18 +278,18 @@ check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok,
tok->decoding_state = -1;
}
else
- PyObject_FREE(cs);
+ PyMem_FREE(cs);
#else
/* Without Unicode support, we cannot
process the coding spec. Since there
won't be any Unicode literals, that
won't matter. */
- PyObject_FREE(cs);
+ PyMem_FREE(cs);
#endif
}
} else { /* then, compare cs with BOM */
r = (strcmp(tok->encoding, cs) == 0);
- PyObject_FREE(cs);
+ PyMem_FREE(cs);
}
}
if (!r) {
@@ -335,7 +335,7 @@ check_bom(int get_char(struct tok_state *),
return 1;
}
if (tok->encoding != NULL)
- PyObject_FREE(tok->encoding);
+ PyMem_FREE(tok->encoding);
tok->encoding = new_string("utf-8", 5); /* resulting is in utf-8 */
return 1;
NON_BOM:
@@ -657,7 +657,7 @@ PyTokenizer_FromFile(FILE *fp, char *ps1, char *ps2)
struct tok_state *tok = tok_new();
if (tok == NULL)
return NULL;
- if ((tok->buf = (char *)PyObject_MALLOC(BUFSIZ)) == NULL) {
+ if ((tok->buf = (char *)PyMem_MALLOC(BUFSIZ)) == NULL) {
PyTokenizer_Free(tok);
return NULL;
}
@@ -676,13 +676,13 @@ void
PyTokenizer_Free(struct tok_state *tok)
{
if (tok->encoding != NULL)
- PyObject_FREE(tok->encoding);
+ PyMem_FREE(tok->encoding);
#ifndef PGEN
Py_XDECREF(tok->decoding_readline);
Py_XDECREF(tok->decoding_buffer);
#endif
if (tok->fp != NULL && tok->buf != NULL)
- PyObject_FREE(tok->buf);
+ PyMem_FREE(tok->buf);
PyMem_FREE(tok);
}
@@ -722,10 +722,10 @@ tok_stdin_decode(struct tok_state *tok, char **inp)
if (converted == NULL)
goto error_nomem;
- PyObject_FREE(*inp);
+ PyMem_FREE(*inp);
*inp = converted;
if (tok->encoding != NULL)
- PyObject_FREE(tok->encoding);
+ PyMem_FREE(tok->encoding);
tok->encoding = new_string(encoding, strlen(encoding));
if (tok->encoding == NULL)
goto error_nomem;
@@ -782,24 +782,24 @@ tok_nextc(register struct tok_state *tok)
if (newtok == NULL)
tok->done = E_INTR;
else if (*newtok == '\0') {
- PyObject_FREE(newtok);
+ PyMem_FREE(newtok);
tok->done = E_EOF;
}
#if !defined(PGEN) && defined(Py_USING_UNICODE)
else if (tok_stdin_decode(tok, &newtok) != 0)
- PyObject_FREE(newtok);
+ PyMem_FREE(newtok);
#endif
else if (tok->start != NULL) {
size_t start = tok->start - tok->buf;
size_t oldlen = tok->cur - tok->buf;
size_t newlen = oldlen + strlen(newtok);
char *buf = tok->buf;
- buf = (char *)PyObject_REALLOC(buf, newlen+1);
+ buf = (char *)PyMem_REALLOC(buf, newlen+1);
tok->lineno++;
if (buf == NULL) {
- PyObject_FREE(tok->buf);
+ PyMem_FREE(tok->buf);
tok->buf = NULL;
- PyObject_FREE(newtok);
+ PyMem_FREE(newtok);
tok->done = E_NOMEM;
return EOF;
}
@@ -807,7 +807,7 @@ tok_nextc(register struct tok_state *tok)
tok->cur = tok->buf + oldlen;
tok->line_start = tok->cur;
strcpy(tok->buf + oldlen, newtok);
- PyObject_FREE(newtok);
+ PyMem_FREE(newtok);
tok->inp = tok->buf + newlen;
tok->end = tok->inp + 1;
tok->start = tok->buf + start;
@@ -815,7 +815,7 @@ tok_nextc(register struct tok_state *tok)
else {
tok->lineno++;
if (tok->buf != NULL)
- PyObject_FREE(tok->buf);
+ PyMem_FREE(tok->buf);
tok->buf = newtok;
tok->line_start = tok->buf;
tok->cur = tok->buf;
@@ -831,7 +831,7 @@ tok_nextc(register struct tok_state *tok)
if (tok->start == NULL) {
if (tok->buf == NULL) {
tok->buf = (char *)
- PyObject_MALLOC(BUFSIZ);
+ PyMem_MALLOC(BUFSIZ);
if (tok->buf == NULL) {
tok->done = E_NOMEM;
return EOF;
@@ -866,8 +866,8 @@ tok_nextc(register struct tok_state *tok)
Py_ssize_t curvalid = tok->inp - tok->buf;
Py_ssize_t newsize = curvalid + BUFSIZ;
char *newbuf = tok->buf;
- newbuf = (char *)PyObject_REALLOC(newbuf,
- newsize);
+ newbuf = (char *)PyMem_REALLOC(newbuf,
+ newsize);
if (newbuf == NULL) {
tok->done = E_NOMEM;
tok->cur = tok->inp;