Commit 7929c0ad authored by Boxiang Sun's avatar Boxiang Sun

add refcounting annotation to some apply, zip builtin function

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