From e1c29a3f13a8d5ca0f9a4e491a752c73aca1d721 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 16 Feb 2001 07:53:21 +0000 Subject: * io.c (set_outfile): f should be the FILE* from the assigning value. * ext/socket/socket.c (tcp_s_open): should not give default value to local_host. * time.c (time_s_times): move to Process::times. * file.c (rb_file_s_lchmod): new method File::lchmod. * file.c (rb_file_s_lchown): new method File::lchown. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 15 +++++++++- ToDo | 9 +++--- configure.in | 2 +- ext/socket/socket.c | 5 ---- file.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ intern.h | 1 + io.c | 2 -- process.c | 77 +++++++++++++++++++++++++++++++++++++++--------- time.c | 32 ++------------------ version.h | 4 +-- 10 files changed, 173 insertions(+), 59 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9982be237f..c23c43757d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Fri Feb 16 01:44:56 2001 Yukihiro Matsumoto + + * io.c (set_outfile): f should be the FILE* from the assigning value. + + * ext/socket/socket.c (tcp_s_open): should not give default value + to local_host. + + * time.c (time_s_times): move to Process::times. + + * file.c (rb_file_s_lchmod): new method File::lchmod. + + * file.c (rb_file_s_lchown): new method File::lchown. + Thu Feb 15 11:33:49 2001 Shugo Maeda * lib/cgi/session.rb (close): fixed reversed condition. @@ -3271,7 +3284,7 @@ Sat Apr 1 22:50:28 2000 Yukihiro Matsumoto Sat Apr 1 21:30:53 2000 WATANABE Hirofumi - * io.c(rb_io_printf, rb_f_printf): should use rb_io_write. + * io.c (rb_io_printf, rb_f_printf): should use rb_io_write. Sat Apr 1 00:16:05 2000 Yukihiro Matsumoto diff --git a/ToDo b/ToDo index c0034dbb2b..fa60ea0128 100644 --- a/ToDo +++ b/ToDo @@ -20,7 +20,7 @@ Language Spec. + remove scope by block + variables appears within block may have independent values. * Regexp: make /o thread safe. -* decide if begin with rescue or ensure make do..while loop. +* decide whether begin with rescue or ensure make do..while loop. * a +1 to be a+1, not a(+1). * unify == and eql? again * to_i returns nil if str contains no digit. @@ -51,6 +51,10 @@ Standard Libraries - Enume#inject - Array#fetch - IO::for_fd +- Process::waitall [ruby-talk:4557] +- Process::Status +- File::lchown, File::lchmod; xxx - still need work for non existing platforms +- move Time::times to Process. * Enumerable#sort_by for Schwartzian transformation * String#scanf(?) * Object#fmt(?) @@ -63,16 +67,13 @@ Standard Libraries * optional stepsize argument for succ() * Ruby module -- Ruby::Version, Ruby::Interpreter * introduce Boolean class; super of TrueClass, FalseClass -* Process::waitall [ruby-talk:4557] * synchronized method - synchronized{...}, synchronized :foo, :bar -* move Time::times to Process. * Array#&, Array#| to allow duplication. ??? * fork_and_kill_other_threads. * way to specify immortal (fork endurance) thread; * or raise ForkException to every thread but fork caller. * Hash::new{default} or recommend Hash#fetch? * new user-defined marshal scheme. _dump(dumper), _load(restorer) -* lchown, lchmod, etc. Extension Libraries diff --git a/configure.in b/configure.in index 609d68510a..0c4f0ad94a 100644 --- a/configure.in +++ b/configure.in @@ -248,7 +248,7 @@ AC_REPLACE_FUNCS(dup2 memmove mkdir strcasecmp strncasecmp strerror strftime\ AC_CHECK_FUNCS(fmod killpg drand48 random wait4 waitpid syscall getcwd chroot\ truncate chsize times utimes fcntl lockf lstat symlink readlink\ setitimer setruid seteuid setreuid setresuid \ - setrgid setegid setregid setresgid pause\ + setrgid setegid setregid setresgid pause lchown lchmod\ getpgrp setpgrp getpgid setpgid getgroups getpriority getrlimit\ dlopen sigprocmask sigaction _setjmp setsid telldir seekdir fchmod) AC_STRUCT_TIMEZONE diff --git a/ext/socket/socket.c b/ext/socket/socket.c index a2bf61009b..1e3611394d 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -895,16 +895,11 @@ tcp_s_open(argc, argv, class) &local_host, &local_serv); Check_SafeStr(remote_host); - if (!NIL_P(local_host)) { Check_SafeStr(local_host); } - if (NIL_P(local_serv)) { - local_serv = INT2NUM(0); - } - return open_inet(class, remote_host, remote_serv, local_host, local_serv, INET_CLIENT); } diff --git a/file.c b/file.c index 749eb061fa..c4e6781ae7 100644 --- a/file.c +++ b/file.c @@ -951,6 +951,42 @@ rb_file_chmod(obj, vmode) return INT2FIX(0); } +#if defined(HAVE_LCHMOD) +static void +lchmod_internal(path, mode) + const char *path; + int mode; +{ + if (lchmod(path, mode) == -1) + rb_sys_fail(path); +} + +static VALUE +rb_file_s_lchmod(argc, argv) + int argc; + VALUE *argv; +{ + VALUE vmode; + VALUE rest; + int mode, n; + + rb_secure(2); + rb_scan_args(argc, argv, "1*", &vmode, &rest); + mode = NUM2INT(vmode); + + n = apply2files(lchmod_internal, rest, mode); + return INT2FIX(n); +} +#else +static VALUE +rb_file_s_lchmod(argc, argv) + int argc; + VALUE *argv; +{ + rb_notimplement(); +} +#endif + struct chown_args { int owner, group; }; @@ -1012,6 +1048,53 @@ rb_file_chown(obj, owner, group) return INT2FIX(0); } +#if defined(HAVE_LCHOWN) +static void +lchown_internal(path, args) + const char *path; + struct chown_args *args; +{ + if (lchown(path, args->owner, args->group) < 0) + rb_sys_fail(path); +} + +static VALUE +rb_file_s_lchown(argc, argv) + int argc; + VALUE *argv; +{ + VALUE o, g, rest; + struct chown_args arg; + int n; + + rb_secure(2); + rb_scan_args(argc, argv, "2*", &o, &g, &rest); + if (NIL_P(o)) { + arg.owner = -1; + } + else { + arg.owner = NUM2INT(o); + } + if (NIL_P(g)) { + arg.group = -1; + } + else { + arg.group = NUM2INT(g); + } + + n = apply2files(lchown_internal, rest, &arg); + return INT2FIX(n); +} +#else +static VALUE +rb_file_s_lchown(argc, argv) + int argc; + VALUE *argv; +{ + rb_notimplement(); +} +#endif + struct timeval rb_time_timeval(); #if defined(HAVE_UTIMES) && !defined(__CHECKER__) @@ -2206,6 +2289,8 @@ Init_File() rb_define_singleton_method(rb_cFile, "utime", rb_file_s_utime, -1); rb_define_singleton_method(rb_cFile, "chmod", rb_file_s_chmod, -1); rb_define_singleton_method(rb_cFile, "chown", rb_file_s_chown, -1); + rb_define_singleton_method(rb_cFile, "lchmod", rb_file_s_lchmod, -1); + rb_define_singleton_method(rb_cFile, "lchown", rb_file_s_lchown, -1); rb_define_singleton_method(rb_cFile, "link", rb_file_s_link, 2); rb_define_singleton_method(rb_cFile, "symlink", rb_file_s_symlink, 2); diff --git a/intern.h b/intern.h index d0253df025..f1a0b70659 100644 --- a/intern.h +++ b/intern.h @@ -260,6 +260,7 @@ void rb_lastline_set _((VALUE)); /* process.c */ int rb_proc_exec _((const char*)); void rb_syswait _((int)); +VALUE rb_proc_times _((VALUE)); /* range.c */ VALUE rb_range_new _((VALUE, VALUE, int)); VALUE rb_range_beg_len _((VALUE, long*, long*, long, int)); diff --git a/io.c b/io.c index fc65849096..3c25f289ce 100644 --- a/io.c +++ b/io.c @@ -2242,8 +2242,6 @@ set_outfile(val, var, orig, stdf) GetOpenFile(val, fptr); rb_io_check_writable(fptr); - - GetOpenFile(*var, fptr); f = GetWriteFile(fptr); dup2(fileno(f), fileno(stdf)); diff --git a/process.c b/process.c index f49ef23eae..dcde77a9bb 100644 --- a/process.c +++ b/process.c @@ -49,6 +49,14 @@ struct timeval rb_time_interval _((VALUE)); #undef HAVE_GETPGRP #endif +#ifdef HAVE_SYS_TIMES_H +#include +#endif + +#if defined(HAVE_TIMES) || defined(NT) +static VALUE S_Tms; +#endif + static VALUE get_pid() { @@ -108,7 +116,16 @@ pst_bitand(st1, st2) } static VALUE -pst_ifstopped(st) +pst_rshift(st1, st2) + VALUE st1, st2; +{ + int status = NUM2INT(st1) >> NUM2INT(st2); + + return INT2NUM(status); +} + +static VALUE +pst_wifstopped(st) VALUE st; { int status = NUM2INT(st); @@ -120,7 +137,7 @@ pst_ifstopped(st) } static VALUE -pst_stopsig(st) +pst_wstopsig(st) VALUE st; { int status = NUM2INT(st); @@ -129,7 +146,7 @@ pst_stopsig(st) } static VALUE -pst_ifsignaled(st) +pst_wifsignaled(st) VALUE st; { int status = NUM2INT(st); @@ -141,7 +158,7 @@ pst_ifsignaled(st) } static VALUE -pst_termsig(st) +pst_wtermsig(st) VALUE st; { int status = NUM2INT(st); @@ -150,7 +167,7 @@ pst_termsig(st) } static VALUE -pst_ifexited(st) +pst_wifexited(st) VALUE st; { int status = NUM2INT(st); @@ -162,7 +179,7 @@ pst_ifexited(st) } static VALUE -pst_exitstatus(st) +pst_wexitstatus(st) VALUE st; { int status = NUM2INT(st); @@ -171,7 +188,7 @@ pst_exitstatus(st) } static VALUE -pst_coredump(st) +pst_wcoredump(st) VALUE st; { #ifdef WCOREDUMP @@ -1254,6 +1271,31 @@ proc_setegid(obj, egid) return egid; } +VALUE +rb_proc_times(obj) + VALUE obj; +{ +#if defined(HAVE_TIMES) && !defined(__CHECKER__) +#ifndef HZ +# ifdef CLK_TCK +# define HZ CLK_TCK +# else +# define HZ 60 +# endif +#endif /* HZ */ + struct tms buf; + + if (times(&buf) == -1) rb_sys_fail(0); + return rb_struct_new(S_Tms, + rb_float_new((double)buf.tms_utime / HZ), + rb_float_new((double)buf.tms_stime / HZ), + rb_float_new((double)buf.tms_cutime / HZ), + rb_float_new((double)buf.tms_cstime / HZ)); +#else + rb_notimplement(); +#endif +} + VALUE rb_mProcess; void @@ -1297,18 +1339,19 @@ Init_process() rb_define_method(rb_cProcStatus, "==", pst_equal, 1); rb_define_method(rb_cProcStatus, "&", pst_bitand, 1); + rb_define_method(rb_cProcStatus, ">>", pst_rshift, 1); rb_define_method(rb_cProcStatus, "to_i", pst_to_i, 0); rb_define_method(rb_cProcStatus, "to_int", pst_to_i, 0); rb_define_method(rb_cProcStatus, "to_s", pst_to_s, 0); rb_define_method(rb_cProcStatus, "inspect", pst_to_s, 0); - rb_define_method(rb_cProcStatus, "ifstopped?", pst_ifstopped, 0); - rb_define_method(rb_cProcStatus, "stopsig", pst_stopsig, 0); - rb_define_method(rb_cProcStatus, "ifsignaled?", pst_ifsignaled, 0); - rb_define_method(rb_cProcStatus, "termsig", pst_termsig, 0); - rb_define_method(rb_cProcStatus, "ifexited?", pst_ifexited, 0); - rb_define_method(rb_cProcStatus, "exitstatus", pst_exitstatus, 0); - rb_define_method(rb_cProcStatus, "coredump?", pst_coredump, 0); + rb_define_method(rb_cProcStatus, "stopped?", pst_wifstopped, 0); + rb_define_method(rb_cProcStatus, "stopsig", pst_wstopsig, 0); + rb_define_method(rb_cProcStatus, "signaled?", pst_wifsignaled, 0); + rb_define_method(rb_cProcStatus, "termsig", pst_wtermsig, 0); + rb_define_method(rb_cProcStatus, "exited?", pst_wifexited, 0); + rb_define_method(rb_cProcStatus, "exitstatus", pst_wexitstatus, 0); + rb_define_method(rb_cProcStatus, "coredump?", pst_wcoredump, 0); rb_define_module_function(rb_mProcess, "pid", get_pid, 0); rb_define_module_function(rb_mProcess, "ppid", get_ppid, 0); @@ -1338,4 +1381,10 @@ Init_process() rb_define_module_function(rb_mProcess, "euid=", proc_seteuid, 1); rb_define_module_function(rb_mProcess, "egid", proc_getegid, 0); rb_define_module_function(rb_mProcess, "egid=", proc_setegid, 1); + + rb_define_module_function(rb_mProcess, "times", rb_proc_times, 0); + +#if defined(HAVE_TIMES) || defined(NT) + S_Tms = rb_struct_define("Tms", "utime", "stime", "cutime", "cstime", 0); +#endif } diff --git a/time.c b/time.c index 9acc00f7a6..4648611ef8 100644 --- a/time.c +++ b/time.c @@ -26,18 +26,11 @@ struct timeval { #endif #endif /* NT */ -#ifdef HAVE_SYS_TIMES_H -#include -#endif - #ifdef HAVE_UNISTD_H #include #endif VALUE rb_cTime; -#if defined(HAVE_TIMES) || defined(NT) -static VALUE S_Tms; -#endif struct time_object { struct timeval tv; @@ -953,25 +946,8 @@ static VALUE time_s_times(obj) VALUE obj; { -#if defined(HAVE_TIMES) && !defined(__CHECKER__) -#ifndef HZ -# ifdef CLK_TCK -# define HZ CLK_TCK -# else -# define HZ 60 -# endif -#endif /* HZ */ - struct tms buf; - - if (times(&buf) == -1) rb_sys_fail(0); - return rb_struct_new(S_Tms, - rb_float_new((double)buf.tms_utime / HZ), - rb_float_new((double)buf.tms_stime / HZ), - rb_float_new((double)buf.tms_cutime / HZ), - rb_float_new((double)buf.tms_cstime / HZ)); -#else - rb_notimplement(); -#endif + rb_warn("obsolete method Time::times; use Process::times"); + return rb_proc_times(obj); } static VALUE @@ -1113,10 +1089,6 @@ Init_Time() rb_define_method(rb_cTime, "strftime", time_strftime, 1); -#if defined(HAVE_TIMES) || defined(NT) - S_Tms = rb_struct_define("Tms", "utime", "stime", "cutime", "cstime", 0); -#endif - /* methods for marshaling */ rb_define_method(rb_cTime, "_dump", time_dump, -1); rb_define_singleton_method(rb_cTime, "_load", time_load, 1); diff --git a/version.h b/version.h index 7fa8e26fc7..fbd1c597de 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.7.0" -#define RUBY_RELEASE_DATE "2001-02-15" +#define RUBY_RELEASE_DATE "2001-02-16" #define RUBY_VERSION_CODE 170 -#define RUBY_RELEASE_CODE 20010215 +#define RUBY_RELEASE_CODE 20010216 -- cgit v1.2.3