Debian Codegraph @

ext/-test-/st/update/update.c

raw
1 #include <ruby.h>
2 #include <ruby/st.h>
3
4 static int
5 update_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
6 {
7 VALUE ret = rb_yield_values(existing ? 2 : 1, (VALUE)*key, (VALUE)*value);
8 switch (ret) {
9 case Qfalse:
10 return ST_STOP;
11 case Qnil:
12 return ST_DELETE;
13 default:
14 *value = ret;
15 return ST_CONTINUE;
16 }
17 }
18
19 static VALUE
20 test_st_update(VALUE self, VALUE key)
21 {
22 if (st_update(RHASH_TBL(self), (st_data_t)key, update_func, 0))
23 return Qtrue;
24 else
25 return Qfalse;
26 }
27
28 void
29 Init_update(void)
30 {
31 VALUE st = rb_define_class_under(rb_define_module("Bug"), "StTable", rb_cHash);
32 rb_define_method(st, "st_update", test_st_update, 1);
33 }
34