* file.c (test_identical, rb_file_s_truncate): use RSTRING_PTR and

RSTRING_STR.

* io.c (pipe_open, rb_io_reopen): ditto.

* process.c (proc_spawn_n, rb_spawn): ditto.

* util.c (ruby_add_suffix): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2006-08-31 11:24:44 +00:00
Родитель 54af80844f
Коммит 5b5e4a6fc1
5 изменённых файлов: 33 добавлений и 22 удалений

Просмотреть файл

@ -1,3 +1,14 @@
Thu Aug 31 20:21:47 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* file.c (test_identical, rb_file_s_truncate): use RSTRING_PTR and
RSTRING_STR.
* io.c (pipe_open, rb_io_reopen): ditto.
* process.c (proc_spawn_n, rb_spawn): ditto.
* util.c (ruby_add_suffix): ditto.
Thu Aug 31 18:23:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ruby.h (struct RString): embed small strings.

14
file.c
Просмотреть файл

@ -1452,13 +1452,13 @@ test_identical(VALUE obj, VALUE fname1, VALUE fname2)
FilePathValue(fname1);
fname1 = rb_str_new4(fname1);
FilePathValue(fname2);
if (access(RSTRING(fname1)->ptr, 0)) return Qfalse;
if (access(RSTRING(fname2)->ptr, 0)) return Qfalse;
if (access(RSTRING_PTR(fname1), 0)) return Qfalse;
if (access(RSTRING_PTR(fname2), 0)) return Qfalse;
#endif
fname1 = rb_file_expand_path(fname1, Qnil);
fname2 = rb_file_expand_path(fname2, Qnil);
if (RSTRING(fname1)->len != RSTRING(fname2)->len) return Qfalse;
if (rb_memcicmp(RSTRING(fname1)->ptr, RSTRING(fname2)->ptr, RSTRING(fname1)->len))
if (RSTRING_LEN(fname1) != RSTRING_LEN(fname2)) return Qfalse;
if (rb_memcicmp(RSTRING_PTR(fname1), RSTRING_PTR(fname2), RSTRING_LEN(fname1)))
return Qfalse;
#endif
return Qtrue;
@ -2975,16 +2975,16 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
# ifdef _WIN32
if ((tmpfd = open(StringValueCStr(path), O_RDWR)) < 0) {
rb_sys_fail(RSTRING(path)->ptr);
rb_sys_fail(RSTRING_PTR(path));
}
# else
if ((tmpfd = open(StringValueCStr(path), 0)) < 0) {
rb_sys_fail(RSTRING(path)->ptr);
rb_sys_fail(RSTRING_PTR(path));
}
# endif
if (chsize(tmpfd, pos) < 0) {
close(tmpfd);
rb_sys_fail(RSTRING(path)->ptr);
rb_sys_fail(RSTRING_PTR(path));
}
close(tmpfd);
}

10
io.c
Просмотреть файл

@ -3047,12 +3047,12 @@ pipe_open(int argc, VALUE *argv, const char *mode)
int i;
for (i = 0; i < argc; ++i) {
args[i] = RSTRING(argv[i])->ptr;
args[i] = RSTRING_PTR(argv[i]);
}
args[i] = NULL;
cmd = ALLOCA_N(char, rb_w32_argv_size(args));
rb_w32_join_argv(cmd, args);
exename = RSTRING(prog)->ptr;
exename = RSTRING_PTR(prog);
}
else {
cmd = StringValueCStr(prog);
@ -3067,7 +3067,7 @@ pipe_open(int argc, VALUE *argv, const char *mode)
rb_thread_sleep(1);
break;
default:
rb_sys_fail(RSTRING(prog)->ptr);
rb_sys_fail(RSTRING_PTR(prog));
break;
}
}
@ -3075,7 +3075,7 @@ pipe_open(int argc, VALUE *argv, const char *mode)
if (argc)
prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
fp = popen(StringValueCStr(prog), mode);
if (!fp) rb_sys_fail(RSTRING(prog)->ptr);
if (!fp) rb_sys_fail(RSTRING_PTR(prog));
fd = fileno(fp);
#endif
@ -3566,7 +3566,7 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file)
fptr->fd = fileno(fptr->stdio_file);
#ifdef USE_SETVBUF
if (setvbuf(fptr->stdio_file, NULL, _IOFBF, 0) != 0)
rb_warn("setvbuf() can't be honoured for %s", RSTRING(fname)->ptr);
rb_warn("setvbuf() can't be honoured for %s", RSTRING_PTR(fname));
#endif
}
else {

Просмотреть файл

@ -1113,11 +1113,11 @@ proc_spawn_n(int argc, VALUE *argv, VALUE prog)
args = ALLOCA_N(char*, argc + 1);
for (i = 0; i < argc; i++) {
args[i] = RSTRING(argv[i])->ptr;
args[i] = RSTRING_PTR(argv[i]);
}
args[i] = (char*) 0;
if (args[0])
return proc_spawn_v(args, prog ? RSTRING(prog)->ptr : 0);
return proc_spawn_v(args, prog ? RSTRING_PTR(prog) : 0);
return -1;
}
@ -1538,7 +1538,7 @@ rb_spawn(int argc, VALUE *argv)
if (prog && argc) argv[0] = prog;
#elif defined HAVE_SPAWNV
if (!argc) {
status = proc_spawn(RSTRING(prog)->ptr);
status = proc_spawn(RSTRING_PTR(prog));
}
else {
status = proc_spawn_n(argc, argv, prog);

14
util.c
Просмотреть файл

@ -156,26 +156,26 @@ ruby_add_suffix(VALUE str, const char *suffix)
long slen;
char buf[1024];
if (RSTRING(str)->len > 1000)
if (RSTRING_LEN(str) > 1000)
rb_fatal("Cannot do inplace edit on long filename (%ld characters)",
RSTRING(str)->len);
RSTRING_LEN(str));
#if defined(DJGPP) || defined(__CYGWIN32__) || defined(_WIN32)
/* Style 0 */
slen = RSTRING(str)->len;
slen = RSTRING_LEN(str);
rb_str_cat(str, suffix, extlen);
#if defined(DJGPP)
if (_USE_LFN) return;
#else
if (valid_filename(RSTRING(str)->ptr)) return;
if (valid_filename(RSTRING_PTR(str))) return;
#endif
/* Fooey, style 0 failed. Fix str before continuing. */
RSTRING(str)->ptr[RSTRING(str)->len = slen] = '\0';
rb_str_resize(str, slen);
#endif
slen = extlen;
t = buf; baselen = 0; s = RSTRING(str)->ptr;
t = buf; baselen = 0; s = RSTRING_PTR(str);
while ((*t = *s) && *s != '.') {
baselen++;
if (*s == '\\' || *s == '/') baselen = 0;
@ -213,7 +213,7 @@ fallback:
(void)memcpy(p, strEQ(ext, suffix1) ? suffix2 : suffix1, 5);
}
rb_str_resize(str, strlen(buf));
memcpy(RSTRING(str)->ptr, buf, RSTRING(str)->len);
memcpy(RSTRING_PTR(str), buf, RSTRING_LEN(str));
}
#if defined(__CYGWIN32__) || defined(_WIN32)