[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Discuss-gnuradio] make check failure and solution patch (faulty gr_basi
From: |
Martin Dvh |
Subject: |
[Discuss-gnuradio] make check failure and solution patch (faulty gr_basic_block sort in gr_flow_graph) |
Date: |
Mon, 11 Aug 2008 05:17:34 +0200 |
User-agent: |
Icedove 1.5.0.14pre (X11/20071018) |
Hi All,
This patch makes the sort of basic_blocks reliable in gr_flowgraph.cc
Without it make check can fail in qa_gr_flowgraph.cc:240
background:
While working with new buffer code I found that make check can fail in
qa_gr_flowgraph.cc
240: CPPUNIT_ASSERT(graphs[0].size() == 4);
The cause of this is that the subgraphs are not in the order as expected.
The code expects
graphs.size()==3
graphs[0].size()==4
graphs[1].size()==3
graphs[2].size()==2
But it gets
graphs.size()==3
graphs[0].size()==3
graphs[1].size()==2
graphs[2].size()==4
This only happens if there are a lot of big malloc /frees in code before it.
The probable cause is that a plain std::sort is used for sorting vectors of
gr_basic_block
But for gr_basic_block the operator < is not defined.
I changed the code to use basic_block->unique_id() for sorting.
This should be more robust.
(I got rid of the make check failure)
This problem might be in more parts of the code
Greetings,
Martin
Index: gr_flowgraph.cc
===================================================================
--- gr_flowgraph.cc (revision 9229)
+++ gr_flowgraph.cc (working copy)
@@ -30,6 +30,11 @@
#include <sstream>
#define GR_FLOWGRAPH_DEBUG 0
+bool
+basic_block_sort_predicate(const gr_basic_block_sptr lhs, const
gr_basic_block_sptr rhs)
+{
+ return lhs->unique_id() < rhs->unique_id();
+}
gr_edge::~gr_edge()
{
@@ -173,7 +178,8 @@
}
// Return vector of unique blocks
- sort(tmp.begin(), tmp.end());
+ //sort(tmp.begin(), tmp.end());
+ sort(tmp.begin(), tmp.end(),basic_block_sort_predicate);
unique_copy(tmp.begin(), tmp.end(), inserter);
return result;
}
@@ -272,7 +278,7 @@
tmp.push_back(p->dst().block());
// Remove duplicates
- sort(tmp.begin(), tmp.end());
+ sort(tmp.begin(), tmp.end(),basic_block_sort_predicate);
unique_copy(tmp.begin(), tmp.end(), inserter);
return result;
}
@@ -288,7 +294,7 @@
tmp.push_back(p->dst().block());
// Remove duplicates
- sort(tmp.begin(), tmp.end());
+ sort(tmp.begin(), tmp.end(),basic_block_sort_predicate);
unique_copy(tmp.begin(), tmp.end(), inserter);
return result;
}
@@ -399,7 +405,7 @@
}
// Remove duplicates
- sort(tmp.begin(), tmp.end());
+ sort(tmp.begin(), tmp.end(),basic_block_sort_predicate);
unique_copy(tmp.begin(), tmp.end(), inserter);
return result;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Discuss-gnuradio] make check failure and solution patch (faulty gr_basic_block sort in gr_flow_graph),
Martin Dvh <=