summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-10 14:52:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-10 14:52:06 +0000
commitefae6194582001cb12108bc101d22dc1ed9a660c (patch)
treeffc8141e760ab852a85ccd7592efd60be2d542dd /ext
parent0934e6c014fdbf178b1dd0d4f27c3e857491d641 (diff)
* st.c: fix packed num_entries on delete_safe. patched by Sokolov
Yura at https://github.com/ruby/ruby/pull/84 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/-test-/st/numhash/numhash.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/-test-/st/numhash/numhash.c b/ext/-test-/st/numhash/numhash.c
index adf3d258b9..9b7df3844e 100644
--- a/ext/-test-/st/numhash/numhash.c
+++ b/ext/-test-/st/numhash/numhash.c
@@ -81,6 +81,28 @@ numhash_update(VALUE self, VALUE key)
return Qfalse;
}
+#if SIZEOF_LONG == SIZEOF_VOIDP
+# define ST2NUM(x) ULONG2NUM(x)
+#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
+# define ST2NUM(x) ULL2NUM(x)
+#endif
+
+static VALUE
+numhash_size(VALUE self)
+{
+ return ST2NUM(((st_table *)DATA_PTR(self))->num_entries);
+}
+
+static VALUE
+numhash_delete_safe(VALUE self, VALUE key)
+{
+ st_data_t val, k = (st_data_t)key;
+ if (st_delete_safe((st_table *)DATA_PTR(self), &k, &val, (st_data_t)self)) {
+ return val;
+ }
+ return Qnil;
+}
+
void
Init_numhash(void)
{
@@ -91,5 +113,7 @@ Init_numhash(void)
rb_define_method(st, "[]=", numhash_aset, 2);
rb_define_method(st, "each", numhash_each, 0);
rb_define_method(st, "update", numhash_update, 1);
+ rb_define_method(st, "size", numhash_size, 0);
+ rb_define_method(st, "delete_safe", numhash_delete_safe, 1);
}