diff options
author | Victor Stinner <vstinner@python.org> | 2020-12-01 08:56:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-01 08:56:42 (GMT) |
commit | 00d7abd7ef588fc4ff0571c8579ab4aba8ada1c0 (patch) | |
tree | 26ebb0fe409768193bb85be90c0229a0f44d6f8e /Parser/tokenizer.c | |
parent | b2d0c66e881301ed8908da3cb41bbf253c449b0c (diff) | |
download | cpython-00d7abd7ef588fc4ff0571c8579ab4aba8ada1c0.zip cpython-00d7abd7ef588fc4ff0571c8579ab4aba8ada1c0.tar.gz cpython-00d7abd7ef588fc4ff0571c8579ab4aba8ada1c0.tar.bz2 |
bpo-42519: Replace PyMem_MALLOC() with PyMem_Malloc() (GH-23586)
No longer use deprecated aliases to functions:
* Replace PyMem_MALLOC() with PyMem_Malloc()
* Replace PyMem_REALLOC() with PyMem_Realloc()
* Replace PyMem_FREE() with PyMem_Free()
* Replace PyMem_Del() with PyMem_Free()
* Replace PyMem_DEL() with PyMem_Free()
Modify also the PyMem_DEL() macro to use directly PyMem_Free().
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r-- | Parser/tokenizer.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index f3c1d9b..96539bd 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -51,7 +51,7 @@ static const char* type_comment_prefix = "# type: "; static struct tok_state * tok_new(void) { - struct tok_state *tok = (struct tok_state *)PyMem_MALLOC( + struct tok_state *tok = (struct tok_state *)PyMem_Malloc( sizeof(struct tok_state)); if (tok == NULL) return NULL; @@ -93,7 +93,7 @@ tok_new(void) static char * new_string(const char *s, Py_ssize_t len, struct tok_state *tok) { - char* result = (char *)PyMem_MALLOC(len + 1); + char* result = (char *)PyMem_Malloc(len + 1); if (!result) { tok->done = E_NOMEM; return NULL; @@ -108,7 +108,7 @@ error_ret(struct tok_state *tok) /* XXX */ { tok->decoding_erred = 1; if (tok->fp != NULL && tok->buf != NULL) /* see PyTokenizer_Free */ - PyMem_FREE(tok->buf); + PyMem_Free(tok->buf); tok->buf = tok->cur = tok->inp = NULL; tok->start = NULL; tok->end = NULL; @@ -184,7 +184,7 @@ get_coding_spec(const char *s, char **spec, Py_ssize_t size, struct tok_state *t return 0; q = get_normal_name(r); if (r != q) { - PyMem_FREE(r); + PyMem_Free(r); r = new_string(q, strlen(q), tok); if (!r) return 0; @@ -244,7 +244,7 @@ check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok, else { PyErr_Format(PyExc_SyntaxError, "encoding problem: %s", cs); - PyMem_FREE(cs); + PyMem_Free(cs); } } } else { /* then, compare cs with BOM */ @@ -252,7 +252,7 @@ check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok, if (!r) PyErr_Format(PyExc_SyntaxError, "encoding problem: %s with BOM", cs); - PyMem_FREE(cs); + PyMem_Free(cs); } return r; } @@ -315,7 +315,7 @@ check_bom(int get_char(struct tok_state *), return 1; } if (tok->encoding != NULL) - PyMem_FREE(tok->encoding); + PyMem_Free(tok->encoding); tok->encoding = new_string("utf-8", 5, tok); if (!tok->encoding) return 0; @@ -620,7 +620,7 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) { size_t needed_length = strlen(s) + 2, final_length; char *buf, *current; char c = '\0'; - buf = PyMem_MALLOC(needed_length); + buf = PyMem_Malloc(needed_length); if (buf == NULL) { tok->done = E_NOMEM; return NULL; @@ -651,9 +651,9 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) { final_length = current - buf + 1; if (final_length < needed_length && final_length) { /* should never fail */ - char* result = PyMem_REALLOC(buf, final_length); + char* result = PyMem_Realloc(buf, final_length); if (result == NULL) { - PyMem_FREE(buf); + PyMem_Free(buf); } buf = result; } @@ -757,7 +757,7 @@ PyTokenizer_FromUTF8(const char *str, int exec_input) tok->read_coding_spec = 1; tok->enc = NULL; tok->str = translated; - tok->encoding = (char *)PyMem_MALLOC(6); + tok->encoding = (char *)PyMem_Malloc(6); if (!tok->encoding) { PyTokenizer_Free(tok); return NULL; @@ -778,7 +778,7 @@ PyTokenizer_FromFile(FILE *fp, const char* enc, struct tok_state *tok = tok_new(); if (tok == NULL) return NULL; - if ((tok->buf = (char *)PyMem_MALLOC(BUFSIZ)) == NULL) { + if ((tok->buf = (char *)PyMem_Malloc(BUFSIZ)) == NULL) { PyTokenizer_Free(tok); return NULL; } @@ -790,7 +790,7 @@ PyTokenizer_FromFile(FILE *fp, const char* enc, if (enc != NULL) { /* Must copy encoding declaration since it gets copied into the parse tree. */ - tok->encoding = PyMem_MALLOC(strlen(enc)+1); + tok->encoding = PyMem_Malloc(strlen(enc)+1); if (!tok->encoding) { PyTokenizer_Free(tok); return NULL; @@ -808,15 +808,15 @@ void PyTokenizer_Free(struct tok_state *tok) { if (tok->encoding != NULL) - PyMem_FREE(tok->encoding); + PyMem_Free(tok->encoding); Py_XDECREF(tok->decoding_readline); Py_XDECREF(tok->decoding_buffer); Py_XDECREF(tok->filename); if (tok->fp != NULL && tok->buf != NULL) - PyMem_FREE(tok->buf); + PyMem_Free(tok->buf); if (tok->input) - PyMem_FREE(tok->input); - PyMem_FREE(tok); + PyMem_Free(tok->input); + PyMem_Free(tok); } /* Get next char, updating state; error code goes into tok->done */ @@ -852,7 +852,7 @@ tok_nextc(struct tok_state *tok) char *newtok = PyOS_Readline(stdin, stdout, tok->prompt); if (newtok != NULL) { char *translated = translate_newlines(newtok, 0, tok); - PyMem_FREE(newtok); + PyMem_Free(newtok); if (translated == NULL) return EOF; newtok = translated; @@ -862,14 +862,14 @@ tok_nextc(struct tok_state *tok) Py_ssize_t buflen; const char* buf; PyObject *u = translate_into_utf8(newtok, tok->encoding); - PyMem_FREE(newtok); + PyMem_Free(newtok); if (!u) { tok->done = E_DECODE; return EOF; } buflen = PyBytes_GET_SIZE(u); buf = PyBytes_AS_STRING(u); - newtok = PyMem_MALLOC(buflen+1); + newtok = PyMem_Malloc(buflen+1); if (newtok == NULL) { Py_DECREF(u); tok->done = E_NOMEM; @@ -883,7 +883,7 @@ tok_nextc(struct tok_state *tok) if (newtok == NULL) tok->done = E_INTR; else if (*newtok == '\0') { - PyMem_FREE(newtok); + PyMem_Free(newtok); tok->done = E_EOF; } else if (tok->start != NULL) { @@ -892,12 +892,12 @@ tok_nextc(struct tok_state *tok) size_t newlen = oldlen + strlen(newtok); Py_ssize_t cur_multi_line_start = tok->multi_line_start - tok->buf; char *buf = tok->buf; - buf = (char *)PyMem_REALLOC(buf, newlen+1); + buf = (char *)PyMem_Realloc(buf, newlen+1); tok->lineno++; if (buf == NULL) { - PyMem_FREE(tok->buf); + PyMem_Free(tok->buf); tok->buf = NULL; - PyMem_FREE(newtok); + PyMem_Free(newtok); tok->done = E_NOMEM; return EOF; } @@ -906,7 +906,7 @@ tok_nextc(struct tok_state *tok) tok->multi_line_start = tok->buf + cur_multi_line_start; tok->line_start = tok->cur; strcpy(tok->buf + oldlen, newtok); - PyMem_FREE(newtok); + PyMem_Free(newtok); tok->inp = tok->buf + newlen; tok->end = tok->inp + 1; tok->start = tok->buf + start; @@ -914,7 +914,7 @@ tok_nextc(struct tok_state *tok) else { tok->lineno++; if (tok->buf != NULL) - PyMem_FREE(tok->buf); + PyMem_Free(tok->buf); tok->buf = newtok; tok->cur = tok->buf; tok->line_start = tok->buf; @@ -929,7 +929,7 @@ tok_nextc(struct tok_state *tok) if (tok->start == NULL) { if (tok->buf == NULL) { tok->buf = (char *) - PyMem_MALLOC(BUFSIZ); + PyMem_Malloc(BUFSIZ); if (tok->buf == NULL) { tok->done = E_NOMEM; return EOF; @@ -966,7 +966,7 @@ tok_nextc(struct tok_state *tok) Py_ssize_t curvalid = tok->inp - tok->buf; Py_ssize_t newsize = curvalid + BUFSIZ; char *newbuf = tok->buf; - newbuf = (char *)PyMem_REALLOC(newbuf, + newbuf = (char *)PyMem_Realloc(newbuf, newsize); if (newbuf == NULL) { tok->done = E_NOMEM; @@ -1851,7 +1851,7 @@ PyTokenizer_Get(struct tok_state *tok, const char **p_start, const char **p_end) encoding in the first or second line of the file (in which case the encoding should be assumed to be UTF-8). - The char* returned is malloc'ed via PyMem_MALLOC() and thus must be freed + The char* returned is malloc'ed via PyMem_Malloc() and thus must be freed by the caller. */ char * @@ -1894,7 +1894,7 @@ PyTokenizer_FindEncodingFilename(int fd, PyObject *filename) } fclose(fp); if (tok->encoding) { - encoding = (char *)PyMem_MALLOC(strlen(tok->encoding) + 1); + encoding = (char *)PyMem_Malloc(strlen(tok->encoding) + 1); if (encoding) strcpy(encoding, tok->encoding); } |