certik / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Error with _GLIBCXX_DEBUG #214

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile with -D_GLIBCXX_DEBUG
2. You get to see the error with the following piece of code:

#include <yaml-cpp/yaml.h>
#include <vector>
using std::vector;

int main()
{
    YAML::Node node;
    std::vector<int> n1(5, 10); 
    node["numbers"] = n1;
    vector<int> n2 = node["numbers"].as<std::vector<int> >();
    return 0;
}

You get the following output when run the above piece of code:
usr/lib/gcc/i686-redhat-linux/4.4.4/../../../../include/c++/4.4.4/debug/safe_ite
rator.h:126:
    error: attempt to copy-construct an iterator from a singular iterator.

Objects involved in the operation:
iterator "this" @ 0x0xbfdad124 {
type = 
N11__gnu_debug14_Safe_iteratorISt17_Rb_tree_iteratorISt4pairIKPN4YAML6detail4nod
eES6_EENSt7__debug3mapIS6_S6_St4lessIS6_ESaIS8_EEEEE (mutable iterator);
  state = singular;
}
iterator "other" @ 0x0xbfdad0a8 {
type = 
N11__gnu_debug14_Safe_iteratorISt17_Rb_tree_iteratorISt4pairIKPN4YAML6detail4nod
eES6_EENSt7__debug3mapIS6_S6_St4lessIS6_ESaIS8_EEEEE (mutable iterator);
  state = singular;
}
Aborted

What version of the product are you using? On what operating system?
0.5.1 on Linux

Original issue reported on code.google.com by mm.st...@gmail.com on 22 Jul 2013 at 11:17

GoogleCodeExporter commented 9 years ago
Do you have a stack trace?

Original comment by jbe...@gmail.com on 22 Jul 2013 at 1:14

GoogleCodeExporter commented 9 years ago

Original comment by jbe...@gmail.com on 22 Jul 2013 at 1:16

GoogleCodeExporter commented 9 years ago
Thanks for checking the defect. 

Stack trace looks like this:
#0  YAML::detail::node_data::begin (this=0x80704e0) at 
/data/tmp/tmp/yaml_expt_2/yaml-cpp/src/node_data.cpp:121
#1  0x0804b648 in YAML::detail::node_ref::begin (this=0x80701b8) at 
./yaml-cpp/include/yaml-cpp/node/detail/node_ref.h:41
#2  0x0804ba04 in YAML::detail::node::begin (this=0x8070358) at 
./yaml-cpp/include/yaml-cpp/node/detail/node.h:84
#3  0x0804c127 in YAML::Node::begin (this=0xbfffed40) at 
./yaml-cpp/include/yaml-cpp/node/impl.h:286
#4  0x0804fa9c in YAML::convert<std::__debug::vector<int, std::allocator<int> 
>   >::decode (node=..., rhs=...) at 
./yaml-cpp/include/yaml-cpp/node/convert.h:190
#5  0x0804e8f5 in YAML::as_if<std::__debug::vector<int, std::allocator<int> >, 
void>::operator() (this=0xbfffecac) at 
./yaml-cpp/include/yaml-cpp/node/impl.h:119
#6  0x0804d972 in YAML::Node::as<std::__debug::vector<int, std::allocator<int> 
> > (this=0xbfffed40) at ./yaml-cpp/include/yaml-cpp/node/impl.h:143
#7  0x0804a3ac in main () at test1.cpp:10

Original comment by mm.st...@gmail.com on 22 Jul 2013 at 2:54

GoogleCodeExporter commented 9 years ago
To reproduce the above I did the following:
1. Modified top level CMakeLists.txt to add _GLIBCXX_DEBUG in Debug mode:

   diff -r c93a3c943d96 CMakeLists.txt
--- a/CMakeLists.txt    Wed Jul 10 08:29:11 2013 -0500
+++ b/CMakeLists.txt    Mon Jul 22 15:58:10 2013 +0100
@@ -129,7 +129,7 @@
    #
    set(CMAKE_CXX_FLAGS_RELEASE "-O2")
    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
-   set(CMAKE_CXX_FLAGS_DEBUG "-g")
+   set(CMAKE_CXX_FLAGS_DEBUG "-g -D_GLIBCXX_DEBUG -O0")
    set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
    #
    set(GCC_EXTRA_OPTIONS "")

2. Build the lib:
   $ cmake -DCMAKE_BUILD_TYPE=Debug ../yaml-cpp/
   $ make

2. Compile attached test1.cpp with :
   g++ -O0 -g -I./yaml-cpp/include -D_GLIBCXX_DEBUG test1.cpp ./Debug/libyaml-cpp.a

Original comment by mm.st...@gmail.com on 22 Jul 2013 at 3:01

Attachments:

GoogleCodeExporter commented 9 years ago
In this case the problem could be due to YAML::detail::node_iterator_base which 
could be constructed with either a SeqIter or a MapIter. When it is constructed 
with SeqIter the MapIter member m_mapIt remains uninitialized and singular; 
hence we get the error when we try to copy construct node_iterator_base 
initialized with a sequence.
One potential solution is to use template (rather than enum) to choose sequence 
and map and have specialized implementation for each of them. Does it make 
sense ?

Original comment by mm.st...@gmail.com on 23 Jul 2013 at 8:08

GoogleCodeExporter commented 9 years ago
I have a rather ugly patch to get around this problem, check the file attached.

Original comment by mm.st...@gmail.com on 25 Jul 2013 at 12:53

Attachments:

GoogleCodeExporter commented 9 years ago
I'm unable to reproduce this, even with your CMakeLists changes.

Incidentally, the example you have at the top of this issue is nearly identical 
to the test NodeTest.StdVector:

https://code.google.com/p/yaml-cpp/source/browse/test/node/node_test.cpp?r=6f449
17eb3a2248224b8d13e3f6e04ede380da5d#95

and this test passes with the build flags you gave.

For sanity, I made sure that all sub-iterators are default-initialized, 
r86c2a73684f83be182b559b52d7df4280fb1675f, but I suspect that this doesn't do 
anything.

If you can reproduce this at tip, please reopen.

Original comment by jbe...@gmail.com on 24 Jan 2015 at 10:24