Tuesday, May 20, 2008

conflict between rbyaml and syck

(This conflict will not happen during you use rbyamlinstead of syck in your ruby compiler/interpreter.)

Most of time, you don't want to include yaml lib and rbyaml lib at the same time,
but sometimes yaml lib will be required implicitly during loading other common libraries.
For lots of libraries load yaml in therir implementations.
Here is an example.

What will reproduce the problem?
require 'rubygems' # or any file which contain yaml implicitly
require 'rbyaml'
:symbol.to_yaml # call to_yaml method of any base type object

What is the expected?
call to_yaml which defined in RbYAML library
What do you see instead?
call to_yaml which defined in SYCK library

Most of time the method from SYCK and RbYAML has the same behaviour, output.
But if there's defect in syck, that will effect rbyaml behaviour.
In this example, RbYAML only define to_yaml in Object class, when you call Symbol#to_yaml, it will call the super class method, Object#to_yaml.
But Syck define to_yaml in Object, Symbol and many base type. So if you load rbyaml after syck, rbyaml will certainly overwrite to_yaml method in Object, but will leave to_yaml method in other base type like as Symbol, Hash, etc.
After that, if you call Symbol#to_yaml, it will not call super class method which defined by RbYAML, but call Symbol#to_yaml defined in Syck. That's not our willing.

to_yaml method conflict has been fixed already, but I think there may still exist some other conflicts. I've add an issue about this in code.google.

No comments: