Skip to content

Commit 949ad62

Browse files
committed
Some more recursion-depth-checking fixes
- Fix a test to do the correct number of iterations - Catch more exceptions in PyDict_GetItem (now that more things can throw)
1 parent 7e2cbb5 commit 949ad62

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/runtime/dict.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,23 @@ extern "C" BORROWED(PyObject*) PyDict_GetItem(PyObject* dict, PyObject* key) noe
360360
if (PyDict_Check(dict)) {
361361
BoxedDict* d = static_cast<BoxedDict*>(dict);
362362

363+
BoxAndHash h;
364+
try {
365+
h = BoxAndHash(key);
366+
} catch (ExcInfo e) {
367+
e.clear();
368+
return NULL;
369+
}
370+
363371
/* preserve the existing exception */
364372
PyObject* err_type, *err_value, *err_tb;
365373
PyErr_Fetch(&err_type, &err_value, &err_tb);
366-
Box* b = d->getOrNull(key);
374+
Box* b = NULL;
375+
try {
376+
b = d->getOrNull(h);
377+
} catch (ExcInfo e) {
378+
e.clear();
379+
}
367380
/* ignore errors */
368381
PyErr_Restore(err_type, err_value, err_tb);
369382
return b;

src/runtime/types.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,13 +1035,17 @@ class BoxedDict : public Box {
10351035

10361036
DEFAULT_CLASS_SIMPLE(dict_cls, true);
10371037

1038-
BORROWED(Box*) getOrNull(Box* k) {
1039-
const auto& p = d.find(BoxAndHash(k));
1038+
BORROWED(Box*) getOrNull(BoxAndHash k) {
1039+
const auto& p = d.find(k);
10401040
if (p != d.end())
10411041
return p->second;
10421042
return NULL;
10431043
}
10441044

1045+
BORROWED(Box*) getOrNull(Box* k) {
1046+
return getOrNull(BoxAndHash(k));
1047+
}
1048+
10451049
class iterator {
10461050
private:
10471051
DictMap::iterator it;

test/tests/generator_recursion_checking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ def test(n):
77
g.next()
88
l.append(g)
99

10-
for i in xrange(1000):
10+
for i in xrange(3):
1111
test(3500)

0 commit comments

Comments
 (0)