Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5aab44b

Browse files
committed
merge 3.5 (#25973)
2 parents bffa73e + 3cc8f4b commit 5aab44b

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

Lib/test/test_syntax.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,14 @@
416416
## ...
417417
## SyntaxWarning: name 'x' is assigned to before nonlocal declaration
418418
419+
From https://bugs.python.org/issue25973
420+
>>> class A:
421+
... def f(self):
422+
... nonlocal __x
423+
Traceback (most recent call last):
424+
...
425+
SyntaxError: no binding for nonlocal '_A__x' found
426+
419427
420428
This tests assignment-context; there was a bug in Python 2.5 where compiling
421429
a complex 'if' (one with 'elif') would fail to notice an invalid suite,

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: tba
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #25973: Fix segfault when an invalid nonlocal statement binds a name
14+
starting with two underscores.
15+
1316
- Issue #22995: Instances of extension types with a state that aren't
1417
subclasses of list or dict and haven't implemented any pickle-related
1518
methods (__reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__,

Python/symtable.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,20 @@ error_at_directive(PySTEntryObject *ste, PyObject *name)
368368
Py_ssize_t i;
369369
PyObject *data;
370370
assert(ste->ste_directives);
371-
for (i = 0; ; i++) {
371+
for (i = 0; i < PyList_GET_SIZE(ste->ste_directives); i++) {
372372
data = PyList_GET_ITEM(ste->ste_directives, i);
373373
assert(PyTuple_CheckExact(data));
374-
if (PyTuple_GET_ITEM(data, 0) == name)
375-
break;
374+
assert(PyUnicode_CheckExact(PyTuple_GET_ITEM(data, 0)));
375+
if (PyUnicode_Compare(PyTuple_GET_ITEM(data, 0), name) == 0) {
376+
PyErr_SyntaxLocationObject(ste->ste_table->st_filename,
377+
PyLong_AsLong(PyTuple_GET_ITEM(data, 1)),
378+
PyLong_AsLong(PyTuple_GET_ITEM(data, 2)));
379+
380+
return 0;
381+
}
376382
}
377-
PyErr_SyntaxLocationObject(ste->ste_table->st_filename,
378-
PyLong_AsLong(PyTuple_GET_ITEM(data, 1)),
379-
PyLong_AsLong(PyTuple_GET_ITEM(data, 2)));
383+
PyErr_SetString(PyExc_RuntimeError,
384+
"BUG: internal directive bookkeeping broken");
380385
return 0;
381386
}
382387

@@ -1115,14 +1120,17 @@ symtable_new_tmpname(struct symtable *st)
11151120
static int
11161121
symtable_record_directive(struct symtable *st, identifier name, stmt_ty s)
11171122
{
1118-
PyObject *data;
1123+
PyObject *data, *mangled;
11191124
int res;
11201125
if (!st->st_cur->ste_directives) {
11211126
st->st_cur->ste_directives = PyList_New(0);
11221127
if (!st->st_cur->ste_directives)
11231128
return 0;
11241129
}
1125-
data = Py_BuildValue("(Oii)", name, s->lineno, s->col_offset);
1130+
mangled = _Py_Mangle(st->st_private, name);
1131+
if (!mangled)
1132+
return 0;
1133+
data = Py_BuildValue("(Nii)", mangled, s->lineno, s->col_offset);
11261134
if (!data)
11271135
return 0;
11281136
res = PyList_Append(st->st_cur->ste_directives, data);

0 commit comments

Comments
 (0)