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

Fix segfault on f-string #32

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ast3/Custom/typed_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ err_free(perrdetail *err)

// copy of PyParser_ASTFromStringObject in Python/pythonrun.c
/* Preferred access to parser is through AST. */
static mod_ty
mod_ty
string_object_to_c_ast(const char *s, PyObject *filename, int start,
PyCompilerFlags *flags, int feature_version,
PyArena *arena)
Expand Down
14 changes: 11 additions & 3 deletions ast3/Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ static int validate_nonempty_seq(asdl_seq *, const char *, const char *);
static int validate_stmt(stmt_ty);
static int validate_expr(expr_ty, expr_context_ty);

mod_ty
string_object_to_c_ast(const char *s, PyObject *filename, int start,
PyCompilerFlags *flags, int feature_version,
PyArena *arena);

static int
validate_comprehension(asdl_seq *gens)
{
Expand Down Expand Up @@ -4362,7 +4367,7 @@ fstring_compile_expr(const char *expr_start, const char *expr_end,
PyCompilerFlags cf;
mod_ty mod;
char *str;
PyObject *o;
PyObject *o, *fstring_name;
Py_ssize_t len;
Py_ssize_t i;

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

cf.cf_flags = PyCF_ONLY_AST;
mod = PyParser_ASTFromString(str, "<fstring>",
Py_eval_input, &cf, c->c_arena);
fstring_name = PyUnicode_FromString("<fstring>");
mod = string_object_to_c_ast(str, fstring_name,
Py_eval_input, &cf,
c->c_feature_version, c->c_arena);
Py_DECREF(fstring_name);
PyMem_RawFree(str);
if (!mod)
return NULL;
Expand Down