summaryrefslogtreecommitdiff
path: root/ext/psych
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-19 03:24:13 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-19 03:24:13 +0000
commitc1b29ff5c6db8dd9a4d3508896eb3856eb9974da (patch)
tree2389042e7eed64487d74643f81710c9290912ccf /ext/psych
parent15335f8aaa8282fd951935135aa04b3d938a267c (diff)
* ext/psych/lib/psych.rb: Adding Psych::Exception
* ext/psych/parser.c: Do not allow extern_encoding to be set twice * test/psych/test_parser.rb: test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych')
-rw-r--r--ext/psych/lib/psych.rb3
-rw-r--r--ext/psych/parser.c7
2 files changed, 10 insertions, 0 deletions
diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb
index 464fae499e..a73b89212c 100644
--- a/ext/psych/lib/psych.rb
+++ b/ext/psych/lib/psych.rb
@@ -94,6 +94,9 @@ module Psych
# The version of libyaml Psych is using
LIBYAML_VERSION = Psych.libyaml_version.join '.'
+ class Exception < RuntimeError
+ end
+
###
# Load +yaml+ in to a Ruby data structure. If multiple documents are
# provided, the object contained in the first document will be returned.
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index 41260ab6f5..c8b92a0fcd 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -293,8 +293,15 @@ static VALUE parse(VALUE self, VALUE yaml)
static VALUE set_external_encoding(VALUE self, VALUE encoding)
{
yaml_parser_t * parser;
+ VALUE exception;
Data_Get_Struct(self, yaml_parser_t, parser);
+
+ if(parser->encoding) {
+ exception = rb_const_get_at(mPsych, rb_intern("Exception"));
+ rb_raise(exception, "don't set the encoding twice!");
+ }
+
yaml_parser_set_encoding(parser, NUM2INT(encoding));
return encoding;