diff options
author | Guido van Rossum <guido@python.org> | 2019-03-12 20:38:22 -0700 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2019-03-12 20:38:22 -0700 |
commit | d72e19bcb65dc1dd9839385d5f16403f35ac3d20 (patch) | |
tree | a5f5bb9780680b26955d9ca2306be8476b6a4209 /Python/ast.c | |
parent | 0294e7cc4afd1ac701d706ffd59300eb3e008d10 (diff) | |
download | cpython-git-d72e19bcb65dc1dd9839385d5f16403f35ac3d20.tar.gz |
Change of plan: set kind to 'u' or None
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 46 |
1 files changed, 12 insertions, 34 deletions
diff --git a/Python/ast.c b/Python/ast.c index 60717340fd..253698684c 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -5390,10 +5390,8 @@ FstringParser_Dealloc(FstringParser *state) /* Constants for the following */ static PyObject *u_kind; -static PyObject *b_kind; -static PyObject *no_kind; -/* Compute 'kind' field for str/bytes Constant (either 'b', 'u' or '') */ +/* Compute 'kind' field for string Constant (either 'u' or None) */ static PyObject * make_kind(struct compiling *c, const node *n) { @@ -5408,39 +5406,19 @@ make_kind(struct compiling *c, const node *n) } REQ(n, STRING); - /* Re-parse the string until we find either 'b', 'u' or a quote */ + /* If it starts with 'u', return a PyUnicode "u" string */ s = STR(n); - while (s) { - switch (*s) { - case 'u': + if (s && *s == 'u') { + if (!u_kind) { + u_kind = PyUnicode_InternFromString("u"); if (!u_kind) - u_kind = PyUnicode_InternFromString("u"); - kind = u_kind; - s = NULL; // Break out of while loop - break; - case 'b': - if (!b_kind) - b_kind = PyUnicode_InternFromString("b"); - kind = b_kind; - s = NULL; // Break out of while loop - break; - case '\'': - case '"': - s = NULL; // Break out of while loop - break; - default: - s++; + return NULL; } - } - if (kind == NULL) { - if (!no_kind) - no_kind = PyUnicode_InternFromString(""); - kind = no_kind; - } - Py_INCREF(kind); - if (PyArena_AddPyObject(c->c_arena, kind) < 0) { - Py_DECREF(kind); - return NULL; + kind = u_kind; + if (PyArena_AddPyObject(c->c_arena, kind) < 0) { + return NULL; + } + Py_INCREF(kind); } return kind; } @@ -5831,7 +5809,7 @@ parsestrplus(struct compiling *c, const node *n) /* Just return the bytes object and we're done. */ if (PyArena_AddPyObject(c->c_arena, bytes_str) < 0) goto error; - return Constant(bytes_str, make_kind(c, n), LINENO(n), n->n_col_offset, + return Constant(bytes_str, NULL, LINENO(n), n->n_col_offset, n->n_end_lineno, n->n_end_col_offset, c->c_arena); } |