aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-26 14:42:26 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-26 14:42:26 +0000
commit19711c780300a3cb50a5ba269e4fc615362affcb (patch)
tree93a44d3d903fc0a1abb63d862067cb52d98bfbde /io.c
parente1aba5bb2f60753a382065d3e6844fb5e16a721f (diff)
downloadruby-19711c780300a3cb50a5ba269e4fc615362affcb.tar.gz
io.c: redulce RSTRING_PTR and RSTRING_LEN
* io.c: replace repeating RSTRING_PTR and RSTRING_LEN with local variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/io.c b/io.c
index c99f0c2a7e..4610e8514a 100644
--- a/io.c
+++ b/io.c
@@ -9089,7 +9089,8 @@ setup_narg(ioctl_req_t cmd, VALUE *argp, int io_p)
narg = NUM2LONG(arg);
}
else {
- long len;
+ char *ptr;
+ long len, slen;
*argp = arg = tmp;
if (io_p)
@@ -9098,13 +9099,16 @@ setup_narg(ioctl_req_t cmd, VALUE *argp, int io_p)
len = fcntl_narg_len((int)cmd);
rb_str_modify(arg);
+ slen = RSTRING_LEN(arg);
/* expand for data + sentinel. */
- if (RSTRING_LEN(arg) < len+1) {
+ if (slen < len+1) {
rb_str_resize(arg, len+1);
+ slen = len+1;
}
/* a little sanity check here */
- RSTRING_PTR(arg)[RSTRING_LEN(arg) - 1] = 17;
- narg = (long)(SIGNED_VALUE)RSTRING_PTR(arg);
+ ptr = RSTRING_PTR(arg);
+ ptr[slen - 1] = 17;
+ narg = (long)(SIGNED_VALUE)ptr;
}
}
@@ -9127,9 +9131,12 @@ rb_ioctl(VALUE io, VALUE req, VALUE arg)
retval = do_ioctl(fptr->fd, cmd, narg);
if (retval < 0) rb_sys_fail_path(fptr->pathv);
if (RB_TYPE_P(arg, T_STRING)) {
- if (RSTRING_PTR(arg)[RSTRING_LEN(arg)-1] != 17)
+ char *ptr;
+ long slen;
+ RSTRING_GETMEM(arg, ptr, slen);
+ if (ptr[slen-1] != 17)
rb_raise(rb_eArgError, "return value overflowed string");
- RSTRING_PTR(arg)[RSTRING_LEN(arg)-1] = '\0';
+ ptr[slen-1] = '\0';
}
return INT2NUM(retval);
@@ -9213,9 +9220,12 @@ rb_fcntl(VALUE io, VALUE req, VALUE arg)
retval = do_fcntl(fptr->fd, cmd, narg);
if (retval < 0) rb_sys_fail_path(fptr->pathv);
if (RB_TYPE_P(arg, T_STRING)) {
- if (RSTRING_PTR(arg)[RSTRING_LEN(arg)-1] != 17)
+ char *ptr;
+ long slen;
+ RSTRING_GETMEM(arg, ptr, slen);
+ if (ptr[slen-1] != 17)
rb_raise(rb_eArgError, "return value overflowed string");
- RSTRING_PTR(arg)[RSTRING_LEN(arg)-1] = '\0';
+ ptr[slen-1] = '\0';
}
return INT2NUM(retval);
@@ -11084,8 +11094,9 @@ argf_read(int argc, VALUE *argv, VALUE argf)
}
}
else if (argc >= 1) {
- if (RSTRING_LEN(str) < len) {
- len -= RSTRING_LEN(str);
+ long slen = RSTRING_LEN(str);
+ if (slen < len) {
+ len -= slen;
argv[0] = INT2NUM(len);
goto retry;
}