Commit 16cbc3bc authored by Tiago Peixoto's avatar Tiago Peixoto

topology: Fix issue with returned iterators leaving dangling references

parent 07196449
......@@ -38,8 +38,7 @@ boost::python::object get_max_cliques(GraphInterface& gi)
[&](auto& s)
{
std::vector<size_t> v(s.begin(), s.end());
auto c = wrap_vector_owned(v);
yield(c);
yield(wrap_vector_owned(v));
});
})();
};
......@@ -49,26 +48,7 @@ boost::python::object get_max_cliques(GraphInterface& gi)
#endif // HAVE_BOOST_COROUTINE
}
boost::python::list get_max_cliques_list(GraphInterface& gi)
{
boost::python::list cliques;
run_action<>()
(gi,
[&](auto& g)
{
max_cliques(g,
[&](auto& s)
{
std::vector<size_t> v(s.begin(), s.end());
cliques.append(wrap_vector_owned(v));
});
})();
return cliques;
}
void export_max_cliques()
{
boost::python::def("max_cliques", &get_max_cliques);
boost::python::def("max_cliques_list", &get_max_cliques_list);
};
......@@ -864,10 +864,8 @@ def max_cliques(g, iterator=True):
if g.is_directed():
g = GraphView(g, directed=False)
if iterator:
return libgraph_tool_topology.max_cliques(g._Graph__graph)
return libgraph_tool_topology.max_cliques_list(g._Graph__graph)
for c in libgraph_tool_topology.max_cliques(g._Graph__graph):
yield c
def min_spanning_tree(g, weights=None, root=None, tree_map=None):
"""
......@@ -2296,7 +2294,8 @@ def all_shortest_paths(g, source, target, weights=None, negative_weights=False,
int(source),
int(target),
_prop("v", g, all_preds_map))
return path_iterator
for p in path_iterator:
yield p
def all_paths(g, source, target, cutoff=None, edges=False):
"""Return an iterator over all paths from `source` to `target`.
......@@ -2353,7 +2352,8 @@ def all_paths(g, source, target, cutoff=None, edges=False):
cutoff,
_prop("v", g, visited),
edges)
return path_iterator
for p in path_iterator:
yield p
def all_circuits(g, unique=False):
"""Return an iterator over all the cycles in a directed graph.
......
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