[BGL] possible Bug in property handling
Hi, I'm new to BGL (and generic programming) so this may well not be a bug but I don't know how this could be intended. Consider the following program: #include <string> #include <iostream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/properties.hpp> #include <boost/graph/adjacency_list.hpp> using namespace boost; typedef property<vertex_name_t, std::string> VertexProp; //this crashes typedef adjacency_list < vecS, vecS, undirectedS,VertexProp, no_property > graph_t; //this doesn't //typedef adjacency_list < vecS, listS, undirectedS,VertexProp, no_property > graph_t; typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor; typedef property_map<graph_t, vertex_name_t>::type id_name_map_t; typedef graph_traits<graph_t>::vertex_iterator vi_t; std::pair<vi_t,vi_t> vi; int main(){ graph_t g; vertex_descriptor vd; id_name_map_t name_map; vd=add_vertex(g); put(name_map,vd,"foo"); for (vi=vertices(g); vi.first!=vi.second;++vi.first) { std::cout<<get(name_map,*vi.first)<<std::endl; } return EXIT_SUCCESS; } From what I read in the BGL book the storage type of the edges shouldn't matter. But here using vecS gives a segfault whereas listS works fine. This is the backtrace of a gdb session: Program received signal SIGSEGV, Segmentation fault. #0 0x00007ffff79316e6 in std::string::assign(char const*, unsigned long) () from /usr/lib64/libstdc++.so.6 #1 0x00000000004016ef in boost::put<boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::property<boost::vertex_name_t, std::string, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::property<boost::vertex_name_t, std::string, boost::no_property>, boost::no_property, boost::no_property, boost::listS>*, std::string, std::string&, boost::vertex_name_t>, std::string&, unsigned long, char [4]> ( pa=@0x7fffffffdcc0, k=0, v=@0x403693) at /usr/include/boost/property_map.hpp:321 #2 0x0000000000400ee8 in main () at bug.cc:26 Version information boost-devel 1.39.0 $: g++ -v Using built-in specs. Target: x86_64-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.3 --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=x86_64-suse-linux Thread model: posix gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux)
typedef property<vertex_name_t, std::string> VertexProp; //this crashes typedef adjacency_list < vecS, vecS, undirectedS,VertexProp, no_property > graph_t; //this doesn't //typedef adjacency_list < vecS, listS, undirectedS,VertexProp, no_property
graph_t; typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor; typedef property_map<graph_t, vertex_name_t>::type id_name_map_t; typedef graph_traits<graph_t>::vertex_iterator vi_t; std::pair<vi_t,vi_t> vi;
Try writing this using bundled properties: http://www.boost.org/doc/libs/1_39_0/libs/graph/doc/bundles.html Andrew Sutton andrew.n.sutton@gmail.com
Andrew Sutton wrote:
typedef property<vertex_name_t, std::string> VertexProp; //this crashes typedef adjacency_list < vecS, vecS, undirectedS,VertexProp, no_property > graph_t; //this doesn't //typedef adjacency_list < vecS, listS, undirectedS,VertexProp, no_property
graph_t; typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor; typedef property_map<graph_t, vertex_name_t>::type id_name_map_t; typedef graph_traits<graph_t>::vertex_iterator vi_t; std::pair<vi_t,vi_t> vi;
Try writing this using bundled properties:
http://www.boost.org/doc/libs/1_39_0/libs/graph/doc/bundles.html
Okay, that's a nice thing I didn't know about, I will use that. But still what is wrong with the original code. Ralf
Try writing this using bundled properties:
http://www.boost.org/doc/libs/1_39_0/libs/graph/doc/bundles.html
Okay, that's a nice thing I didn't know about, I will use that. But still what is wrong with the original code.
I have no idea. It didn't look like anything is wrong. There may be an issue with overlapping usage of vertex_name_t, but I couldn't say for sure. Andrew Sutton andrew.n.sutton@gmail.com
On Fri, 28 Aug 2009, Ralf Goertz wrote:
Hi,
I'm new to BGL (and generic programming) so this may well not be a bug but I don't know how this could be intended. Consider the following program:
#include <string> #include <iostream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/properties.hpp> #include <boost/graph/adjacency_list.hpp>
using namespace boost;
typedef property<vertex_name_t, std::string> VertexProp; //this crashes typedef adjacency_list < vecS, vecS, undirectedS,VertexProp, no_property > graph_t; //this doesn't //typedef adjacency_list < vecS, listS, undirectedS,VertexProp, no_property > graph_t; typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor; typedef property_map<graph_t, vertex_name_t>::type id_name_map_t; typedef graph_traits<graph_t>::vertex_iterator vi_t; std::pair<vi_t,vi_t> vi;
int main(){ graph_t g; vertex_descriptor vd; id_name_map_t name_map; vd=add_vertex(g); put(name_map,vd,"foo"); for (vi=vertices(g); vi.first!=vi.second;++vi.first) { std::cout<<get(name_map,*vi.first)<<std::endl; } return EXIT_SUCCESS; }
It appears that name_map is not initialized. You need to do something like: id_name_map_t name_map = get(vertex_name, g); to get the property map before you use it. -- Jeremiah Willcock
participants (3)
-
Andrew Sutton
-
Jeremiah Willcock
-
Ralf Goertz