about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-05-19 21:58:55 +0000
committerEric Wong <normalperson@yhbt.net>2011-05-19 22:08:59 +0000
commit6d61241b5ce1e3baefcbd3379241f55c2af8fa1b (patch)
tree66bdc2226807e6eb4549aa2f9945f848de8d3ad5
parent6fd281b29e0e4220719e736bff4ef6d5feb49056 (diff)
downloadsleepy_penguin-6d61241b5ce1e3baefcbd3379241f55c2af8fa1b.tar.gz
It's fewer lines of code and cleaner in cases where "new"
and "for_fd" are the same underlying method.
-rw-r--r--ext/sleepy_penguin/eventfd.c7
-rw-r--r--ext/sleepy_penguin/inotify.c10
-rw-r--r--ext/sleepy_penguin/signalfd.c9
-rw-r--r--ext/sleepy_penguin/timerfd.c7
-rw-r--r--test/test_inotify.rb2
5 files changed, 16 insertions, 19 deletions
diff --git a/ext/sleepy_penguin/eventfd.c b/ext/sleepy_penguin/eventfd.c
index d291bff..4da5e45 100644
--- a/ext/sleepy_penguin/eventfd.c
+++ b/ext/sleepy_penguin/eventfd.c
@@ -1,7 +1,6 @@
 #ifdef HAVE_SYS_EVENTFD_H
 #include "sleepy_penguin.h"
 #include <sys/eventfd.h>
-static ID id_for_fd;
 
 /*
  * call-seq:
@@ -21,7 +20,7 @@ static ID id_for_fd;
  */
 static VALUE s_new(int argc, VALUE *argv, VALUE klass)
 {
-        VALUE _initval, _flags;
+        VALUE _initval, _flags, rv;
         unsigned initval;
         int flags;
         int fd;
@@ -40,7 +39,8 @@ static VALUE s_new(int argc, VALUE *argv, VALUE klass)
                         rb_sys_fail("eventfd");
         }
 
-        return rb_funcall(klass, id_for_fd, 1, INT2NUM(fd));
+        rv = INT2FIX(fd);
+        return rb_call_super(1, &rv);
 }
 
 struct efd_args {
@@ -170,6 +170,5 @@ void sleepy_penguin_init_eventfd(void)
 #endif
         rb_define_method(cEventFD, "value", getvalue, -1);
         rb_define_method(cEventFD, "incr", incr, -1);
-        id_for_fd = rb_intern("for_fd");
 }
 #endif /* HAVE_SYS_EVENTFD_H */
diff --git a/ext/sleepy_penguin/inotify.c b/ext/sleepy_penguin/inotify.c
index b3cad7d..406d6a3 100644
--- a/ext/sleepy_penguin/inotify.c
+++ b/ext/sleepy_penguin/inotify.c
@@ -4,7 +4,7 @@
 #include <sys/ioctl.h>
 #include "missing_inotify.h"
 
-static ID id_for_fd, id_inotify_buf, id_inotify_tmp, id_mask;
+static ID id_inotify_buf, id_inotify_tmp, id_mask;
 static VALUE cEvent, checks;
 
 /*
@@ -34,7 +34,8 @@ static VALUE s_new(int argc, VALUE *argv, VALUE klass)
                         rb_sys_fail("inotify_init1");
         }
 
-        rv = rb_funcall(klass, id_for_fd, 1, INT2NUM(fd));
+        rv = INT2FIX(fd);
+        rv = rb_call_super(1, &rv);
         rb_ivar_set(rv, id_inotify_buf, rb_str_new(0, 128));
         rb_ivar_set(rv, id_inotify_tmp, rb_ary_new());
 
@@ -256,9 +257,7 @@ static VALUE events(VALUE self)
  */
 static VALUE init_copy(VALUE dest, VALUE orig)
 {
-        VALUE tmp;
-
-        dest = rb_call_super(1, &orig); /* copy all other ivars as-is */
+        rb_call_super(1, &orig); /* copy all other ivars as-is */
         rb_ivar_set(dest, id_inotify_buf, rb_str_new(0, 128));
 
         return dest;
@@ -339,7 +338,6 @@ void sleepy_penguin_init_inotify(void)
         cEvent = rb_define_class_under(cInotify, "Event", cEvent);
         rb_define_method(cEvent, "events", events, 0);
         rb_define_singleton_method(cInotify, "new", s_new, -1);
-        id_for_fd = rb_intern("for_fd");
         id_inotify_buf = rb_intern("@inotify_buf");
         id_inotify_tmp = rb_intern("@inotify_tmp");
         id_mask = rb_intern("mask");
diff --git a/ext/sleepy_penguin/signalfd.c b/ext/sleepy_penguin/signalfd.c
index 2f8cd45..f9e5030 100644
--- a/ext/sleepy_penguin/signalfd.c
+++ b/ext/sleepy_penguin/signalfd.c
@@ -2,7 +2,7 @@
 #include "sleepy_penguin.h"
 #include <signal.h>
 #include <sys/signalfd.h>
-static ID id_for_fd, id_list;
+static ID id_list;
 static VALUE ssi_members;
 static VALUE cSigInfo;
 
@@ -123,7 +123,7 @@ static VALUE update_bang(int argc, VALUE *argv, VALUE self)
  */
 static VALUE s_new(int argc, VALUE *argv, VALUE klass)
 {
-        VALUE vmask, vflags;
+        VALUE vmask, vflags, rv;
         sigset_t mask;
         int flags;
         int fd;
@@ -142,7 +142,9 @@ static VALUE s_new(int argc, VALUE *argv, VALUE klass)
                         rb_sys_fail("signalfd");
         }
 
-        return rb_funcall(klass, id_for_fd, 1, INT2NUM(fd));
+
+        rv = INT2FIX(fd);
+        return rb_call_super(1, &rv);
 }
 
 static VALUE ssi_alloc(VALUE klass)
@@ -290,7 +292,6 @@ void sleepy_penguin_init_signalfd(void)
 
         rb_define_method(cSignalFD, "take", sfd_take, -1);
         rb_define_method(cSignalFD, "update!", update_bang, -1);
-        id_for_fd = rb_intern("for_fd");
         ssi_members = rb_ary_new();
 
         NODOC_CONST(cSigInfo, "MEMBERS", ssi_members);
diff --git a/ext/sleepy_penguin/timerfd.c b/ext/sleepy_penguin/timerfd.c
index b8d1c2a..c7378c3 100644
--- a/ext/sleepy_penguin/timerfd.c
+++ b/ext/sleepy_penguin/timerfd.c
@@ -2,7 +2,6 @@
 #include "sleepy_penguin.h"
 #include <sys/timerfd.h>
 #include "value2timespec.h"
-static ID id_for_fd;
 
 /*
  * call-seq:
@@ -22,7 +21,7 @@ static ID id_for_fd;
  */
 static VALUE s_new(int argc, VALUE *argv, VALUE klass)
 {
-        VALUE cid, fl;
+        VALUE cid, fl, rv;
         int clockid, flags;
         int fd;
 
@@ -40,7 +39,8 @@ static VALUE s_new(int argc, VALUE *argv, VALUE klass)
                         rb_sys_fail("timerfd_create");
         }
 
-        return rb_funcall(klass, id_for_fd, 1, INT2NUM(fd));
+        rv = INT2FIX(fd);
+        return rb_call_super(1, &rv);
 }
 
 static VALUE itimerspec2ary(struct itimerspec *its)
@@ -165,6 +165,5 @@ void sleepy_penguin_init_timerfd(void)
         rb_define_method(cTimerFD, "settime", settime, 3);
         rb_define_method(cTimerFD, "gettime", gettime, 0);
         rb_define_method(cTimerFD, "expirations", expirations, -1);
-        id_for_fd = rb_intern("for_fd");
 }
 #endif /* HAVE_SYS_TIMERFD_H */
diff --git a/test/test_inotify.rb b/test/test_inotify.rb
index a003baf..dd2c7ad 100644
--- a/test/test_inotify.rb
+++ b/test/test_inotify.rb
@@ -36,7 +36,7 @@ class TestInotify < Test::Unit::TestCase
     assert a.fileno != b.fileno
     abuf = a.instance_variable_get(:@inotify_buf)
     bbuf = b.instance_variable_get(:@inotify_buf)
-    assert abuf.object_id != bbuf.object_id
+    assert abuf.object_id != bbuf.object_id, "#{a.inspect} #{b.inspect}"
 
     atmp = a.instance_variable_get(:@inotify_tmp)
     btmp = b.instance_variable_get(:@inotify_tmp)