summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-23 08:41:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-23 08:41:07 +0000
commit69459d98ef81c26291d8504dbcd904eda71e7e31 (patch)
tree25516e057647a261ce2521cbafd60ec582892eb3
parent2aba26fa521e1a4405546b50c08de0d90b5bfd44 (diff)
* 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
-rw-r--r--ChangeLog18
-rw-r--r--dir.c6
-rw-r--r--eval.c4
-rw-r--r--hash.c8
-rw-r--r--io.c45
-rw-r--r--string.c24
6 files changed, 75 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index 514cc6f4cc..d380580b93 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* io.c (rb_open_file): initialize flags.
diff --git a/dir.c b/dir.c
index 156c1d59dd..7a188cacbb 100644
--- a/dir.c
+++ b/dir.c
@@ -82,9 +82,9 @@ char *strchr _((char*,char));
#if defined DOSISH
#define isdirsep(c) ((c) == '/' || (c) == '\\')
-static char *
+static const char *
find_dirsep(s)
- char *s;
+ const char *s;
{
while (*s) {
if (isdirsep(*s))
@@ -767,7 +767,7 @@ glob_helper(path, sub, flags, func, arg)
free(magic);
break;
}
-
+
#if defined DOSISH_DRIVE_LETTER
#define BASE (*base && !((isdirsep(*base) && !base[1]) || (base[1] == ':' && isdirsep(base[2]) && !base[3])))
#else
diff --git a/eval.c b/eval.c
index 4186b2e9e3..4d19b89c34 100644
--- a/eval.c
+++ b/eval.c
@@ -1034,7 +1034,7 @@ static void
error_print()
{
VALUE errat = Qnil; /* OK */
- volatile VALUE eclass;
+ volatile VALUE eclass, e;
char *einfo;
long elen;
@@ -1069,7 +1069,7 @@ error_print()
eclass = CLASS_OF(ruby_errinfo);
if (EXEC_TAG() == 0) {
- VALUE e = rb_obj_as_string(ruby_errinfo);
+ e = rb_obj_as_string(ruby_errinfo);
einfo = RSTRING(e)->ptr;
elen = RSTRING(e)->len;
}
diff --git a/hash.c b/hash.c
index 8f636e1590..b87d9e268d 100644
--- a/hash.c
+++ b/hash.c
@@ -1583,8 +1583,8 @@ env_has_value(dmy, value)
if (TYPE(value) != T_STRING) return Qfalse;
env = GET_ENVIRON(environ);
while (*env) {
- char *s = strchr(*env, '=')+1;
- if (s) {
+ char *s = strchr(*env, '=');
+ if (s++) {
#ifdef ENV_IGNORECASE
if (strncasecmp(s, RSTRING(value)->ptr, strlen(s)) == 0) {
#else
@@ -1610,8 +1610,8 @@ env_index(dmy, value)
StringValue(value);
env = GET_ENVIRON(environ);
while (*env) {
- char *s = strchr(*env, '=')+1;
- if (s) {
+ char *s = strchr(*env, '=');
+ if (s++) {
#ifdef ENV_IGNORECASE
if (strncasecmp(s, RSTRING(value)->ptr, strlen(s)) == 0) {
#else
diff --git a/io.c b/io.c
index 815d0dc8d4..1377df4b51 100644
--- a/io.c
+++ b/io.c
@@ -823,13 +823,13 @@ io_read(argc, argv, io)
if (feof(fptr->f)) return Qnil;
if (NIL_P(str)) {
str = rb_str_new(0, len);
- if (len == 0) return str;
}
else {
StringValue(str);
rb_str_modify(str);
rb_str_resize(str,len);
}
+ if (len == 0) return str;
READ_CHECK(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_resize(str, ilen);
}
+ if (ilen == 0) return str;
n = 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);
fptr = RFILE(file)->fptr;
+ if (!fptr) {
+ fptr = RFILE(file)->fptr = ALLOC(OpenFile);
+ }
if (!NIL_P(nmode)) {
mode = StringValuePtr(nmode);
@@ -2497,10 +2501,14 @@ rb_io_init_copy(dest, io)
if (orig->f2) {
io_fflush(orig->f2, orig);
+ fseeko(orig->f, 0L, SEEK_CUR);
}
else if (orig->mode & FMODE_WRITABLE) {
io_fflush(orig->f, orig);
}
+ else {
+ fseeko(orig->f, 0L, SEEK_CUR);
+ }
/* copy OpenFile structure */
fptr->mode = orig->mode;
@@ -3528,12 +3536,21 @@ rb_f_syscall(argc, argv)
#endif
}
+static VALUE io_new_instance _((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__
- int pipes[2];
- VALUE r, w;
+ int pipes[2], state;
+ VALUE r, w, args[3];
#ifdef _WIN32
if (_pipe(pipes, 1024, O_BINARY) == -1)
@@ -3542,8 +3559,24 @@ rb_io_s_pipe()
#endif
rb_sys_fail(0);
- r = prep_stdio(rb_fdopen(pipes[0], "r"), FMODE_READABLE, rb_cIO);
- w = prep_stdio(rb_fdopen(pipes[1], "w"), FMODE_WRITABLE|FMODE_SYNC, rb_cIO);
+ args[0] = klass;
+ 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);
#else
diff --git a/string.c b/string.c
index eed7a0e887..15b68374f8 100644
--- a/string.c
+++ b/string.c
@@ -451,18 +451,6 @@ VALUE
rb_string_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;
if (TYPE(s) != T_STRING) {
s = rb_str_to_str(s);
@@ -472,7 +460,14 @@ rb_string_value_ptr(ptr)
FL_SET(s, ELTS_SHARED);
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
@@ -1015,9 +1010,8 @@ rb_str_rindex_m(argc, argv, str)
char *p = RSTRING(str)->ptr + pos;
char *pbeg = RSTRING(str)->ptr;
- while (pbeg <= p) {
+ while (pbeg <= --p) {
if (*p == c) return LONG2NUM(p - RSTRING(str)->ptr);
- p--;
}
return Qnil;
}