* dir.c (find_dirsep): get rid of warnings.

* eval.c (error_print): temporary value might be disposed by GC.

* hash.c (env_has_value, env_index): should not increment NULL.

* io.c (io_read, rb_io_sysread): not read when length is 0.

* io.c (rb_io_reopen): ensure initialized IO.

* io.c (rb_io_init_copy): sychronize file pointer.

* io.c (rb_io_s_pipe): make exception proof.

* string.c (rb_str_rindex_m): Fixnum 0 matched end of string.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-06-23 08:41:07 +00:00
parent 2aba26fa52
commit 69459d98ef
6 changed files with 75 additions and 30 deletions

View File

@ -1,3 +1,21 @@
Mon Jun 23 17:40:58 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* dir.c (find_dirsep): get rid of warnings.
* eval.c (error_print): temporary value might be disposed by GC.
* hash.c (env_has_value, env_index): should not increment NULL.
* io.c (io_read, rb_io_sysread): not read when length is 0.
* io.c (rb_io_reopen): ensure initialized IO.
* io.c (rb_io_init_copy): sychronize file pointer.
* io.c (rb_io_s_pipe): make exception proof.
* string.c (rb_str_rindex_m): Fixnum 0 matched end of string.
Mon Jun 23 16:18:12 2003 Tanaka Akira <akr@m17n.org> Mon Jun 23 16:18:12 2003 Tanaka Akira <akr@m17n.org>
* io.c (rb_open_file): initialize flags. * io.c (rb_open_file): initialize flags.

6
dir.c
View File

@ -82,9 +82,9 @@ char *strchr _((char*,char));
#if defined DOSISH #if defined DOSISH
#define isdirsep(c) ((c) == '/' || (c) == '\\') #define isdirsep(c) ((c) == '/' || (c) == '\\')
static char * static const char *
find_dirsep(s) find_dirsep(s)
char *s; const char *s;
{ {
while (*s) { while (*s) {
if (isdirsep(*s)) if (isdirsep(*s))
@ -767,7 +767,7 @@ glob_helper(path, sub, flags, func, arg)
free(magic); free(magic);
break; break;
} }
#if defined DOSISH_DRIVE_LETTER #if defined DOSISH_DRIVE_LETTER
#define BASE (*base && !((isdirsep(*base) && !base[1]) || (base[1] == ':' && isdirsep(base[2]) && !base[3]))) #define BASE (*base && !((isdirsep(*base) && !base[1]) || (base[1] == ':' && isdirsep(base[2]) && !base[3])))
#else #else

4
eval.c
View File

@ -1034,7 +1034,7 @@ static void
error_print() error_print()
{ {
VALUE errat = Qnil; /* OK */ VALUE errat = Qnil; /* OK */
volatile VALUE eclass; volatile VALUE eclass, e;
char *einfo; char *einfo;
long elen; long elen;
@ -1069,7 +1069,7 @@ error_print()
eclass = CLASS_OF(ruby_errinfo); eclass = CLASS_OF(ruby_errinfo);
if (EXEC_TAG() == 0) { if (EXEC_TAG() == 0) {
VALUE e = rb_obj_as_string(ruby_errinfo); e = rb_obj_as_string(ruby_errinfo);
einfo = RSTRING(e)->ptr; einfo = RSTRING(e)->ptr;
elen = RSTRING(e)->len; elen = RSTRING(e)->len;
} }

8
hash.c
View File

@ -1583,8 +1583,8 @@ env_has_value(dmy, value)
if (TYPE(value) != T_STRING) return Qfalse; if (TYPE(value) != T_STRING) return Qfalse;
env = GET_ENVIRON(environ); env = GET_ENVIRON(environ);
while (*env) { while (*env) {
char *s = strchr(*env, '=')+1; char *s = strchr(*env, '=');
if (s) { if (s++) {
#ifdef ENV_IGNORECASE #ifdef ENV_IGNORECASE
if (strncasecmp(s, RSTRING(value)->ptr, strlen(s)) == 0) { if (strncasecmp(s, RSTRING(value)->ptr, strlen(s)) == 0) {
#else #else
@ -1610,8 +1610,8 @@ env_index(dmy, value)
StringValue(value); StringValue(value);
env = GET_ENVIRON(environ); env = GET_ENVIRON(environ);
while (*env) { while (*env) {
char *s = strchr(*env, '=')+1; char *s = strchr(*env, '=');
if (s) { if (s++) {
#ifdef ENV_IGNORECASE #ifdef ENV_IGNORECASE
if (strncasecmp(s, RSTRING(value)->ptr, strlen(s)) == 0) { if (strncasecmp(s, RSTRING(value)->ptr, strlen(s)) == 0) {
#else #else

45
io.c
View File

@ -823,13 +823,13 @@ io_read(argc, argv, io)
if (feof(fptr->f)) return Qnil; if (feof(fptr->f)) return Qnil;
if (NIL_P(str)) { if (NIL_P(str)) {
str = rb_str_new(0, len); str = rb_str_new(0, len);
if (len == 0) return str;
} }
else { else {
StringValue(str); StringValue(str);
rb_str_modify(str); rb_str_modify(str);
rb_str_resize(str,len); rb_str_resize(str,len);
} }
if (len == 0) return str;
READ_CHECK(fptr->f); READ_CHECK(fptr->f);
n = rb_io_fread(RSTRING(str)->ptr, len, fptr->f); n = rb_io_fread(RSTRING(str)->ptr, len, fptr->f);
@ -1573,6 +1573,7 @@ rb_io_sysread(argc, argv, io)
rb_str_modify(str); rb_str_modify(str);
rb_str_resize(str, ilen); rb_str_resize(str, ilen);
} }
if (ilen == 0) return str;
n = fileno(fptr->f); n = fileno(fptr->f);
rb_thread_wait_fd(fileno(fptr->f)); rb_thread_wait_fd(fileno(fptr->f));
@ -2439,6 +2440,9 @@ rb_io_reopen(argc, argv, file)
rb_io_taint_check(file); rb_io_taint_check(file);
fptr = RFILE(file)->fptr; fptr = RFILE(file)->fptr;
if (!fptr) {
fptr = RFILE(file)->fptr = ALLOC(OpenFile);
}
if (!NIL_P(nmode)) { if (!NIL_P(nmode)) {
mode = StringValuePtr(nmode); mode = StringValuePtr(nmode);
@ -2497,10 +2501,14 @@ rb_io_init_copy(dest, io)
if (orig->f2) { if (orig->f2) {
io_fflush(orig->f2, orig); io_fflush(orig->f2, orig);
fseeko(orig->f, 0L, SEEK_CUR);
} }
else if (orig->mode & FMODE_WRITABLE) { else if (orig->mode & FMODE_WRITABLE) {
io_fflush(orig->f, orig); io_fflush(orig->f, orig);
} }
else {
fseeko(orig->f, 0L, SEEK_CUR);
}
/* copy OpenFile structure */ /* copy OpenFile structure */
fptr->mode = orig->mode; fptr->mode = orig->mode;
@ -3528,12 +3536,21 @@ rb_f_syscall(argc, argv)
#endif #endif
} }
static VALUE io_new_instance _((VALUE));
static VALUE static VALUE
rb_io_s_pipe() io_new_instance(args)
VALUE args;
{
return rb_class_new_instance(2, (VALUE*)args+1, *(VALUE*)args);
}
static VALUE
rb_io_s_pipe(klass)
VALUE klass;
{ {
#ifndef __human68k__ #ifndef __human68k__
int pipes[2]; int pipes[2], state;
VALUE r, w; VALUE r, w, args[3];
#ifdef _WIN32 #ifdef _WIN32
if (_pipe(pipes, 1024, O_BINARY) == -1) if (_pipe(pipes, 1024, O_BINARY) == -1)
@ -3542,8 +3559,24 @@ rb_io_s_pipe()
#endif #endif
rb_sys_fail(0); rb_sys_fail(0);
r = prep_stdio(rb_fdopen(pipes[0], "r"), FMODE_READABLE, rb_cIO); args[0] = klass;
w = prep_stdio(rb_fdopen(pipes[1], "w"), FMODE_WRITABLE|FMODE_SYNC, rb_cIO); args[1] = INT2NUM(pipes[0]);
args[2] = INT2FIX(O_RDONLY);
r = rb_protect(io_new_instance, (VALUE)args, &state);
if (state) {
close(pipes[0]);
close(pipes[1]);
rb_jump_tag(state);
}
args[1] = INT2NUM(pipes[1]);
args[2] = INT2FIX(O_WRONLY);
w = rb_protect(io_new_instance, (VALUE)args, &state);
if (state) {
close(pipes[1]);
if (!NIL_P(r)) rb_io_close(r);
rb_jump_tag(state);
}
rb_io_synchronized(RFILE(w)->fptr);
return rb_assoc_new(r, w); return rb_assoc_new(r, w);
#else #else

View File

@ -450,18 +450,6 @@ static char *null_str = "";
VALUE VALUE
rb_string_value(ptr) rb_string_value(ptr)
volatile VALUE *ptr; volatile VALUE *ptr;
{
*ptr = rb_str_to_str(*ptr);
if (!RSTRING(*ptr)->ptr) {
FL_SET(*ptr, ELTS_SHARED);
RSTRING(*ptr)->ptr = null_str;
}
return *ptr;
}
char *
rb_string_value_ptr(ptr)
volatile VALUE *ptr;
{ {
VALUE s = *ptr; VALUE s = *ptr;
if (TYPE(s) != T_STRING) { if (TYPE(s) != T_STRING) {
@ -472,7 +460,14 @@ rb_string_value_ptr(ptr)
FL_SET(s, ELTS_SHARED); FL_SET(s, ELTS_SHARED);
RSTRING(s)->ptr = null_str; RSTRING(s)->ptr = null_str;
} }
return RSTRING(s)->ptr; return s;
}
char *
rb_string_value_ptr(ptr)
volatile VALUE *ptr;
{
return RSTRING(rb_string_value(s))->ptr;
} }
VALUE VALUE
@ -1015,9 +1010,8 @@ rb_str_rindex_m(argc, argv, str)
char *p = RSTRING(str)->ptr + pos; char *p = RSTRING(str)->ptr + pos;
char *pbeg = RSTRING(str)->ptr; char *pbeg = RSTRING(str)->ptr;
while (pbeg <= p) { while (pbeg <= --p) {
if (*p == c) return LONG2NUM(p - RSTRING(str)->ptr); if (*p == c) return LONG2NUM(p - RSTRING(str)->ptr);
p--;
} }
return Qnil; return Qnil;
} }