ruby-changes:21664
From: kosaki <ko1@a...>
Date: Sat, 12 Nov 2011 11:10:10 +0900 (JST)
Subject: [ruby-changes:21664] kosaki:r33713 (trunk): * io.c (+setup_narg): factor out length calculation logic.
kosaki 2011-11-12 11:09:56 +0900 (Sat, 12 Nov 2011) New Revision: 33713 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33713 Log: * io.c (+setup_narg): factor out length calculation logic. * io.c (rb_io_ctl): ditto. Modified files: trunk/ChangeLog trunk/io.c Index: ChangeLog =================================================================== --- ChangeLog (revision 33712) +++ ChangeLog (revision 33713) @@ -1,3 +1,8 @@ +Sat Nov 12 10:56:43 2011 KOSAKI Motohiro <kosaki.motohiro@g...> + + * io.c (+setup_narg): factor out length calculation logic. + * io.c (rb_io_ctl): ditto. + Sat Nov 12 10:52:17 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * io.c (+ioctl_narg_len) new helper function. Index: io.c =================================================================== --- io.c (revision 33712) +++ io.c (revision 33713) @@ -7928,17 +7928,12 @@ return len; } -static VALUE -rb_io_ctl(VALUE io, VALUE req, VALUE arg, int io_p) +static long +setup_narg(int cmd, VALUE *argp, int io_p) { - int cmd = NUM2INT(req); - rb_io_t *fptr; - long len = 0; long narg = 0; - int retval; + VALUE arg = *argp; - rb_secure(2); - if (NIL_P(arg) || arg == Qfalse) { narg = 0; } @@ -7955,10 +7950,11 @@ narg = NUM2LONG(arg); } else { - arg = tmp; + long len; + *argp = arg = tmp; if (io_p) - ioctl_narg_len(cmd); + len = ioctl_narg_len(cmd); else len = 256; rb_str_modify(arg); @@ -7973,10 +7969,25 @@ narg = (long)(SIGNED_VALUE)RSTRING_PTR(arg); } } + + return narg; +} + +static VALUE +rb_io_ctl(VALUE io, VALUE req, VALUE arg, int io_p) +{ + int cmd = NUM2INT(req); + rb_io_t *fptr; + long narg; + int retval; + + rb_secure(2); + + narg = setup_narg(cmd, &arg, io_p); GetOpenFile(io, fptr); retval = io_cntl(fptr->fd, cmd, narg, io_p); if (retval < 0) rb_sys_fail_path(fptr->pathv); - if (RB_TYPE_P(arg, T_STRING) && RSTRING_PTR(arg)[len] != 17) { + if (RB_TYPE_P(arg, T_STRING) && RSTRING_PTR(arg)[RSTRING_LEN(arg)-1] != 17) { rb_raise(rb_eArgError, "return value overflowed string"); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/