Opened 8 years ago

#10086 new Bugs

Backwards compatibility to 1.42 adjacency list serialisation is broken

Reported by: oluedecke@… Owned by: Jeremiah Willcock
Milestone: To Be Determined Component: graph
Version: Boost 1.55.0 Severity: Regression
Keywords: Cc:

Description

I have an archive created with boost serialization of an adjacency list which was created with boost 1.42. When switching to Boost 1.55, the adjacency list cannot be deserialised from the archive anymore.

I identified commit [77549] which probably broke the serialisation: It appears that the vertex and edges are not wrapped in a 'property' anymore, but stored directly in the adjacency list. Additionaly, in [77615] a new member "graph_property" was added to the serialisation code.

Unfortunately, the serialisation version number of adjacency list was not incremented and the code in 'boost/graph/adj_list_serialize.hpp' was not changed accordingly.

Furthermore in 'boost/pending/property_serialize.hpp', the serialisation order of 'value' and 'base' was switched, again without changing the class serialisation version number.

I was able to load the old archive by making following changes:

adj_list_serialize.hpp

template<class Archive, class OEL, class VL, class D,
     class VP, class EP, class GP, class EL>
inline void load(
    Archive & ar,
    boost::adjacency_list<OEL,VL,D,VP,EP,GP,EL> &graph,
    const unsigned int /* file_version */
){
  typedef adjacency_list<OEL,VL,D,VP,EP,GP,EL> Graph;
  typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
  typedef typename graph_traits<Graph>::edge_descriptor Edge;

  unsigned int V;
  ar >> BOOST_SERIALIZATION_NVP(V);
  unsigned int E;
  ar >> BOOST_SERIALIZATION_NVP(E);
  
  std::vector<Vertex> verts(V);
  int i = 0;
  while(V-- > 0){
    // >>>>> BOOST_ADJ_LIST_1_42_SERIALIZATION_PATCH
    if( ar.get_library_version() <= 7 /* not sure about the 7, could be a greater version */){
      Vertex v = add_vertex(graph);
      boost::property<boost::vertex_bundle_t, VP> vertexAsProperty;
      ar >> vertexAsProperty;
      graph[v] = vertexAsProperty.m_value;
      verts[i++] = v;
    }
    else
    // <<<<< BOOST_ADJ_LIST_1_42_SERIALIZATION_PATCH
    {
      Vertex v = add_vertex(graph);
      verts[i++] = v;
      ar >> serialization::make_nvp("vertex_property", get(vertex_all_t(), graph, v) );
    }
  }
  while(E-- > 0){
    // >>>>> BOOST_ADJ_LIST_1_42_SERIALIZATION_PATCH
    if( ar.get_library_version() <= 7 /* not sure about the 7, could be a greater version */){
      int u; int v;
      ar >> BOOST_SERIALIZATION_NVP(u);
      ar >> BOOST_SERIALIZATION_NVP(v);
      Edge e; bool inserted;
      boost::tie(e,inserted) = add_edge(verts[u], verts[v], graph);
      boost::property<boost::edge_bundle_t, EP> edgeAsProperty;
      ar >> edgeAsProperty;
      graph[e] = edgeAsProperty.m_value;
    }
    else
    // <<<<< BOOST_ADJ_LIST_1_42_SERIALIZATION_PATCH
    {
      int u; int v;
      ar >> BOOST_SERIALIZATION_NVP(u);
      ar >> BOOST_SERIALIZATION_NVP(v);
      Edge e; bool inserted;
      boost::tie(e,inserted) = add_edge(verts[u], verts[v], graph);
      ar >> serialization::make_nvp("edge_property", get(edge_all_t(), graph, e) );
    }
  }

  // >>>>> BOOST_ADJ_LIST_1_42_SERIALIZATION_PATCH
  if(are_Adjacency_list_and_boost_property_in_old_format(ar) == false)
    ar >> serialization::make_nvp("graph_property", get_property(graph, graph_all_t()) );
  // <<<<< BOOST_ADJ_LIST_1_42_SERIALIZATION_PATCH
}

property_serialize.hpp

template<class Archive, class Tag, class T, class Base>
  void 
  serialize(Archive& ar, property<Tag, T, Base>& prop, 
            const unsigned int /*version*/) 
  {
    // >>>>> BOOST_ADJ_LIST_1_42_SERIALIZATION_PATCH
    if( ar.get_library_version() <= 7 /* not sure about the 7, could be a greater version */){
      ar & serialization::make_nvp( "property_base" , prop.m_base);
      ar & serialization::make_nvp( "property_value" , prop.m_value );
    }
    else
    // <<<<< BOOST_ADJ_LIST_1_42_SERIALIZATION_PATCH
    {
      ar & serialization::make_nvp( "property_value" , prop.m_value );
      ar & serialization::make_nvp( "property_base" , prop.m_base );
    }
  }

Change History (0)

Note: See TracTickets for help on using tickets.