Skip to content

Commit

Permalink
* dir.c (find_dirsep): get rid of warnings.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Jun 23, 2003
1 parent 2aba26f commit 69459d9
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 30 deletions.
18 changes: 18 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Mon Jun 23 17:40:58 2003 Nobuyoshi Nakada <[email protected]>

* 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 <[email protected]>

* io.c (rb_open_file): initialize flags.
Expand Down
6 changes: 3 additions & 3 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ static void
error_print()
{
VALUE errat = Qnil; /* OK */
volatile VALUE eclass;
volatile VALUE eclass, e;
char *einfo;
long elen;

Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
45 changes: 39 additions & 6 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
24 changes: 9 additions & 15 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,18 +450,6 @@ static char *null_str = "";
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) {
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 69459d9

Please sign in to comment.