Skip to content
This repository was archived by the owner on Jul 5, 2023. It is now read-only.

Commit cebf4a2

Browse files
ilevkivskyiddfisher
authored andcommitted
Fix segfault on f-string (#32)
1 parent 6dba5ff commit cebf4a2

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

ast3/Custom/typed_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ err_free(perrdetail *err)
213213

214214
// copy of PyParser_ASTFromStringObject in Python/pythonrun.c
215215
/* Preferred access to parser is through AST. */
216-
static mod_ty
216+
mod_ty
217217
string_object_to_c_ast(const char *s, PyObject *filename, int start,
218218
PyCompilerFlags *flags, int feature_version,
219219
PyArena *arena)

ast3/Python/ast.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ static int validate_nonempty_seq(asdl_seq *, const char *, const char *);
2525
static int validate_stmt(stmt_ty);
2626
static int validate_expr(expr_ty, expr_context_ty);
2727

28+
mod_ty
29+
string_object_to_c_ast(const char *s, PyObject *filename, int start,
30+
PyCompilerFlags *flags, int feature_version,
31+
PyArena *arena);
32+
2833
static int
2934
validate_comprehension(asdl_seq *gens)
3035
{
@@ -4362,7 +4367,7 @@ fstring_compile_expr(const char *expr_start, const char *expr_end,
43624367
PyCompilerFlags cf;
43634368
mod_ty mod;
43644369
char *str;
4365-
PyObject *o;
4370+
PyObject *o, *fstring_name;
43664371
Py_ssize_t len;
43674372
Py_ssize_t i;
43684373

@@ -4411,8 +4416,11 @@ fstring_compile_expr(const char *expr_start, const char *expr_end,
44114416
str[len+2] = 0;
44124417

44134418
cf.cf_flags = PyCF_ONLY_AST;
4414-
mod = PyParser_ASTFromString(str, "<fstring>",
4415-
Py_eval_input, &cf, c->c_arena);
4419+
fstring_name = PyUnicode_FromString("<fstring>");
4420+
mod = string_object_to_c_ast(str, fstring_name,
4421+
Py_eval_input, &cf,
4422+
c->c_feature_version, c->c_arena);
4423+
Py_DECREF(fstring_name);
44164424
PyMem_RawFree(str);
44174425
if (!mod)
44184426
return NULL;

0 commit comments

Comments
 (0)