summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog49
-rw-r--r--array.c3
-rw-r--r--configure.in4
-rw-r--r--doc/NEWS8
-rw-r--r--eval.c10
-rw-r--r--ext/pty/pty.c126
-rw-r--r--ext/socket/socket.c74
-rw-r--r--intern.h1
-rw-r--r--io.c4
-rw-r--r--lib/cgi/session.rb7
-rw-r--r--misc/ruby-mode.el45
-rw-r--r--numeric.c17
-rw-r--r--pack.c16
-rw-r--r--parse.y3
-rw-r--r--process.c130
-rw-r--r--signal.c2
-rw-r--r--string.c71
-rw-r--r--version.h4
18 files changed, 331 insertions, 243 deletions
diff --git a/ChangeLog b/ChangeLog
index 76e476d..334e768 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,58 @@
+Mon Aug 6 03:29:03 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_lstrip_bang): new method.
+
+ * string.c (rb_str_rstrip_bang): new method.
+
+Sun Aug 5 19:28:39 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
+
+ * string.c (rb_str_associate): should consider STR_ASSOC too.
+
+Sun Aug 5 07:46:18 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
+
+ * eval.c (rb_undefined): do not recurse if method_missing is
+ undefined.
+
+Thu Aug 2 21:37:32 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * process.c (proc_waitpid): now all arguments are optional.
+
+ * process.c (Init_process): waitpid is now alias to wait.
+
+ * process.c (Init_process): waitpid2 is now alias to wait2.
+
+ * process.c (rb_waitpid): made public.
+
+ * ext/pty/pty.c (pty_getpty): avoid disturbing SIGCHLD using
+ thread and rb_waitpid.
+
+Thu Aug 2 11:23:07 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * process.c (proc_getpgrp): now takes no argument on all
+ platforms.
+
+ * process.c (proc_setpgrp): ditto.
+
Thu Aug 2 01:29:42 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* file.c (strrdirsep): removed meaningless code.
* file.c (rb_file_s_expand_path): reverted to 1.66.
+Wed Aug 1 16:17:47 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ext/socket/socket.c (sock_s_pack_sockaddr_in): added
+ Socket::pack_sockaddr_in(). [new]
+
+ * ext/socket/socket.c (sock_s_pack_sockaddr_un): added
+ Socket::pack_sockaddr_un(). [new]
+
+ * ext/socket/socket.c (sock_s_pack_sockaddr_in): added
+ Socket::unpack_sockaddr_in(). [new]
+
+ * ext/socket/socket.c (sock_s_pack_sockaddr_un): added
+ Socket::unpack_sockaddr_un(). [new]
+
Wed Aug 1 15:42:16 2001 Usaku Nakamura <usa@ruby-lang.org>
* eval.c (ruby_run): avoid VC++ warning.
diff --git a/array.c b/array.c
index 5acc45a..4ca1dc3 100644
--- a/array.c
+++ b/array.c
@@ -735,6 +735,7 @@ rb_ary_dup(ary)
OBJSETUP(dup, rb_obj_type(ary), T_ARRAY);
MEMCPY(RARRAY(dup)->ptr, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
RARRAY(dup)->len = RARRAY(ary)->len;
+ OBJ_INFECT(dup, ary);
return dup;
}
@@ -1736,7 +1737,7 @@ Init_Array()
rb_define_method(rb_cArray, "indexes", rb_ary_indexes, -1);
rb_define_method(rb_cArray, "indices", rb_ary_indexes, -1);
rb_define_method(rb_cArray, "clone", rb_ary_clone, 0);
- rb_define_method(rb_cArray, "clone", rb_ary_dup, 0);
+ rb_define_method(rb_cArray, "dup", rb_ary_dup, 0);
rb_define_method(rb_cArray, "join", rb_ary_join_m, -1);
rb_define_method(rb_cArray, "reverse", rb_ary_reverse_m, 0);
rb_define_method(rb_cArray, "reverse!", rb_ary_reverse_bang, 0);
diff --git a/configure.in b/configure.in
index ec4d3d7..2fd670d 100644
--- a/configure.in
+++ b/configure.in
@@ -660,6 +660,10 @@ if test "$with_dln_a_out" != yes; then
;;
esac
rb_cv_dlopen=yes ;;
+ nto-qnx*) DLDFLAGS="-L/lib -L/usr/lib -L/usr/local/lib"
+ LDSHARED='ld -Bshareable -x'
+ LDFLAGS="-L/lib -L/usr/lib -L/usr/local/lib"
+ rb_cv_dlopen=yes;;
cygwin*|mingw*) : ${LDSHARED="${DLLWRAP} --target=${target_os} --as=${AS} --dlltool-name=${DLLTOOL} --driver-name=${CC} --export-all -s"}
rb_cv_dlopen=yes ;;
*) LDSHARED='ld' ;;
diff --git a/doc/NEWS b/doc/NEWS
index ff24df1..ccb6b49 100644
--- a/doc/NEWS
+++ b/doc/NEWS
@@ -1,3 +1,11 @@
+: Socket::pack_sockaddr_in(), Socket::unpack_sockaddr_in()
+
+ Added. Utility for direct Socket access.
+
+: Socket::pack_sockaddr_un(), Socket::unpack_sockaddr_un()
+
+ Added. Utility for direct Socket access.
+
: String#casecmp
Added. This is a case insensitive version of String#<=>.
diff --git a/eval.c b/eval.c
index 5300a6c..439de65 100644
--- a/eval.c
+++ b/eval.c
@@ -4213,12 +4213,18 @@ rb_undefined(obj, id, argc, argv, call_status)
{
VALUE *nargv;
+ last_call_status = call_status;
+
+ if (id == missing) {
+ PUSH_FRAME();
+ rb_f_missing(argc, argv, obj);
+ POP_FRAME();
+ }
+
nargv = ALLOCA_N(VALUE, argc+1);
nargv[0] = ID2SYM(id);
MEMCPY(nargv+1, argv, VALUE, argc);
- last_call_status = call_status;
-
return rb_funcall2(obj, missing, argc+1, nargv);
}
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index 12063f9..9d2fb52 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -94,10 +94,6 @@ char SlaveName[DEVICELEN];
extern int errno;
-#define MAX_PTY 16
-static int n_pty,last_pty;
-static int chld_pid[MAX_PTY];
-
#ifndef HAVE_SETEUID
# ifdef HAVE_SETREUID
# define seteuid(e) setreuid(-1, (e))
@@ -116,88 +112,44 @@ struct pty_info {
};
static void
-set_signal_action(action)
- RETSIGTYPE (*action)();
+pty_raise(cpid)
+ int cpid;
{
-#ifdef __hpux
- struct sigvec sv;
- /*
- * signal SIGCHLD should be delivered on stop of the child
- */
- sv.sv_handler = action;
- sv.sv_mask = sigmask(SIGCHLD);
- sv.sv_flags = SV_BSDSIG;
- sigvector(SIGCHLD, &sv, (struct sigvec *) 0);
-#else /* not HPUX */
-#if defined(SA_NOCLDSTOP)
- struct sigaction sa;
- /*
- * signal SIGCHLD should be delivered on stop of the child
- * (for SVR4)
- */
- sa.sa_handler = action;
- sigemptyset(&sa.sa_mask);
- sigaddset(&sa.sa_mask, SIGCHLD);
- sa.sa_flags = 0; /* SA_NOCLDSTOP flag is removed */
- sigaction(SIGCHLD, &sa, (struct sigaction *) 0);
-#else
- signal(SIGCHLD,action);
-#endif
-#endif /* not HPUX */
+ char buf[1024];
+ snprintf(buf, sizeof(buf),
+ "eval %%Q{Thread.main.raise 'pty - stopped: %d'}, nil, \"%s\", %d",
+ cpid, ruby_sourcefile, ruby_sourceline);
+ rb_eval_string(buf);
}
-static void
-reset_signal_action()
+static VALUE
+pty_syswait(pid)
+ int pid;
{
- set_signal_action(SIG_DFL);
-}
+ int cpid, status;
-static RETSIGTYPE
-chld_changed()
-{
- int cpid;
- int i,n = -1;
- int statusp;
+ cpid = rb_waitpid(pid, &status, WUNTRACED);
- for (;;) {
-#ifdef HAVE_WAITPID
- cpid = waitpid(-1, &statusp, WUNTRACED|WNOHANG);
-#else
- cpid = wait3(&statusp, WUNTRACED|WNOHANG, 0);
-#endif
- if (cpid == 0 || cpid == -1)
- return;
- for (i = 0; i < last_pty; i++) {
- if (chld_pid[i] == cpid) {
- n = i;
- goto catched;
- }
- }
- rb_raise(rb_eRuntimeError, "fork: %d", cpid);
- }
- catched:
+ printf("PTY command (%d) finished (%d:%d)\n", pid, cpid, status);
+ if (cpid == 0 || cpid == -1)
+ return Qnil;
#ifdef IF_STOPPED
- if (IF_STOPPED(statusp)) { /* suspend */
- rb_raise(rb_eRuntimeError, "Stopped: %d",cpid);
+ if (IF_STOPPED(status)) { /* suspend */
+ pty_raise(cpid);
}
#else
#ifdef WIFSTOPPED
- if (WIFSTOPPED(statusp)) { /* suspend */
- rb_raise(rb_eRuntimeError, "Stopped: %d",cpid);
+ if (WIFSTOPPED(status)) { /* suspend */
+ pty_raise(cpid);
}
#else
---->> Either IF_STOPPED or WIFSTOPPED is needed <<----
#endif /* WIFSTOPPED */
#endif /* IF_STOPPED */
- if (n >= 0) {
- chld_pid[n] = 0;
- n_pty--;
- if (n_pty == 0)
- reset_signal_action();
- }
- rb_raise(rb_eRuntimeError, "Child_changed: %d",cpid);
+
+ return Qnil;
}
static void getDevice _((int*, int*));
@@ -227,7 +179,6 @@ establishShell(shellname, info)
getDevice(&master,&slave);
currentPid = getpid();
- set_signal_action(chld_changed);
if((i = vfork()) < 0) {
rb_sys_fail("fork failed");
}
@@ -304,19 +255,6 @@ establishShell(shellname, info)
close(slave);
- if (n_pty == last_pty) {
- chld_pid[n_pty] = i;
- n_pty++;
- last_pty++;
- }
- else {
- for (j = 0; j < last_pty; j++) {
- if (chld_pid[j] == 0) {
- chld_pid[j] = i;
- n_pty++;
- }
- }
- }
info->child_pid = i;
info->fd = master;
}
@@ -426,16 +364,12 @@ static VALUE
pty_getpty(self, shell)
VALUE self, shell;
{
- VALUE res;
+ VALUE res, th;
struct pty_info info;
OpenFile *wfptr,*rfptr;
NEWOBJ(rport, struct RFile);
NEWOBJ(wport, struct RFile);
- if (n_pty == MAX_PTY+1) {
- rb_raise(rb_eRuntimeError, "Too many ptys are open");
- }
-
OBJSETUP(rport, rb_cFile, T_FILE);
MakeOpenFile(rport, rfptr);
@@ -457,32 +391,34 @@ pty_getpty(self, shell)
rb_ary_store(res,1,(VALUE)wport);
rb_ary_store(res,2,INT2FIX(info.child_pid));
+ printf("start watching PTY command (%d)\n", info.child_pid);
+ th = rb_thread_create(pty_syswait, (void*)info.child_pid);
if (rb_block_given_p()) {
- rb_yield((VALUE)res);
- reset_signal_action();
- return Qnil;
+ res = rb_yield((VALUE)res);
+ rb_funcall(th, rb_intern("kill"), 0, 0);
+ return res;
}
else {
return (VALUE)res;
}
}
-/* ruby function: protect_signal */
+/* ruby function: protect_signal - obsolete */
static VALUE
pty_protect(self)
VALUE self;
{
- reset_signal_action();
+ rb_warn("PTY::protect_signal is no longer needed");
rb_yield(Qnil);
- set_signal_action(chld_changed);
return self;
}
+/* ruby function: reset_signal - obsolete */
static VALUE
pty_reset_signal(self)
VALUE self;
{
- reset_signal_action();
+ rb_warn("PTY::reset_signal is no longer needed");
return self;
}
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 86f9dfc..d3e3fd5 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1562,7 +1562,7 @@ static VALUE
sock_s_socketpair(class, domain, type, protocol)
VALUE class, domain, type, protocol;
{
-#if !defined(NT) && !defined(__BEOS__) && !defined(__EMX__)
+#if !defined(NT) && !defined(__BEOS__) && !defined(__EMX__) && !defined(__QNXNTO__)
int d, t, sp[2];
setup_domain_and_type(domain, &d, type, &t);
@@ -1806,11 +1806,20 @@ sock_s_gethostbyaddr(argc, argv)
{
VALUE addr, type;
struct hostent *h;
+ struct sockaddr *sa;
+ int t = AF_INET;
rb_scan_args(argc, argv, "11", &addr, &type);
- StringValue(addr);
- h = gethostbyaddr(RSTRING(addr)->ptr, RSTRING(addr)->len,
- NIL_P(type)?AF_INET:NUM2INT(type));
+ sa = (struct sockaddr*)StringValuePtr(addr);
+ if (!NIL_P(type)) {
+ t = NUM2INT(type);
+ }
+#ifdef INET6
+ else if (RSTRING(addr)->len == 16) {
+ t = AF_INET6;
+ }
+#endif
+ h = gethostbyaddr(RSTRING(addr)->ptr, RSTRING(addr)->len, t);
return mkhostent(h);
}
@@ -2055,6 +2064,57 @@ sock_s_getnameinfo(argc, argv)
rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error));
}
+static VALUE
+sock_s_pack_sockaddr_in(self, port, host)
+ VALUE self, port, host;
+{
+ struct addrinfo *res = ip_addrsetup(host, port);
+ VALUE addr = rb_str_new((char*)res->ai_addr, res->ai_addrlen);
+
+ freeaddrinfo(res);
+ OBJ_INFECT(addr, port);
+ OBJ_INFECT(addr, host);
+
+ return addr;
+}
+
+static VALUE
+sock_s_pack_sockaddr_un(self, path)
+ VALUE self, path;
+{
+ struct sockaddr_un sockaddr;
+ VALUE addr;
+
+ MEMZERO(&sockaddr, struct sockaddr_un, 1);
+ sockaddr.sun_family = AF_UNIX;
+ strncpy(sockaddr.sun_path, StringValuePtr(path), sizeof(sockaddr.sun_path)-1);
+ addr = rb_str_new((char*)&sockaddr, sizeof(sockaddr));
+ OBJ_INFECT(addr, path);
+
+ return addr;
+}
+
+static VALUE
+sock_s_unpack_sockaddr_in(self, addr)
+ VALUE self, addr;
+{
+ struct sockaddr_in * sockaddr;
+
+ sockaddr = (struct sockaddr_in*)StringValuePtr(addr);
+ return rb_assoc_new(INT2NUM(ntohs(sockaddr->sin_port)), mkipaddr(sockaddr));
+}
+
+static VALUE
+sock_s_unpack_sockaddr_un(self, addr)
+ VALUE self, addr;
+{
+ struct sockaddr_un * sockaddr;
+
+ sockaddr = (struct sockaddr_un*)StringValuePtr(addr);
+ /* xxx: should I check against sun_path size? */
+ return rb_tainted_str_new2(sockaddr->sun_path);
+}
+
static VALUE mConst;
static void
@@ -2164,6 +2224,12 @@ Init_socket()
rb_define_singleton_method(rb_cSocket, "getservbyname", sock_s_getservbyaname, -1);
rb_define_singleton_method(rb_cSocket, "getaddrinfo", sock_s_getaddrinfo, -1);
rb_define_singleton_method(rb_cSocket, "getnameinfo", sock_s_getnameinfo, -1);
+ rb_define_singleton_method(rb_cSocket, "sockaddr_in", sock_s_pack_sockaddr_in, 2);
+ rb_define_singleton_method(rb_cSocket, "sockaddr_un", sock_s_pack_sockaddr_un, 1);
+ rb_define_singleton_method(rb_cSocket, "pack_sockaddr_in", sock_s_pack_sockaddr_in, 2);
+ rb_define_singleton_method(rb_cSocket, "pack_sockaddr_un", sock_s_pack_sockaddr_un, 1);
+ rb_define_singleton_method(rb_cSocket, "unpack_sockaddr_in", sock_s_unpack_sockaddr_in, 1);
+ rb_define_singleton_method(rb_cSocket, "unpack_sockaddr_un", sock_s_unpack_sockaddr_un, 1);
/* constants */
mConst = rb_define_module_under(rb_cSocket, "Constants");
diff --git a/intern.h b/intern.h
index 4cd56ea..32970dd 100644
--- a/intern.h
+++ b/intern.h
@@ -275,6 +275,7 @@ void rb_lastline_set _((VALUE));
VALUE rb_sym_all_symbols _((void));
/* process.c */
int rb_proc_exec _((const char*));
+int rb_waitpid _((int,int*,int));
void rb_syswait _((int));
VALUE rb_proc_times _((VALUE));
/* range.c */
diff --git a/io.c b/io.c
index 448fd60..0d8f489 100644
--- a/io.c
+++ b/io.c
@@ -31,6 +31,10 @@
# define USE_SETVBUF
#endif
+#ifdef __QNXNTO__
+#include "unix.h"
+#endif
+
#include <sys/types.h>
#if !defined(DJGPP) && !defined(NT) && !defined(__human68k__)
#include <sys/ioctl.h>
diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb
index 9187dbf..23c9bdc 100644
--- a/lib/cgi/session.rb
+++ b/lib/cgi/session.rb
@@ -12,7 +12,7 @@ class CGI
def Session::callback(dbman)
lambda{
- dbman.close
+ dbman[0].close unless dbman.empty?
}
end
@@ -63,7 +63,8 @@ class CGI
end)
]
end
- ObjectSpace::define_finalizer(self, Session::callback(@dbman))
+ @dbprot = [@dbman]
+ ObjectSpace::define_finalizer(self, Session::callback(@dbprot))
end
def [](key)
@@ -89,10 +90,12 @@ class CGI
def close
@dbman.close
+ @dbprot.clear
end
def delete
@dbman.delete
+ @dbprot.clear
end
class FileStore
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index d29e3bd..40f1eaa 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -707,6 +707,9 @@ An end of a defun is found by moving forward from the beginning of one."
(defvar ruby-font-lock-keywords
(list
+ ;; trick
+ '("\\s-+" 0 nil t)
+ '("\\S-+" 0 nil t)
(cons (concat
"\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\("
(mapconcat
@@ -750,16 +753,14 @@ An end of a defun is found by moving forward from the beginning of one."
"\\|")
"\\)\\>\\([^_]\\|$\\)")
2)
- ;; regexps
- '("/\\(\\(\\\\/\\|[^/\n]\\)*\\)/\\([iop]*\\)"
- (1 font-lock-string-face)
- (3 font-lock-constant-face))
;; variables
'("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\b\\([^_]\\|$\\)"
2 font-lock-variable-name-face)
;; variables
- '("[$@].\\(\\w\\|_\\)*"
- 0 font-lock-variable-name-face)
+ '("\\(\\$\\(\\W\\|[0-9]\\)\\)\\W"
+ 1 font-lock-variable-name-face t)
+ '("\\($\\|@\\|@@\\)\\(\\w\\(\\w\\|_\\)*\\|#{\\)"
+ 0 font-lock-variable-name-face t)
;; embedded document
'(ruby-font-lock-docs
0 font-lock-comment-face t)
@@ -772,8 +773,36 @@ An end of a defun is found by moving forward from the beginning of one."
'("^\\s *def\\s +\\([^( ]+\\)"
1 font-lock-function-name-face)
;; symbols
- '("\\(^\\|[^:]\\)\\(:\\([-+/%&|^~`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|\\[\\]\\|\\(\\w\\|_\\)+\\([!?=]\\|\\b\\)\\)\\)"
- 2 font-lock-reference-face))
+ '("\\(^\\|[^:]\\)\\(:\\([-+/%&|^~`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|\\[\\]\\|\\(\\w\\|_\\)+\\([!?=]\\|\\b\\)\\|#{[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\)\\)"
+ 2 font-lock-reference-face)
+ ;; strings
+ ;; %Q! !
+ '("[[\\s <+(,]%[rqQ]?\\(\\([^a-zA-Z0-9 \n]\\)[^\\2\n\\\\]*\\(\\\\.[^\\2\n\\\\]*\\)*\\2\\)"
+ 1 font-lock-string-face t)
+ ;; '...'
+ '("[[\\s <+(,]\\('[^'\n\\\\]*\\(\\\\.[^'\n\\\\]*\\)*'\\)"
+ 1 font-lock-string-face t)
+ ;; "..."
+ '("[[\\s <+(,]\\(\"[^\"\n\\\\]*\\(\\\\.[^\"\n\\\\]*\\)*\"\\)"
+ 1 font-lock-string-face t)
+ ;; `...`
+ '("[\\s <+(,]\\(`[^`\n\\\\]*\\(\\\\.[^`\n\\\\]*\\)*`\\)"
+ 1 font-lock-warning-face t)
+ ;; %x!...!
+ '("[\\s <+(,]%x\\(\\([^a-zA-Z0-9 \n]\\)[^\\2\n\\]*\\(\\\\.[^\\2\n\\]*\\)*\\2\\)"
+ 1 font-lock-warning-face t)
+ ;; regexps
+ '("\\(^\\|[=(,~?:]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|\\.g?sub!?\\)\\s *\\(/[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*/\\([iop]*\\)\\)"
+ (4 font-lock-string-face t)
+ (6 font-lock-constant-face t))
+ '("\\(/[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*/\\)\\s *[=!][=~]"
+ 1 font-lock-string-face t)
+ ;; expression expansion
+ '("#{[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}"
+ 0 font-lock-variable-name-face t)
+ ;; comment
+ '("^\\s *\\([^#\n'\"%/]\\|'[^'\n\\]*\\(\\\\.[^'\n\\]*\\)*'\\|\"[^\"\n\\]*\\(\\\\.[^\"\n\\]*\\)*\"\\|%[rqQx]?\\([^a-zA-Z0-9 \n]\\)[^\\4\n\\]*\\(\\\\.[^\\4\n\\]*\\)*\\4\\|/[^/\n\\]*\\(\\\\.[^/\n\\]\\)*/\\|#{[^}\\\\]*\\(\\\\.[^}\\\\]*\\)*}\\)*\\(#\\([^{\n].*\\|$\\)\\)"
+ 8 font-lock-comment-face t))
"*Additional expressions to highlight in ruby mode."))
((featurep 'hilit19)
diff --git a/numeric.c b/numeric.c
index 027ee63..bf3f462 100644
--- a/numeric.c
+++ b/numeric.c
@@ -17,8 +17,7 @@
#include <floatingpoint.h>
#endif
-static ID coerce;
-static ID to_i;
+static ID id_coerce, id_to_i, id_div;
VALUE rb_cNumeric;
VALUE rb_cFloat;
@@ -47,7 +46,7 @@ static VALUE
coerce_body(x)
VALUE *x;
{
- return rb_funcall(x[1], coerce, 1, x[0]);
+ return rb_funcall(x[1], id_coerce, 1, x[0]);
}
static VALUE
@@ -119,7 +118,7 @@ static VALUE
num_div(x, y)
VALUE x, y;
{
- return rb_funcall(x, '/', 1, y);
+ return rb_funcall(x, id_div, 1, y);
}
static VALUE
@@ -128,7 +127,7 @@ num_divmod(x, y)
{
VALUE div, mod;
- div = rb_funcall(x, '/', 1, y);
+ div = rb_funcall(x, div, 1, y);
if (TYPE(div) == T_FLOAT) {
double d = floor(RFLOAT(div)->value);
@@ -1535,8 +1534,9 @@ Init_Numeric()
/* allow divide by zero -- Inf */
fpsetmask(fpgetmask() & ~(FP_X_DZ|FP_X_INV|FP_X_OFL));
#endif
- coerce = rb_intern("coerce");
- to_i = rb_intern("to_i");
+ id_coerce = rb_intern("coerce");
+ id_to_i = rb_intern("to_i");
+ id_div = rb_intern("div");
rb_eZeroDivError = rb_define_class("ZeroDivisionError", rb_eStandardError);
rb_eFloatDomainError = rb_define_class("FloatDomainError", rb_eRangeError);
@@ -1550,7 +1550,7 @@ Init_Numeric()
rb_define_method(rb_cNumeric, "-@", num_uminus, 0);
rb_define_method(rb_cNumeric, "===", num_equal, 1);
rb_define_method(rb_cNumeric, "eql?", num_eql, 1);
- rb_define_method(rb_cNumeric, "div", num_div, 1);
+ rb_define_method(rb_cNumeric, "/", num_div, 1);
rb_define_method(rb_cNumeric, "divmod", num_divmod, 1);
rb_define_method(rb_cNumeric, "modulo", num_modulo, 1);
rb_define_method(rb_cNumeric, "remainder", num_remainder, 1);
@@ -1675,3 +1675,4 @@ Init_Numeric()
rb_define_method(rb_cFloat, "infinite?", flo_is_infinite_p, 0);
rb_define_method(rb_cFloat, "finite?", flo_is_finite_p, 0);
}
+
diff --git a/pack.c b/pack.c
index 44a683a..caf829e 100644
--- a/pack.c
+++ b/pack.c
@@ -331,7 +331,7 @@ pack_pack(ary, fmt)
static char *nul10 = "\0\0\0\0\0\0\0\0\0\0";
static char *spc10 = " ";
char *p, *pend;
- VALUE res, from, associates = 0;
+ VALUE res, from;
char type;
int items, len, idx;
char *ptr;
@@ -872,10 +872,7 @@ pack_pack(ary, fmt)
StringValue(from);
t = RSTRING(from)->ptr;
}
- if (!associates) {
- associates = rb_ary_new();
- }
- rb_ary_push(associates, from);
+ rb_str_associate(res, from);
rb_str_buf_cat(res, (char*)&t, sizeof(char*));
}
break;
@@ -930,10 +927,6 @@ pack_pack(ary, fmt)
break;
}
}
-
- if (associates) {
- rb_str_associate(res, associates);
- }
return res;
}
@@ -1677,13 +1670,12 @@ pack_unpack(str, fmt)
s += sizeof(char *);
if (t) {
- VALUE a, tmp;
- VALUE *p, *pend;
+ VALUE a, *p, *pend;
- p = RARRAY(a)->ptr;
if (!(a = rb_str_associated(str))) {
rb_raise(rb_eArgError, "no associated pointer");
}
+ p = RARRAY(a)->ptr;
pend = p + RARRAY(a)->len;
while (p < pend) {
if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t) {
diff --git a/parse.y b/parse.y
index dcad843..cf9c9e0 100644
--- a/parse.y
+++ b/parse.y
@@ -4597,10 +4597,11 @@ cond0(node, logop)
enum node_type type = nd_type(node);
assign_in_cond(node);
+ if (logop) return node;
+
switch (type) {
case NODE_DSTR:
case NODE_STR:
- if (logop) break;
rb_warn("string literal in condition");
break;
diff --git a/process.c b/process.c
index 97b8faf..261edb8 100644
--- a/process.c
+++ b/process.c
@@ -227,11 +227,11 @@ pst_wcoredump(st)
static st_table *pid_tbl;
#endif
-static int
-rb_waitpid(pid, flags, st)
+int
+rb_waitpid(pid, st, flags)
int pid;
- int flags;
int *st;
+ int flags;
{
int result;
#ifndef NO_WAITPID
@@ -326,50 +326,7 @@ waitall_each(key, value, data)
#endif
static VALUE
-proc_wait()
-{
- int pid, status;
-#ifdef NO_WAITPID
- struct wait_data data;
-
- if (pid_tbl) {
- data.status = -1;
- st_foreach(pid_tbl, wait_each, &data);
- if (data.status != -1) {
- last_status_set(data.status);
- return INT2FIX(data.pid);
- }
- }
-
- while (1) {
- TRAP_BEG;
- pid = wait(&status);
- TRAP_END;
- if (pid >= 0) break;
- if (errno == EINTR) {
- rb_thread_schedule();
- continue;
- }
- rb_sys_fail(0);
- }
- last_status_set(status);
-#else
- if ((pid = rb_waitpid(-1, 0, &status)) < 0)
- rb_sys_fail(0);
-#endif
- return INT2FIX(pid);
-}
-
-static VALUE
-proc_wait2()
-{
- VALUE pid = proc_wait();
-
- return rb_assoc_new(pid, rb_last_status);
-}
-
-static VALUE
-proc_waitpid(argc, argv)
+proc_wait(argc, argv)
int argc;
VALUE *argv;
{
@@ -377,12 +334,17 @@ proc_waitpid(argc, argv)
int pid, flags, status;
flags = 0;
- rb_scan_args(argc, argv, "11", &vpid, &vflags);
- if (argc == 2 && !NIL_P(vflags)) {
- flags = NUM2UINT(vflags);
+ rb_scan_args(argc, argv, "02", &vpid, &vflags);
+ if (argc == 0) {
+ pid = -1;
}
-
- if ((pid = rb_waitpid(NUM2INT(vpid), flags, &status)) < 0)
+ else {
+ pid = NUM2INT(vpid);
+ if (argc == 2 && !NIL_P(vflags)) {
+ flags = NUM2UINT(vflags);
+ }
+ }
+ if ((pid = rb_waitpid(pid, &status, flags)) < 0)
rb_sys_fail(0);
if (pid == 0) {
rb_last_status = Qnil;
@@ -392,11 +354,11 @@ proc_waitpid(argc, argv)
}
static VALUE
-proc_waitpid2(argc, argv)
+proc_wait2(argc, argv)
int argc;
VALUE *argv;
{
- VALUE pid = proc_waitpid(argc, argv);
+ VALUE pid = proc_wait(argc, argv);
if (NIL_P(pid)) return Qnil;
return rb_assoc_new(pid, rb_last_status);
}
@@ -430,7 +392,7 @@ proc_waitall()
#else
rb_last_status = Qnil;
for (pid = -1;;) {
- pid = rb_waitpid(-1, 0, &status);
+ pid = rb_waitpid(-1, &status, 0);
if (pid == -1) {
if (errno == ECHILD)
break;
@@ -816,7 +778,7 @@ rb_syswait(pid)
ifunc = signal(SIGINT, SIG_IGN);
do {
- i = rb_waitpid(pid, 0, &status);
+ i = rb_waitpid(pid, &status, 0);
} while (i == -1 && errno == EINTR);
#ifdef SIGHUP
@@ -994,52 +956,36 @@ rb_f_sleep(argc, argv)
}
static VALUE
-proc_getpgrp(argc, argv)
- int argc;
- VALUE *argv;
+proc_getpgrp()
{
-#ifdef HAVE_GETPGRP
int pgrp;
-#ifndef GETPGRP_VOID
- VALUE vpid;
- int pid;
- rb_scan_args(argc, argv, "01", &vpid);
- pid = NIL_P(vpid)?0:NUM2INT(vpid);
- pgrp = getpgrp(pid);
-#else
- rb_scan_args(argc, argv, "0");
+#if defined(HAVE_GETPGRP) && defined(GETPGRP_VOID)
pgrp = getpgrp();
-#endif
if (pgrp < 0) rb_sys_fail(0);
return INT2FIX(pgrp);
#else
+# ifdef HAVE_GETPGID
+ pgrp = getpgid(0);
+ if (pgrp < 0) rb_sys_fail(0);
+ return INT2FIX(pgrp);
+# else
rb_notimplement();
+# endif
#endif
}
static VALUE
-proc_setpgrp(argc, argv)
- int argc;
- VALUE *argv;
+proc_setpgrp()
{
-#ifdef HAVE_SETPGRP
-#ifndef SETPGRP_VOID
- VALUE pid, pgrp;
- int ipid, ipgrp;
-
- rb_scan_args(argc, argv, "02", &pid, &pgrp);
-
- ipid = NIL_P(pid)?0:NUM2INT(pid);
- ipgrp = NIL_P(pgrp)?0:NUM2INT(pgrp);
- if (setpgrp(ipid, ipgrp) < 0) rb_sys_fail(0);
-#else
- rb_scan_args(argc, argv, "0");
+#if defined(HAVE_SETPGRP) && defined(SETPGRP_VOID)
if (setpgrp() < 0) rb_sys_fail(0);
-#endif
- return INT2FIX(0);
#else
+# ifdef HAVE_SETPGID
+ if (setpgid(0, 0) < 0) rb_sys_fail(0);
+# else
rb_notimplement();
+# endif
#endif
}
@@ -1328,11 +1274,11 @@ Init_process()
rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1);
rb_define_module_function(rb_mProcess, "kill", rb_f_kill, -1);
#ifndef NT
- rb_define_module_function(rb_mProcess, "wait", proc_wait, 0);
- rb_define_module_function(rb_mProcess, "wait2", proc_wait2, 0);
+ rb_define_module_function(rb_mProcess, "wait", proc_wait, -1);
+ rb_define_module_function(rb_mProcess, "wait2", proc_wait2, -1);
+ rb_define_module_function(rb_mProcess, "waitpid", proc_wait, -1);
+ rb_define_module_function(rb_mProcess, "waitpid2", proc_wait2, -1);
rb_define_module_function(rb_mProcess, "waitall", proc_waitall, 0);
- rb_define_module_function(rb_mProcess, "waitpid", proc_waitpid, -1);
- rb_define_module_function(rb_mProcess, "waitpid2", proc_waitpid2, -1);
rb_cProcStatus = rb_define_class_under(rb_mProcess, "Status", rb_cObject);
rb_undef_method(CLASS_OF(rb_cProcStatus), "new");
@@ -1357,8 +1303,8 @@ Init_process()
rb_define_module_function(rb_mProcess, "ppid", get_ppid, 0);
#endif /* ifndef NT */
- rb_define_module_function(rb_mProcess, "getpgrp", proc_getpgrp, -1);
- rb_define_module_function(rb_mProcess, "setpgrp", proc_setpgrp, -1);
+ rb_define_module_function(rb_mProcess, "getpgrp", proc_getpgrp, 0);
+ rb_define_module_function(rb_mProcess, "setpgrp", proc_setpgrp, 0);
rb_define_module_function(rb_mProcess, "getpgid", proc_getpgid, 1);
rb_define_module_function(rb_mProcess, "setpgid", proc_setpgid, 2);
diff --git a/signal.c b/signal.c
index 2b1e99a..bdfa321 100644
--- a/signal.c
+++ b/signal.c
@@ -292,7 +292,7 @@ posix_signal(signum, handler)
sigact.sa_handler = handler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
-#ifdef SA_RESTART
+#if defined(SA_RESTART)
sigact.sa_flags |= SA_RESTART; /* SVR4, 4.3+BSD */
#endif
#ifdef SA_NOCLDWAIT
diff --git a/string.c b/string.c
index 227f4f7..326b962 100644
--- a/string.c
+++ b/string.c
@@ -202,7 +202,7 @@ void
rb_str_associate(str, add)
VALUE str, add;
{
- if (!FL_TEST(str, STR_NO_ORIG)) {
+ if (FL_TEST(str, STR_NO_ORIG|STR_ASSOC) != (STR_NO_ORIG|STR_ASSOC)) {
if (RSTRING(str)->orig) {
rb_str_modify(str);
}
@@ -216,7 +216,7 @@ VALUE
rb_str_associated(str)
VALUE str;
{
- if (!FL_TEST(str, STR_NO_ORIG|STR_ASSOC)) {
+ if (FL_TEST(str, STR_NO_ORIG|STR_ASSOC) != (STR_NO_ORIG|STR_ASSOC)) {
return Qfalse;
}
return RSTRING(str)->orig;
@@ -2648,7 +2648,7 @@ rb_f_chomp(argc, argv)
}
static VALUE
-rb_str_strip_bang(str)
+rb_str_lstrip_bang(str)
VALUE str;
{
char *s, *t, *e;
@@ -2659,27 +2659,63 @@ rb_str_strip_bang(str)
/* remove spaces at head */
while (s < t && ISSPACE(*s)) s++;
+ RSTRING(str)->len = t-s;
+ if (s > RSTRING(str)->ptr) {
+ memmove(RSTRING(str)->ptr, s, RSTRING(str)->len);
+ RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
+ return str;
+ }
+}
+
+static VALUE
+rb_str_lstrip(str)
+ VALUE str;
+{
+ str = rb_str_dup(str);
+ rb_str_lstrip_bang(str);
+ return str;
+}
+
+static VALUE
+rb_str_rstrip_bang(str)
+ VALUE str;
+{
+ char *s, *t, *e;
+
+ rb_str_modify(str);
+ s = RSTRING(str)->ptr;
+ e = t = s + RSTRING(str)->len;
+
/* remove trailing spaces */
t--;
while (s <= t && ISSPACE(*t)) t--;
t++;
RSTRING(str)->len = t-s;
- if (s > RSTRING(str)->ptr) {
- char *p = RSTRING(str)->ptr;
-
- RSTRING(str)->ptr = ALLOC_N(char, RSTRING(str)->len+1);
- memcpy(RSTRING(str)->ptr, s, RSTRING(str)->len);
- RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
- free(p);
- }
- else if (t < e) {
+ if (t < e) {
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
+ return str;
}
- else {
- return Qnil;
- }
+ return Qnil;
+}
+static VALUE
+rb_str_rstrip(str)
+ VALUE str;
+{
+ str = rb_str_dup(str);
+ rb_str_rstrip_bang(str);
+ return str;
+}
+
+static VALUE
+rb_str_strip_bang(str)
+ VALUE str;
+{
+ VALUE l = rb_str_lstrip_bang(str);
+ VALUE r = rb_str_rstrip_bang(str);
+
+ if (NIL_P(l) && NIL_P(r)) return Qnil;
return str;
}
@@ -3015,12 +3051,17 @@ Init_String()
rb_define_method(rb_cString, "chop", rb_str_chop, 0);
rb_define_method(rb_cString, "chomp", rb_str_chomp, -1);
rb_define_method(rb_cString, "strip", rb_str_strip, 0);
+ rb_define_method(rb_cString, "lstrip", rb_str_lstrip, 0);
+ rb_define_method(rb_cString, "rstrip", rb_str_rstrip, 0);
rb_define_method(rb_cString, "sub!", rb_str_sub_bang, -1);
rb_define_method(rb_cString, "gsub!", rb_str_gsub_bang, -1);
rb_define_method(rb_cString, "strip!", rb_str_strip_bang, 0);
rb_define_method(rb_cString, "chop!", rb_str_chop_bang, 0);
rb_define_method(rb_cString, "chomp!", rb_str_chomp_bang, -1);
+ rb_define_method(rb_cString, "strip!", rb_str_strip_bang, 0);
+ rb_define_method(rb_cString, "lstrip!", rb_str_lstrip_bang, 0);
+ rb_define_method(rb_cString, "rstrip!", rb_str_rstrip_bang, 0);
rb_define_method(rb_cString, "tr", rb_str_tr, 2);
rb_define_method(rb_cString, "tr_s", rb_str_tr_s, 2);
diff --git a/version.h b/version.h
index c9948e2..ca3b759 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.1"
-#define RUBY_RELEASE_DATE "2001-07-31"
+#define RUBY_RELEASE_DATE "2001-08-06"
#define RUBY_VERSION_CODE 171
-#define RUBY_RELEASE_CODE 20010731
+#define RUBY_RELEASE_CODE 20010806