[macruby-changes] [2702] MacRuby/trunk/io.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Oct 1 17:25:50 PDT 2009


Revision: 2702
          http://trac.macosforge.org/projects/ruby/changeset/2702
Author:   lsansonetti at apple.com
Date:     2009-10-01 17:25:49 -0700 (Thu, 01 Oct 2009)
Log Message:
-----------
fixed a few crashers in IO#ioctl and IO#fcntl

Modified Paths:
--------------
    MacRuby/trunk/io.c

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2009-10-01 21:14:49 UTC (rev 2701)
+++ MacRuby/trunk/io.c	2009-10-02 00:25:49 UTC (rev 2702)
@@ -3430,8 +3430,22 @@
 {
     rb_secure(2);
 	
+    unsigned long cmd;
+    if (arg == Qnil || arg == Qfalse) {
+	cmd = 0;
+    }
+    else if (FIXNUM_P(arg)) {
+	cmd = FIX2LONG(arg);
+    }
+    else if (arg == Qtrue) {
+	cmd = 1;
+    }
+    else {
+	// TODO arg may be a string
+	cmd = NUM2LONG(arg);
+    }
+
     unsigned long request;
-    unsigned long cmd = NUM2ULONG(arg);
     rb_io_t *io_s = ExtractIOStruct(io);
     if (TYPE(req) == T_STRING) {
 	request = (unsigned long)(intptr_t)RSTRING_PTR(req);
@@ -3457,8 +3471,11 @@
  */
 
 static VALUE
-rb_io_ioctl(VALUE recv, SEL sel, VALUE integer_cmd, VALUE arg)
+rb_io_ioctl(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
+    VALUE integer_cmd, arg;
+    rb_scan_args(argc, argv, "11", &integer_cmd, &arg);
+
     rb_io_assert_open(ExtractIOStruct(recv));
     return rb_io_ctl(recv, integer_cmd, arg, 1);
 }
@@ -3477,8 +3494,11 @@
  */
 
 static VALUE
-rb_io_fcntl(VALUE recv, SEL sel, VALUE integer_cmd, VALUE arg)
+rb_io_fcntl(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
+    VALUE integer_cmd, arg;
+    rb_scan_args(argc, argv, "11", &integer_cmd, &arg);
+
     rb_io_assert_open(ExtractIOStruct(recv));
     return rb_io_ctl(recv, integer_cmd, arg, 0);
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091001/a1a50ede/attachment.html>


More information about the macruby-changes mailing list