Commit dbe3767a authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #1127 from Daetalus/refcouting_nexedi_builtin

add refcouting annotation to zip builtin function
parents 125f19b2 7929c0ad
...@@ -876,7 +876,6 @@ Box* reduce(Box* f, Box* container, Box* initial) { ...@@ -876,7 +876,6 @@ Box* reduce(Box* f, Box* container, Box* initial) {
// from cpython, bltinmodule.c // from cpython, bltinmodule.c
PyObject* filterstring(PyObject* func, BoxedString* strobj) { PyObject* filterstring(PyObject* func, BoxedString* strobj) {
assert(0 && "check refcounting");
PyObject* result; PyObject* result;
Py_ssize_t i, j; Py_ssize_t i, j;
Py_ssize_t len = PyString_Size(strobj); Py_ssize_t len = PyString_Size(strobj);
...@@ -996,7 +995,6 @@ Fail_1: ...@@ -996,7 +995,6 @@ Fail_1:
} }
static PyObject* filterunicode(PyObject* func, PyObject* strobj) { static PyObject* filterunicode(PyObject* func, PyObject* strobj) {
assert(0 && "check refcounting");
PyObject* result; PyObject* result;
Py_ssize_t i, j; Py_ssize_t i, j;
Py_ssize_t len = PyUnicode_GetSize(strobj); Py_ssize_t len = PyUnicode_GetSize(strobj);
...@@ -1102,7 +1100,6 @@ Fail_1: ...@@ -1102,7 +1100,6 @@ Fail_1:
} }
static PyObject* filtertuple(PyObject* func, PyObject* tuple) { static PyObject* filtertuple(PyObject* func, PyObject* tuple) {
assert(0 && "check refcounting");
PyObject* result; PyObject* result;
Py_ssize_t i, j; Py_ssize_t i, j;
Py_ssize_t len = PyTuple_Size(tuple); Py_ssize_t len = PyTuple_Size(tuple);
...@@ -1169,7 +1166,6 @@ Fail_1: ...@@ -1169,7 +1166,6 @@ Fail_1:
} }
Box* filter2(Box* f, Box* container) { Box* filter2(Box* f, Box* container) {
assert(0 && "check refcounting");
// If the filter-function argument is None, filter() works by only returning // If the filter-function argument is None, filter() works by only returning
// the elements that are truthy. This is equivalent to using the bool() constructor. // the elements that are truthy. This is equivalent to using the bool() constructor.
// - actually since we call nonzero() afterwards, we could use an ident() function // - actually since we call nonzero() afterwards, we could use an ident() function
...@@ -1204,40 +1200,44 @@ Box* filter2(Box* f, Box* container) { ...@@ -1204,40 +1200,44 @@ Box* filter2(Box* f, Box* container) {
} }
Box* rtn = new BoxedList(); Box* rtn = new BoxedList();
AUTO_DECREF(rtn);
for (Box* e : container->pyElements()) { for (Box* e : container->pyElements()) {
AUTO_DECREF(e);
Box* r = runtimeCall(f, ArgPassSpec(1), e, NULL, NULL, NULL, NULL); Box* r = runtimeCall(f, ArgPassSpec(1), e, NULL, NULL, NULL, NULL);
AUTO_DECREF(r);
bool b = nonzero(r); bool b = nonzero(r);
if (b) if (b)
listAppendInternal(rtn, e); listAppendInternal(rtn, e);
} }
return rtn; return incref(rtn);
} }
Box* zip(BoxedTuple* containers) { Box* zip(BoxedTuple* containers) {
assert(0 && "check refcounting");
assert(containers->cls == tuple_cls); assert(containers->cls == tuple_cls);
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
AUTO_DECREF(rtn);
if (containers->size() == 0) if (containers->size() == 0)
return rtn; return incref(rtn);
std::vector<BoxIteratorRange> ranges; std::vector<BoxIteratorRange> ranges;
for (auto container : *containers) { for (auto container : *containers) {
ranges.push_back(container->pyElements()); ranges.push_back(std::move(container->pyElements()));
} }
std::vector<BoxIterator> iterators; std::vector<BoxIterator> iterators;
for (auto&& range : ranges) { for (auto&& range : ranges) {
iterators.push_back(range.begin()); iterators.push_back(std::move(range.begin()));
} }
while (true) { while (true) {
for (int i = 0; i < iterators.size(); i++) { for (int i = 0; i < iterators.size(); i++) {
if (iterators[i] == ranges[i].end()) if (iterators[i] == ranges[i].end())
return rtn; return incref(rtn);
} }
auto el = BoxedTuple::create(iterators.size()); auto el = BoxedTuple::create(iterators.size());
AUTO_DECREF(el);
for (int i = 0; i < iterators.size(); i++) { for (int i = 0; i < iterators.size(); i++) {
el->elts[i] = *iterators[i]; el->elts[i] = *iterators[i];
++(iterators[i]); ++(iterators[i]);
...@@ -1786,14 +1786,19 @@ Box* builtinCmp(Box* a, Box* b) { ...@@ -1786,14 +1786,19 @@ Box* builtinCmp(Box* a, Box* b) {
return PyInt_FromLong((long)c); return PyInt_FromLong((long)c);
} }
Box* builtinApply(Box* func, Box* args, Box* keywords) { Box* builtinApply(Box* func, Box* _args, Box* keywords) {
assert(0 && "check refcounting"); Box* args;
if (!PyTuple_Check(args)) { if (!PyTuple_Check(_args)) {
if (!PySequence_Check(args)) if (!PySequence_Check(_args))
raiseExcHelper(TypeError, "apply() arg 2 expected sequence, found %s", getTypeName(args)); raiseExcHelper(TypeError, "apply() arg 2 expected sequence, found %s", getTypeName(_args));
args = PySequence_Tuple(args); args = PySequence_Tuple(_args);
checkAndThrowCAPIException(); checkAndThrowCAPIException();
} else {
args = incref(_args);
} }
AUTO_DECREF(args);
if (keywords && !PyDict_Check(keywords)) if (keywords && !PyDict_Check(keywords))
raiseExcHelper(TypeError, "apply() arg 3 expected dictionary, found %s", getTypeName(keywords)); raiseExcHelper(TypeError, "apply() arg 3 expected dictionary, found %s", getTypeName(keywords));
return runtimeCall(func, ArgPassSpec(0, 0, true, keywords != NULL), args, keywords, NULL, NULL, NULL); return runtimeCall(func, ArgPassSpec(0, 0, true, keywords != NULL), args, keywords, NULL, NULL, NULL);
......
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