Skip to content

Commit

Permalink
991207
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Dec 7, 1999
1 parent bd5567f commit 1462975
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 128 deletions.
15 changes: 12 additions & 3 deletions ChangeLog
@@ -1,13 +1,22 @@
Tue Dec 7 11:16:30 1999 Yukihiro Matsumoto <matz@netlab.co.jp>

* eval.c (Init_eval): calculate stack limit from rlimit where
getrlimit(2) is available.

Tue Dec 7 09:57:33 1999 Katsuyuki Komatsu <komatsu@sarion.co.jp>

* file.c (rb_file_ftype): should have removed mode_t.

Mon Dec 6 15:55:30 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>

* numeric.c (fix_rshift): Fix -1 >> 32 returned 0. (-1 is true)
* numeric.c (fix_rshift): Fix -1 >> 32 returned 0 (should be -1).

* numeric.c (fix_rshift): Fix 1 >> -1 returned 0. (2 is true)
* numeric.c (fix_rshift): Fix 1 >> -1 returned 0 (should be 2).

Mon Dec 6 11:47:23 1999 Yukihiro Matsumoto <matz@netlab.co.jp>

* sprintf.c (rb_f_sprintf): formatted string must be tainted if
any of parameters is tainted.
any of parameters is a tainted string.

* file.c (rb_file_s_expand_path): expanded file path need not to
be tainted always.
Expand Down
2 changes: 2 additions & 0 deletions ToDo
Expand Up @@ -25,6 +25,7 @@ Hacking Interpreter
- use eban's fnmatch
- RUBYOPT environment variable
- alias $defout $>
* retrieve STACK_LEVEL_MAX from users' limit.
* remove end_proc registered out of require only
* non-blocking open (e.g. for named pipe) for thread
* avoid blocking with gethostbyname/gethostbyaddr
Expand All @@ -42,6 +43,7 @@ Standard Libraries
- Dir.glob(pat){|f|...}
- sprintf/printf's $ to specify argument order
- Dir.glob("**/*.c") ala zsh
- Remove Enumerable#{size,length}
* SyntaxError and NameError should not be subclasses of StandardError, maybe.
* debugger for thread programming
* Struct::new([name,]member,...) ??
Expand Down
4 changes: 2 additions & 2 deletions configure
Expand Up @@ -2199,7 +2199,7 @@ fi

for ac_hdr in stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\
fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\
syscall.h pwd.h a.out.h utime.h memory.h direct.h
syscall.h pwd.h a.out.h utime.h memory.h direct.h sys/resource.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
Expand Down Expand Up @@ -3102,7 +3102,7 @@ for ac_func in fmod killpg drand48 random wait4 waitpid syscall getcwd\
truncate chsize times utimes fcntl lockf setitimer\
setruid seteuid setreuid setrgid setegid setregid\
getpgrp setpgrp getpgid setpgid getgroups getpriority\
dlopen sigprocmask sigaction _setjmp setsid
dlopen sigprocmask sigaction _setjmp setsid getrlimit
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:3109: checking for $ac_func" >&5
Expand Down
4 changes: 2 additions & 2 deletions configure.in
Expand Up @@ -156,7 +156,7 @@ AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\
fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\
syscall.h pwd.h a.out.h utime.h memory.h direct.h)
syscall.h pwd.h a.out.h utime.h memory.h direct.h sys/resource.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UID_T
Expand All @@ -180,7 +180,7 @@ AC_CHECK_FUNCS(fmod killpg drand48 random wait4 waitpid syscall getcwd\
truncate chsize times utimes fcntl lockf setitimer\
setruid seteuid setreuid setrgid setegid setregid\
getpgrp setpgrp getpgid setpgid getgroups getpriority\
dlopen sigprocmask sigaction _setjmp setsid)
dlopen sigprocmask sigaction _setjmp setsid getrlimit)
AC_STRUCT_TIMEZONE
if test "$ac_cv_func_strftime" = no; then
AC_TRY_LINK([],
Expand Down
36 changes: 4 additions & 32 deletions enum.c
Expand Up @@ -198,7 +198,7 @@ min_i(i, min)
*min = i;
else {
cmp = rb_funcall(i, id_cmp, 1, *min);
if (FIX2LONG(cmp) < 0)
if (NUM2LONG(cmp) < 0)
*min = i;
}
return Qnil;
Expand All @@ -214,7 +214,7 @@ min_ii(i, min)
*min = i;
else {
cmp = rb_yield(rb_assoc_new(i, *min));
if (FIX2LONG(cmp) < 0)
if (NUM2LONG(cmp) < 0)
*min = i;
}
return Qnil;
Expand All @@ -240,7 +240,7 @@ max_i(i, max)
*max = i;
else {
cmp = rb_funcall(i, id_cmp, 1, *max);
if (FIX2LONG(cmp) > 0)
if (NUM2LONG(cmp) > 0)
*max = i;
}
return Qnil;
Expand All @@ -256,7 +256,7 @@ max_ii(i, max)
*max = i;
else {
cmp = rb_yield(rb_assoc_new(i, *max));
if (FIX2LONG(cmp) > 0)
if (NUM2LONG(cmp) > 0)
*max = i;
}
return Qnil;
Expand Down Expand Up @@ -332,32 +332,6 @@ enum_member(obj, val)
return Qfalse;
}

static VALUE
length_i(i, length)
VALUE i;
int *length;
{
(*length)++;
return Qnil;
}

static VALUE
enum_length(obj)
VALUE obj;
{
int length = 0;

rb_iterate(rb_each, obj, length_i, (VALUE)&length);
return INT2FIX(length);
}

VALUE
rb_enum_length(obj)
VALUE obj;
{
return enum_length(obj);
}

static VALUE
each_with_index_i(val, indexp)
VALUE val;
Expand Down Expand Up @@ -403,8 +377,6 @@ Init_Enumerable()
rb_define_method(rb_mEnumerable,"index", enum_index, 1);
rb_define_method(rb_mEnumerable,"member?", enum_member, 1);
rb_define_method(rb_mEnumerable,"include?", enum_member, 1);
rb_define_method(rb_mEnumerable,"length", enum_length, 0);
rb_define_method(rb_mEnumerable,"size", enum_length, 0);
rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, 0);

id_eqq = rb_intern("===");
Expand Down
60 changes: 41 additions & 19 deletions eval.c
Expand Up @@ -49,6 +49,28 @@ char *strrchr _((const char*,const char));
#endif
#endif

#include <sys/types.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#else
#ifndef NT
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
#endif /* NT */
#endif
#include <signal.h>
#include <errno.h>

#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif

#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif

VALUE rb_cProc;
static VALUE rb_cBinding;
static VALUE proc_call _((VALUE,VALUE));
Expand Down Expand Up @@ -3714,9 +3736,14 @@ rb_undefined(obj, id, argc, argv, call_status)
extern int _stacksize;
# define STACK_LEVEL_MAX (_stacksize - 4096)
#else
#ifdef HAVE_GETRLIMIT
static int STACK_LEVEL_MAX = 655300;
#else
# define STACK_LEVEL_MAX 655300
#endif
#endif
#endif

extern VALUE *rb_gc_stack_start;
static int
stack_length()
Expand Down Expand Up @@ -3844,7 +3871,7 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
break;
}

if ((++tick & 0x3ff) == 0) {
if ((++tick & 0xff) == 0) {
CHECK_INTS; /* better than nothing */
if (stack_length() > STACK_LEVEL_MAX) {
rb_raise(rb_eSysStackError, "stack level too deep");
Expand Down Expand Up @@ -5389,6 +5416,19 @@ Init_eval()
rb_global_variable(&trace_func);

rb_define_virtual_variable("$SAFE", safe_getter, safe_setter);

#ifdef HAVE_GETRLIMIT
{
struct rlimit rlim;

if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
double space = (double)rlim.rlim_cur*0.2;

if (space > 256*1024) space = 256*1024;
STACK_LEVEL_MAX = (rlim.rlim_cur - space) / 4;
}
}
#endif
}

VALUE rb_f_autoload();
Expand Down Expand Up @@ -6042,24 +6082,6 @@ int rb_thread_pending = 0;

VALUE rb_cThread;

#include <sys/types.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#else
#ifndef NT
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
#endif /* NT */
#endif
#include <signal.h>
#include <errno.h>

#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif

extern VALUE rb_last_status;

enum thread_status {
Expand Down
24 changes: 12 additions & 12 deletions file.c
Expand Up @@ -731,35 +731,35 @@ rb_file_s_size(obj, fname)
}

static VALUE
rb_file_ftype(mode)
mode_t mode;
rb_file_ftype(st)
struct stat *st;
{
char *t;

if (S_ISREG(mode)) {
if (S_ISREG(st->st_mode)) {
t = "file";
} else if (S_ISDIR(mode)) {
} else if (S_ISDIR(st->st_mode)) {
t = "directory";
} else if (S_ISCHR(mode)) {
} else if (S_ISCHR(st->st_mode)) {
t = "characterSpecial";
}
#ifdef S_ISBLK
else if (S_ISBLK(mode)) {
else if (S_ISBLK(st->st_mode)) {
t = "blockSpecial";
}
#endif
#ifdef S_ISFIFO
else if (S_ISFIFO(mode)) {
else if (S_ISFIFO(st->st_mode)) {
t = "fifo";
}
#endif
#ifdef S_ISLNK
else if (S_ISLNK(mode)) {
else if (S_ISLNK(st->st_mode)) {
t = "link";
}
#endif
#ifdef S_ISSOCK
else if (S_ISSOCK(mode)) {
else if (S_ISSOCK(st->st_mode)) {
t = "socket";
}
#endif
Expand All @@ -786,7 +786,7 @@ rb_file_s_ftype(obj, fname)
}
#endif

return rb_file_ftype(st.st_mode);
return rb_file_ftype(&st);
}

static VALUE
Expand Down Expand Up @@ -1183,7 +1183,6 @@ rb_file_s_expand_path(argc, argv)
s = STR2CSTR(fname);
p = buf;
if (s[0] == '~') {
tainted = 1;
if (isdirsep(s[1]) || s[1] == '\0') {
char *dir = getenv("HOME");

Expand All @@ -1193,6 +1192,7 @@ rb_file_s_expand_path(argc, argv)
strcpy(buf, dir);
p = &buf[strlen(buf)];
s++;
tainted = 1;
}
else {
#ifdef HAVE_PWD_H
Expand Down Expand Up @@ -1670,7 +1670,7 @@ static VALUE
rb_stat_ftype(obj)
VALUE obj;
{
return rb_file_ftype(get_stat(obj)->st_mode);
return rb_file_ftype(get_stat(obj));
}

static VALUE
Expand Down
7 changes: 4 additions & 3 deletions hash.c
Expand Up @@ -550,7 +550,7 @@ rb_hash_replace(hash, hash2)
}

static VALUE
rb_hash_length(hash)
rb_hash_size(hash)
VALUE hash;
{
return INT2FIX(RHASH(hash)->tbl->num_entries);
Expand Down Expand Up @@ -1454,8 +1454,8 @@ Init_Hash()
rb_define_method(rb_cHash,"index", rb_hash_index, 1);
rb_define_method(rb_cHash,"indexes", rb_hash_indexes, -1);
rb_define_method(rb_cHash,"indices", rb_hash_indexes, -1);
rb_define_method(rb_cHash,"length", rb_hash_length, 0);
rb_define_alias(rb_cHash, "size", "length");
rb_define_method(rb_cHash,"size", rb_hash_size, 0);
rb_define_method(rb_cHash,"length", rb_hash_size, 0);
rb_define_method(rb_cHash,"empty?", rb_hash_empty_p, 0);

rb_define_method(rb_cHash,"each", rb_hash_each_pair, 0);
Expand Down Expand Up @@ -1503,6 +1503,7 @@ Init_Hash()
rb_define_singleton_method(envtbl,"index", env_index, 1);
rb_define_singleton_method(envtbl,"indexes", env_indexes, -1);
rb_define_singleton_method(envtbl,"indices", env_indexes, -1);
rb_define_singleton_method(envtbl,"size", env_size, 0);
rb_define_singleton_method(envtbl,"length", env_size, 0);
rb_define_singleton_method(envtbl,"empty?", env_empty_p, 0);
rb_define_singleton_method(envtbl,"keys", env_keys, 0);
Expand Down
1 change: 1 addition & 0 deletions intern.h
Expand Up @@ -233,6 +233,7 @@ void rb_syswait _((int));
/* range.c */
VALUE rb_range_new _((VALUE, VALUE, int));
VALUE rb_range_beg_len _((VALUE, long*, long*, long, int));
VALUE rb_length_by_each _((VALUE));
/* re.c */
VALUE rb_reg_nth_defined _((int, VALUE));
VALUE rb_reg_nth_match _((int, VALUE));
Expand Down

0 comments on commit 1462975

Please sign in to comment.