certik / yaml-cpp

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

strange crashes involving node reuse #207

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Run example program with example input

What is the expected output? What do you see instead?
No crashes are expected, instead something seems to linger:

call 0
hello
1
5
call 1
true
terminate called after throwing an instance of 'YAML::TypedBadConversion<bool>'
  what():  yaml-cpp: error at line 0, column 0: bad conversion
Aborted

What version of the product are you using? On what operating system?
0.5.1 - linux, 64bit and compiling with gcc 4.8.1

Please provide any additional information below.

compile and run as so:
g++ -std=c++11 -ggdb -O0 -DDEBUG test.cpp -lyaml-cpp -o test_yaml; ./test_yaml

Original issue reported on code.google.com by nev...@gmail.com on 6 Jun 2013 at 11:00

Attachments:

GoogleCodeExporter commented 9 years ago
if possible, please publish a patch asap, the timing of this bug is a bit 
inconvenient.

Original comment by nev...@gmail.com on 6 Jun 2013 at 11:02

GoogleCodeExporter commented 9 years ago
This is intended behavior. You're modifying the existing node. Specifically, 
consider:

YAML::Node doc = YAML::Load("{a: 1, b: 2}");
YAML::Node a = doc["a"];
a = doc["b"];

The third line is semantically the same as

doc["a"] = doc["b"];

In the new API, yaml-cpp treats = as setting identity. The result is that the 
document now looks like

b: &x 2
a: *x

Note that you're not getting a "crash"; instead, it's throwing an exception, 
saying that it can't convert the given value to a boolean. This is because 
you've modified the document.

Instead, you want to use reset(). E.g.:

k.reset(node["test_parm"]);

Original comment by jbe...@gmail.com on 7 Jun 2013 at 9:13

GoogleCodeExporter commented 9 years ago
OK thanks for that clarification... I have to say this while intended was
not intuitive... at this point Nodes look like an invasively fused smart
pointer and an object which may give some conveniences (where?) but differ
in behavior from either..

In any case, am I missing some explanations of this somewhere?  Are the
docs up to date regarding these new details?

Original comment by nev...@gmail.com on 7 Jun 2013 at 9:35

GoogleCodeExporter commented 9 years ago
Yeah, I agree, this is a corner case that's not intuitive. I'm really not sure 
if it's the right behavior; I'm trying to mimic python syntax, but C++ doesn't 
make that easy.

I'll look into updating the docs, and I'll continue thinking about this 
behavior more. Thanks for the note.

Original comment by jbe...@gmail.com on 7 Jun 2013 at 9:38

GoogleCodeExporter commented 9 years ago
I created an issue to track modifying this behavior, so you'll be updated if I 
can figure out what to do.

Original comment by jbe...@gmail.com on 7 Jun 2013 at 9:41