aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2009-03-29 11:57:43 +0100
committerAvatar Richard Brown <rbrown@exherbo.org> 2009-03-29 11:58:09 +0100
commit1c19aa0dbf7ac341afe9603b18b89225922e029d (patch)
tree3e9bbc14a4394deed14b39eda82e106e3b037ed6
parenta4399ab2510c2249599f63abb0b684d4753f8227 (diff)
downloadpaludis-1c19aa0dbf7ac341afe9603b18b89225922e029d.tar.gz
paludis-1c19aa0dbf7ac341afe9603b18b89225922e029d.tar.xz
Check type of paramater passed to Environment.accpet_keywords
-rw-r--r--ruby/environment.cc27
1 files changed, 17 insertions, 10 deletions
diff --git a/ruby/environment.cc b/ruby/environment.cc
index baf836d..822b3de 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -137,21 +137,28 @@ namespace
VALUE
environment_accept_keywords(VALUE self, VALUE keywords, VALUE p)
{
- try
+ if (rb_obj_is_kind_of(keywords, rb_cArray))
{
- std::tr1::shared_ptr<KeywordNameSet> knc (new KeywordNameSet);
- long len = NUM2LONG(rb_funcall(keywords,rb_intern("length"),0));
- for (long i = 0; i < len; i++)
+ try
+ {
+ std::tr1::shared_ptr<KeywordNameSet> knc (new KeywordNameSet);
+ long len = NUM2LONG(rb_funcall(keywords,rb_intern("length"),0));
+ for (long i = 0; i < len; i++)
+ {
+ // Stupid macros won't let me do it on one line.
+ VALUE kw = rb_ary_entry(keywords, i);
+ knc->insert(KeywordName(StringValuePtr(kw)));
+ }
+ return value_to_environment(self)->accept_keywords(knc, *value_to_package_id(p)) ? Qtrue : Qfalse;
+ }
+ catch (const std::exception & e)
{
- // Stupid macros won't let me do it on one line.
- VALUE kw = rb_ary_entry(keywords, i);
- knc->insert(KeywordName(StringValuePtr(kw)));
+ exception_to_ruby_exception(e);
}
- return value_to_environment(self)->accept_keywords(knc, *value_to_package_id(p)) ? Qtrue : Qfalse;
}
- catch (const std::exception & e)
+ else
{
- exception_to_ruby_exception(e);
+ rb_raise(rb_eTypeError, "Can't convert %s into Array", rb_obj_classname(keywords));
}
}