summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-05-23 05:35:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-05-23 05:35:32 +0000
commit6e87a54aecec13d500f90ed4a19ffebc6883794b (patch)
tree8dad6991e36a9eb9ad560c31b6e16ea9edb2a682
parent730d8f1d326a62d86e41faa0482f9a3c329832cb (diff)
* ruby.c (proc_options): removed "-*-" support for #! line.
* io.c (rb_io_s_sysopen): new method to get a raw file descriptor. [new] * ext/socket/socket.c (tcp_sysaccept): new method to return an accepted socket fd (integer). [new] * ext/socket/socket.c (unix_sysaccept,sock_sysaccept): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--doc/NEWS8
-rw-r--r--ext/socket/socket.c45
-rw-r--r--io.c30
-rw-r--r--misc/ruby-mode.el12
-rw-r--r--ruby.c14
-rw-r--r--version.h4
7 files changed, 109 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index a133156..3f43f74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Thu May 23 09:13:56 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ruby.c (proc_options): removed "-*-" support for #! line.
+
+ * io.c (rb_io_s_sysopen): new method to get a raw file
+ descriptor. [new]
+
+ * ext/socket/socket.c (tcp_sysaccept): new method to return an
+ accepted socket fd (integer). [new]
+
+ * ext/socket/socket.c (unix_sysaccept,sock_sysaccept): ditto.
+
Wed May 22 21:26:47 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* ruby.c (proc_options): -T consumes digits only.
diff --git a/doc/NEWS b/doc/NEWS
index 972f3ac..06552b9 100644
--- a/doc/NEWS
+++ b/doc/NEWS
@@ -1,3 +1,11 @@
+: IO::sysopen
+
+ a new method to get a raw file descriptor.
+
+: TCPServer#accept, UNIXServer#accept, Socket#accept
+
+ new methods to return an accepted socket fd.
+
: Date and DateTime
lib/date.rb now provides both Date and DateTime.
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 8373ce3..f4b59f4 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1134,6 +1134,7 @@ s_accept(klass, fd, sockaddr, len)
}
rb_sys_fail(0);
}
+ if (!klass) return INT2NUM(fd2);
return init_sock(rb_obj_alloc(klass), fd2);
}
@@ -1151,6 +1152,19 @@ tcp_accept(sock)
(struct sockaddr*)&from, &fromlen);
}
+static VALUE
+tcp_sysaccept(sock)
+ VALUE sock;
+{
+ OpenFile *fptr;
+ struct sockaddr_storage from;
+ socklen_t fromlen;
+
+ GetOpenFile(sock, fptr);
+ fromlen = sizeof(from);
+ return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
+}
+
#ifdef HAVE_SYS_UN_H
static VALUE
init_unixsock(sock, path, server)
@@ -1575,6 +1589,19 @@ unix_accept(sock)
}
static VALUE
+unix_sysaccept(sock)
+ VALUE sock;
+{
+ OpenFile *fptr;
+ struct sockaddr_un from;
+ socklen_t fromlen;
+
+ GetOpenFile(sock, fptr);
+ fromlen = sizeof(struct sockaddr_un);
+ return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
+}
+
+static VALUE
unixaddr(sockaddr)
struct sockaddr_un *sockaddr;
{
@@ -1836,6 +1863,21 @@ sock_accept(sock)
return rb_assoc_new(sock2, rb_tainted_str_new(buf, len));
}
+static VALUE
+sock_sysaccept(sock)
+ VALUE sock;
+{
+ OpenFile *fptr;
+ VALUE sock2;
+ char buf[1024];
+ socklen_t len = sizeof buf;
+
+ GetOpenFile(sock, fptr);
+ sock2 = s_accept(0,fileno(fptr->f),(struct sockaddr*)buf,&len);
+
+ return rb_assoc_new(sock2, rb_tainted_str_new(buf, len));
+}
+
#ifdef HAVE_GETHOSTNAME
static VALUE
sock_gethostname(obj)
@@ -2322,6 +2364,7 @@ Init_socket()
rb_cTCPServer = rb_define_class("TCPServer", rb_cTCPSocket);
rb_define_global_const("TCPserver", rb_cTCPServer);
rb_define_method(rb_cTCPServer, "accept", tcp_accept, 0);
+ rb_define_method(rb_cTCPServer, "sysaccept", tcp_sysaccept, 0);
rb_define_method(rb_cTCPServer, "initialize", tcp_svr_init, -1);
rb_define_method(rb_cTCPServer, "listen", sock_listen, 1);
@@ -2349,6 +2392,7 @@ Init_socket()
rb_define_global_const("UNIXserver", rb_cUNIXServer);
rb_define_method(rb_cUNIXServer, "initialize", unix_svr_init, 1);
rb_define_method(rb_cUNIXServer, "accept", unix_accept, 0);
+ rb_define_method(rb_cUNIXServer, "sysaccept", unix_sysaccept, 0);
rb_define_method(rb_cUNIXServer, "listen", sock_listen, 1);
#endif
@@ -2359,6 +2403,7 @@ Init_socket()
rb_define_method(rb_cSocket, "bind", sock_bind, 1);
rb_define_method(rb_cSocket, "listen", sock_listen, 1);
rb_define_method(rb_cSocket, "accept", sock_accept, 0);
+ rb_define_method(rb_cSocket, "sysaccept", sock_sysaccept, 0);
rb_define_method(rb_cSocket, "recvfrom", sock_recvfrom, -1);
diff --git a/io.c b/io.c
index 14203f0..8dff71b 100644
--- a/io.c
+++ b/io.c
@@ -1966,7 +1966,7 @@ rb_open_file(argc, argv, io)
VALUE *argv;
VALUE io;
{
- VALUE fname, vmode, file, perm;
+ VALUE fname, vmode, perm;
char *path, *mode;
int flags, fmode;
@@ -1978,11 +1978,11 @@ rb_open_file(argc, argv, io)
flags = FIXNUM_P(vmode) ? NUM2INT(vmode) : rb_io_mode_modenum(StringValuePtr(vmode));
fmode = NIL_P(perm) ? 0666 : NUM2INT(perm);
- file = rb_file_sysopen_internal(io, path, flags, fmode);
+ rb_file_sysopen_internal(io, path, flags, fmode);
}
else {
mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode);
- file = rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
+ rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
}
return io;
}
@@ -2003,6 +2003,29 @@ rb_io_s_open(argc, argv, klass)
}
static VALUE
+rb_io_s_sysopen(argc, argv)
+ int argc;
+ VALUE *argv;
+{
+ VALUE fname, vmode, perm;
+ int flags, fmode, fd;
+
+ rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
+ SafeStringValue(fname);
+
+ if (NIL_P(vmode)) flags = O_RDONLY;
+ else if (FIXNUM_P(vmode)) flags = NUM2INT(vmode);
+ else {
+ flags = rb_io_mode_modenum(StringValuePtr(vmode));
+ }
+ if (NIL_P(perm)) fmode = 0666;
+ else fmode = NUM2INT(perm);
+
+ fd = rb_sysopen(RSTRING(fname)->ptr, flags, fmode);
+ return INT2NUM(fd);
+}
+
+static VALUE
rb_f_open(argc, argv)
int argc;
VALUE *argv;
@@ -3706,6 +3729,7 @@ Init_IO()
rb_define_singleton_method(rb_cIO, "allocate", rb_io_s_alloc, 0);
rb_define_singleton_method(rb_cIO, "new", rb_io_s_new, -1);
rb_define_singleton_method(rb_cIO, "open", rb_io_s_open, -1);
+ rb_define_singleton_method(rb_cIO, "sysopen", rb_io_s_sysopen, -1);
rb_define_singleton_method(rb_cIO, "for_fd", rb_class_new_instance, -1);
rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1);
rb_define_singleton_method(rb_cIO, "foreach", rb_io_s_foreach, -1);
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index 13571de..6750035 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -781,9 +781,10 @@ An end of a defun is found by moving forward from the beginning of one."
'(lambda ()
(make-local-variable 'font-lock-defaults)
(make-local-variable 'font-lock-keywords)
- (make-local-variable 'font-lock-syntactic-keywords)
+ (make-local-variable 'font-lock-syntax-table)
(setq font-lock-defaults '((ruby-font-lock-keywords) nil nil))
(setq font-lock-keywords ruby-font-lock-keywords)
+ (setq font-lock-syntax-table ruby-font-lock-syntax-table)
(setq font-lock-syntactic-keywords ruby-font-lock-syntactic-keywords)))))
(defun ruby-font-lock-docs (limit)
@@ -812,6 +813,11 @@ An end of a defun is found by moving forward from the beginning of one."
t)
nil)))
+ (defvar ruby-font-lock-syntax-table
+ (let* ((tbl (copy-syntax-table ruby-mode-syntax-table)))
+ (modify-syntax-entry ?_ "w" tbl)
+ tbl))
+
(defvar ruby-font-lock-keywords
(list
(cons (concat
@@ -855,10 +861,10 @@ An end of a defun is found by moving forward from the beginning of one."
"yield"
)
"\\|")
- "\\)\\>\\([^_]\\|$\\)")
+ "\\)\\>")
2)
;; variables
- '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\b\\([^_]\\|$\\)"
+ '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\>"
2 font-lock-variable-name-face)
;; variables
'("\\(\\$\\([^a-zA-Z0-9 \n]\\|[0-9]\\)\\)\\W"
diff --git a/ruby.c b/ruby.c
index 55dd7ab..6623095 100644
--- a/ruby.c
+++ b/ruby.c
@@ -561,6 +561,7 @@ proc_options(argc, argv)
s += numlen;
}
rb_set_safe_level(v);
+ s += numlen;
}
goto reswitch;
@@ -572,7 +573,7 @@ proc_options(argc, argv)
ruby_incpush(argv[1]);
argc--,argv++;
}
- break;
+ goto reswitch;
case '0':
{
@@ -624,11 +625,6 @@ proc_options(argc, argv)
}
break;
- case '*':
- case ' ':
- if (s[1] == '-') s+=2;
- break;
-
default:
fprintf(stderr, "%s: invalid option -%c (-h will show valid options)\n",
origargv[0], *s);
@@ -657,10 +653,12 @@ proc_options(argc, argv)
}
else {
while (s && *s) {
- while (ISSPACE(*s)) s++;
if (*s == '-') {
s++;
- if (ISSPACE(*s)) continue;
+ if (ISSPACE(*s)) {
+ do {s++;} while (ISSPACE(*s));
+ continue;
+ }
}
if (!*s) break;
if (!strchr("IdvwrK", *s))
diff --git a/version.h b/version.h
index a61938f..ad9c048 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.2"
-#define RUBY_RELEASE_DATE "2002-05-22"
+#define RUBY_RELEASE_DATE "2002-05-23"
#define RUBY_VERSION_CODE 172
-#define RUBY_RELEASE_CODE 20020522
+#define RUBY_RELEASE_CODE 20020523