diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-12-27 13:04:30 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-12-27 13:04:30 +0000 |
commit | 2f6d8bdc94926a625f769f72b890ed78553c928f (patch) | |
tree | 1fa4e037a9a8ed2601142ef2150e5c613ada59ca /ext/-test- | |
parent | 7f649d10ed8055214e0062800b2d117453b2304f (diff) |
* st.c (st_update): new function to lookup the given key and
update the value. [ruby-dev:44998]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-')
-rw-r--r-- | ext/-test-/st/update/extconf.rb | 1 | ||||
-rw-r--r-- | ext/-test-/st/update/update.c | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/ext/-test-/st/update/extconf.rb b/ext/-test-/st/update/extconf.rb new file mode 100644 index 0000000000..96dbae43ab --- /dev/null +++ b/ext/-test-/st/update/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/st/update") diff --git a/ext/-test-/st/update/update.c b/ext/-test-/st/update/update.c new file mode 100644 index 0000000000..33db04270c --- /dev/null +++ b/ext/-test-/st/update/update.c @@ -0,0 +1,34 @@ +#include <ruby.h> +#include <ruby/st.h> + +static int +update_func(st_data_t key, st_data_t *value, st_data_t arg) +{ + VALUE ret = rb_yield_values(2, (VALUE)key, (VALUE)*value); + switch (ret) { + case Qfalse: + return ST_STOP; + case Qnil: + return ST_DELETE; + default: + *value = ret; + return ST_CONTINUE; + } +} + +static VALUE +test_st_update(VALUE self, VALUE key) +{ + if (st_update(RHASH_TBL(self), (st_data_t)key, update_func, 0)) + return Qtrue; + else + return Qfalse; +} + +void +Init_update(void) +{ + VALUE st = rb_define_class_under(rb_define_module("Bug"), "StTable", rb_cHash); + rb_define_method(st, "st_update", test_st_update, 1); +} + |