diff options
author | Benjamin Peterson <benjamin@python.org> | 2015-12-29 16:08:34 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2015-12-29 16:08:34 (GMT) |
commit | 3cc8f4b9693572e6ea423881cdbebfc981307b50 (patch) | |
tree | d4c387193a04e023c7a3dac2f79dac28536e7f7a /Python | |
parent | 01f7ac3bb07ccca254af27f046ef64f9f5641e05 (diff) | |
download | cpython-3cc8f4b9693572e6ea423881cdbebfc981307b50.zip cpython-3cc8f4b9693572e6ea423881cdbebfc981307b50.tar.gz cpython-3cc8f4b9693572e6ea423881cdbebfc981307b50.tar.bz2 |
make recording and reporting errors and nonlocal and global directives more robust (closes #25973)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/symtable.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Python/symtable.c b/Python/symtable.c index 64910d8..6d1a62b 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -368,15 +368,20 @@ error_at_directive(PySTEntryObject *ste, PyObject *name) Py_ssize_t i; PyObject *data; assert(ste->ste_directives); - for (i = 0; ; i++) { + for (i = 0; i < PyList_GET_SIZE(ste->ste_directives); i++) { data = PyList_GET_ITEM(ste->ste_directives, i); assert(PyTuple_CheckExact(data)); - if (PyTuple_GET_ITEM(data, 0) == name) - break; + assert(PyUnicode_CheckExact(PyTuple_GET_ITEM(data, 0))); + if (PyUnicode_Compare(PyTuple_GET_ITEM(data, 0), name) == 0) { + PyErr_SyntaxLocationObject(ste->ste_table->st_filename, + PyLong_AsLong(PyTuple_GET_ITEM(data, 1)), + PyLong_AsLong(PyTuple_GET_ITEM(data, 2))); + + return 0; + } } - PyErr_SyntaxLocationObject(ste->ste_table->st_filename, - PyLong_AsLong(PyTuple_GET_ITEM(data, 1)), - PyLong_AsLong(PyTuple_GET_ITEM(data, 2))); + PyErr_SetString(PyExc_RuntimeError, + "BUG: internal directive bookkeeping broken"); return 0; } @@ -1115,14 +1120,17 @@ symtable_new_tmpname(struct symtable *st) static int symtable_record_directive(struct symtable *st, identifier name, stmt_ty s) { - PyObject *data; + PyObject *data, *mangled; int res; if (!st->st_cur->ste_directives) { st->st_cur->ste_directives = PyList_New(0); if (!st->st_cur->ste_directives) return 0; } - data = Py_BuildValue("(Oii)", name, s->lineno, s->col_offset); + mangled = _Py_Mangle(st->st_private, name); + if (!mangled) + return 0; + data = Py_BuildValue("(Nii)", mangled, s->lineno, s->col_offset); if (!data) return 0; res = PyList_Append(st->st_cur->ste_directives, data); |