Skip to content

Commit 749d3bc

Browse files
authored
[3.8] bpo-41132: Use pymalloc allocator in the f-string parser (GH-21173) (GH-21184)
Automerge-Triggered-By: @pablogsal
1 parent 027bba2 commit 749d3bc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Python/ast.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4898,7 +4898,7 @@ fstring_compile_expr(const char *expr_start, const char *expr_end,
48984898

48994899
len = expr_end - expr_start;
49004900
/* Allocate 3 extra bytes: open paren, close paren, null byte. */
4901-
str = PyMem_RawMalloc(len + 3);
4901+
str = PyMem_Malloc(len + 3);
49024902
if (str == NULL) {
49034903
PyErr_NoMemory();
49044904
return NULL;
@@ -4914,15 +4914,15 @@ fstring_compile_expr(const char *expr_start, const char *expr_end,
49144914
mod_n = PyParser_SimpleParseStringFlagsFilename(str, "<fstring>",
49154915
Py_eval_input, 0);
49164916
if (!mod_n) {
4917-
PyMem_RawFree(str);
4917+
PyMem_Free(str);
49184918
return NULL;
49194919
}
49204920
/* Reuse str to find the correct column offset. */
49214921
str[0] = '{';
49224922
str[len+1] = '}';
49234923
fstring_fix_node_location(n, mod_n, str);
49244924
mod = PyAST_FromNode(mod_n, &cf, "<fstring>", c->c_arena);
4925-
PyMem_RawFree(str);
4925+
PyMem_Free(str);
49264926
PyNode_Free(mod_n);
49274927
if (!mod)
49284928
return NULL;
@@ -5438,17 +5438,17 @@ ExprList_Append(ExprList *l, expr_ty exp)
54385438
Py_ssize_t i;
54395439
/* We're still using the cached data. Switch to
54405440
alloc-ing. */
5441-
l->p = PyMem_RawMalloc(sizeof(expr_ty) * new_size);
5441+
l->p = PyMem_Malloc(sizeof(expr_ty) * new_size);
54425442
if (!l->p)
54435443
return -1;
54445444
/* Copy the cached data into the new buffer. */
54455445
for (i = 0; i < l->size; i++)
54465446
l->p[i] = l->data[i];
54475447
} else {
54485448
/* Just realloc. */
5449-
expr_ty *tmp = PyMem_RawRealloc(l->p, sizeof(expr_ty) * new_size);
5449+
expr_ty *tmp = PyMem_Realloc(l->p, sizeof(expr_ty) * new_size);
54505450
if (!tmp) {
5451-
PyMem_RawFree(l->p);
5451+
PyMem_Free(l->p);
54525452
l->p = NULL;
54535453
return -1;
54545454
}
@@ -5476,7 +5476,7 @@ ExprList_Dealloc(ExprList *l)
54765476
/* Do nothing. */
54775477
} else {
54785478
/* We have dynamically allocated. Free the memory. */
5479-
PyMem_RawFree(l->p);
5479+
PyMem_Free(l->p);
54805480
}
54815481
l->p = NULL;
54825482
l->size = -1;

0 commit comments

Comments
 (0)