Commit b596a71a authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by Kevin Modzelewski

Some more recursion-depth-checking fixes

- Fix a test to do the correct number of iterations
- Catch more exceptions in PyDict_GetItem/createModule (now that more things can throw)
parent 7e2cbb56
......@@ -434,7 +434,13 @@ extern "C" PyObject* Py_InitModule4(const char* name, PyMethodDef* methods, cons
}
}
BoxedModule* module = createModule(autoDecref(boxString(name)), NULL, doc);
BoxedModule* module;
try {
module = createModule(autoDecref(boxString(name)), NULL, doc);
} catch (ExcInfo e) {
setCAPIException(e);
return NULL;
}
// Pass self as is, even if NULL we are not allowed to change it to None
Box* passthrough = static_cast<Box*>(self);
......
......@@ -975,7 +975,7 @@ class BoxedClass;
// TODO these shouldn't be here
void setupRuntime();
Box* createAndRunModule(BoxedString* name, const std::string& fn);
BORROWED(BoxedModule*) createModule(BoxedString* name, const char* fn = NULL, const char* doc = NULL) noexcept;
BORROWED(BoxedModule*) createModule(BoxedString* name, const char* fn = NULL, const char* doc = NULL);
Box* moduleInit(BoxedModule* self, Box* name, Box* doc = NULL);
// TODO where to put this
......
......@@ -360,10 +360,23 @@ extern "C" BORROWED(PyObject*) PyDict_GetItem(PyObject* dict, PyObject* key) noe
if (PyDict_Check(dict)) {
BoxedDict* d = static_cast<BoxedDict*>(dict);
BoxAndHash h;
try {
h = BoxAndHash(key);
} catch (ExcInfo e) {
e.clear();
return NULL;
}
/* preserve the existing exception */
PyObject* err_type, *err_value, *err_tb;
PyErr_Fetch(&err_type, &err_value, &err_tb);
Box* b = d->getOrNull(key);
Box* b = NULL;
try {
b = d->getOrNull(h);
} catch (ExcInfo e) {
e.clear();
}
/* ignore errors */
PyErr_Restore(err_type, err_value, err_tb);
return b;
......
......@@ -4725,7 +4725,7 @@ void setupRuntime() {
TRACK_ALLOCATIONS = true;
}
BORROWED(BoxedModule*) createModule(BoxedString* name, const char* fn, const char* doc) noexcept {
BORROWED(BoxedModule*) createModule(BoxedString* name, const char* fn, const char* doc) {
assert((!fn || strlen(fn)) && "probably wanted to set the fn to <stdin>?");
BoxedDict* d = getSysModulesDict();
......
......@@ -1035,13 +1035,15 @@ public:
DEFAULT_CLASS_SIMPLE(dict_cls, true);
BORROWED(Box*) getOrNull(Box* k) {
const auto& p = d.find(BoxAndHash(k));
BORROWED(Box*) getOrNull(BoxAndHash k) {
const auto& p = d.find(k);
if (p != d.end())
return p->second;
return NULL;
}
BORROWED(Box*) getOrNull(Box* k) { return getOrNull(BoxAndHash(k)); }
class iterator {
private:
DictMap::iterator it;
......
......@@ -7,5 +7,5 @@ def test(n):
g.next()
l.append(g)
for i in xrange(1000):
for i in xrange(3):
test(3500)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment