Commit ead5b73a authored by Kevin Modzelewski's avatar Kevin Modzelewski

Exception safety for min/max

parent 9b94ee3b
...@@ -188,12 +188,12 @@ Box* min_max(Box* arg0, BoxedTuple* args, BoxedDict* kwargs, int opid) { ...@@ -188,12 +188,12 @@ Box* min_max(Box* arg0, BoxedTuple* args, BoxedDict* kwargs, int opid) {
extremVal = nullptr; extremVal = nullptr;
container = arg0; container = arg0;
} else { } else {
extremElement = incref(arg0);
if (key_func != NULL) { if (key_func != NULL) {
extremVal = runtimeCall(key_func, ArgPassSpec(1), extremElement, NULL, NULL, NULL, NULL); extremVal = runtimeCall(key_func, ArgPassSpec(1), arg0, NULL, NULL, NULL, NULL);
} else { } else {
extremVal = incref(extremElement); extremVal = incref(arg0);
} }
extremElement = incref(arg0);
container = args; container = args;
} }
...@@ -205,7 +205,14 @@ Box* min_max(Box* arg0, BoxedTuple* args, BoxedDict* kwargs, int opid) { ...@@ -205,7 +205,14 @@ Box* min_max(Box* arg0, BoxedTuple* args, BoxedDict* kwargs, int opid) {
extremElement = e; extremElement = e;
continue; continue;
} }
try {
curVal = runtimeCall(key_func, ArgPassSpec(1), e, NULL, NULL, NULL, NULL); curVal = runtimeCall(key_func, ArgPassSpec(1), e, NULL, NULL, NULL, NULL);
} catch (ExcInfo ex) {
Py_DECREF(e);
Py_DECREF(extremVal);
Py_DECREF(extremElement);
throw ex;
}
} else { } else {
if (!extremElement) { if (!extremElement) {
extremVal = incref(e); extremVal = incref(e);
......
# expected: reffail
import math import math
print math.sqrt(2) print math.sqrt(2)
print math.sqrt(0) print math.sqrt(0)
......
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