1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
parent 54af80844f
commit 5b5e4a6fc1
5 changed files with 33 additions and 22 deletions

View file

@ -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> Thu Aug 31 18:23:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ruby.h (struct RString): embed small strings. * ruby.h (struct RString): embed small strings.

14
file.c
View file

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

10
io.c
View file

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

View file

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

14
util.c
View file

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