mirror of
https://github.com/python/cpython.git
synced 2025-09-09 02:11:51 +00:00
[3.9] bpo-41132: Use pymalloc allocator in the f-string parser (GH-21173) (GH-21183)
(cherry picked from commit 6dcbc2422d
)
Automerge-Triggered-By: @pablogsal
This commit is contained in:
parent
9191eacf9e
commit
5193d0a665
2 changed files with 14 additions and 14 deletions
|
@ -597,7 +597,7 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end,
|
||||||
|
|
||||||
len = expr_end - expr_start;
|
len = expr_end - expr_start;
|
||||||
/* Allocate 3 extra bytes: open paren, close paren, null byte. */
|
/* Allocate 3 extra bytes: open paren, close paren, null byte. */
|
||||||
str = PyMem_RawMalloc(len + 3);
|
str = PyMem_Malloc(len + 3);
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -610,7 +610,7 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end,
|
||||||
|
|
||||||
struct tok_state* tok = PyTokenizer_FromString(str, 1);
|
struct tok_state* tok = PyTokenizer_FromString(str, 1);
|
||||||
if (tok == NULL) {
|
if (tok == NULL) {
|
||||||
PyMem_RawFree(str);
|
PyMem_Free(str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(p->tok->filename);
|
Py_INCREF(p->tok->filename);
|
||||||
|
@ -636,7 +636,7 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end,
|
||||||
result = expr;
|
result = expr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
PyMem_RawFree(str);
|
PyMem_Free(str);
|
||||||
_PyPegen_Parser_Free(p2);
|
_PyPegen_Parser_Free(p2);
|
||||||
PyTokenizer_Free(tok);
|
PyTokenizer_Free(tok);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1148,7 +1148,7 @@ ExprList_Append(ExprList *l, expr_ty exp)
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
/* We're still using the cached data. Switch to
|
/* We're still using the cached data. Switch to
|
||||||
alloc-ing. */
|
alloc-ing. */
|
||||||
l->p = PyMem_RawMalloc(sizeof(expr_ty) * new_size);
|
l->p = PyMem_Malloc(sizeof(expr_ty) * new_size);
|
||||||
if (!l->p) {
|
if (!l->p) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1158,9 +1158,9 @@ ExprList_Append(ExprList *l, expr_ty exp)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Just realloc. */
|
/* Just realloc. */
|
||||||
expr_ty *tmp = PyMem_RawRealloc(l->p, sizeof(expr_ty) * new_size);
|
expr_ty *tmp = PyMem_Realloc(l->p, sizeof(expr_ty) * new_size);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
PyMem_RawFree(l->p);
|
PyMem_Free(l->p);
|
||||||
l->p = NULL;
|
l->p = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1188,7 +1188,7 @@ ExprList_Dealloc(ExprList *l)
|
||||||
/* Do nothing. */
|
/* Do nothing. */
|
||||||
} else {
|
} else {
|
||||||
/* We have dynamically allocated. Free the memory. */
|
/* We have dynamically allocated. Free the memory. */
|
||||||
PyMem_RawFree(l->p);
|
PyMem_Free(l->p);
|
||||||
}
|
}
|
||||||
l->p = NULL;
|
l->p = NULL;
|
||||||
l->size = -1;
|
l->size = -1;
|
||||||
|
|
14
Python/ast.c
14
Python/ast.c
|
@ -4765,7 +4765,7 @@ fstring_compile_expr(const char *expr_start, const char *expr_end,
|
||||||
|
|
||||||
len = expr_end - expr_start;
|
len = expr_end - expr_start;
|
||||||
/* Allocate 3 extra bytes: open paren, close paren, null byte. */
|
/* Allocate 3 extra bytes: open paren, close paren, null byte. */
|
||||||
str = PyMem_RawMalloc(len + 3);
|
str = PyMem_Malloc(len + 3);
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -4781,7 +4781,7 @@ fstring_compile_expr(const char *expr_start, const char *expr_end,
|
||||||
mod_n = PyParser_SimpleParseStringFlagsFilename(str, "<fstring>",
|
mod_n = PyParser_SimpleParseStringFlagsFilename(str, "<fstring>",
|
||||||
Py_eval_input, 0);
|
Py_eval_input, 0);
|
||||||
if (!mod_n) {
|
if (!mod_n) {
|
||||||
PyMem_RawFree(str);
|
PyMem_Free(str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Reuse str to find the correct column offset. */
|
/* Reuse str to find the correct column offset. */
|
||||||
|
@ -4789,7 +4789,7 @@ fstring_compile_expr(const char *expr_start, const char *expr_end,
|
||||||
str[len+1] = '}';
|
str[len+1] = '}';
|
||||||
fstring_fix_node_location(n, mod_n, str);
|
fstring_fix_node_location(n, mod_n, str);
|
||||||
mod = PyAST_FromNode(mod_n, &cf, "<fstring>", c->c_arena);
|
mod = PyAST_FromNode(mod_n, &cf, "<fstring>", c->c_arena);
|
||||||
PyMem_RawFree(str);
|
PyMem_Free(str);
|
||||||
PyNode_Free(mod_n);
|
PyNode_Free(mod_n);
|
||||||
if (!mod)
|
if (!mod)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -5305,7 +5305,7 @@ ExprList_Append(ExprList *l, expr_ty exp)
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
/* We're still using the cached data. Switch to
|
/* We're still using the cached data. Switch to
|
||||||
alloc-ing. */
|
alloc-ing. */
|
||||||
l->p = PyMem_RawMalloc(sizeof(expr_ty) * new_size);
|
l->p = PyMem_Malloc(sizeof(expr_ty) * new_size);
|
||||||
if (!l->p)
|
if (!l->p)
|
||||||
return -1;
|
return -1;
|
||||||
/* Copy the cached data into the new buffer. */
|
/* Copy the cached data into the new buffer. */
|
||||||
|
@ -5313,9 +5313,9 @@ ExprList_Append(ExprList *l, expr_ty exp)
|
||||||
l->p[i] = l->data[i];
|
l->p[i] = l->data[i];
|
||||||
} else {
|
} else {
|
||||||
/* Just realloc. */
|
/* Just realloc. */
|
||||||
expr_ty *tmp = PyMem_RawRealloc(l->p, sizeof(expr_ty) * new_size);
|
expr_ty *tmp = PyMem_Realloc(l->p, sizeof(expr_ty) * new_size);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
PyMem_RawFree(l->p);
|
PyMem_Free(l->p);
|
||||||
l->p = NULL;
|
l->p = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -5343,7 +5343,7 @@ ExprList_Dealloc(ExprList *l)
|
||||||
/* Do nothing. */
|
/* Do nothing. */
|
||||||
} else {
|
} else {
|
||||||
/* We have dynamically allocated. Free the memory. */
|
/* We have dynamically allocated. Free the memory. */
|
||||||
PyMem_RawFree(l->p);
|
PyMem_Free(l->p);
|
||||||
}
|
}
|
||||||
l->p = NULL;
|
l->p = NULL;
|
||||||
l->size = -1;
|
l->size = -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue