Skip to content

Commit 6e87a54

Browse files
author
matz
committed
* 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
1 parent 730d8f1 commit 6e87a54

File tree

7 files changed

+109
-16
lines changed

7 files changed

+109
-16
lines changed

ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
Thu May 23 09:13:56 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
2+
3+
* ruby.c (proc_options): removed "-*-" support for #! line.
4+
5+
* io.c (rb_io_s_sysopen): new method to get a raw file
6+
descriptor. [new]
7+
8+
* ext/socket/socket.c (tcp_sysaccept): new method to return an
9+
accepted socket fd (integer). [new]
10+
11+
* ext/socket/socket.c (unix_sysaccept,sock_sysaccept): ditto.
12+
113
Wed May 22 21:26:47 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
214

315
* ruby.c (proc_options): -T consumes digits only.

doc/NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
: IO::sysopen
2+
3+
a new method to get a raw file descriptor.
4+
5+
: TCPServer#accept, UNIXServer#accept, Socket#accept
6+
7+
new methods to return an accepted socket fd.
8+
19
: Date and DateTime
210

311
lib/date.rb now provides both Date and DateTime.

ext/socket/socket.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ s_accept(klass, fd, sockaddr, len)
11341134
}
11351135
rb_sys_fail(0);
11361136
}
1137+
if (!klass) return INT2NUM(fd2);
11371138
return init_sock(rb_obj_alloc(klass), fd2);
11381139
}
11391140

@@ -1151,6 +1152,19 @@ tcp_accept(sock)
11511152
(struct sockaddr*)&from, &fromlen);
11521153
}
11531154

1155+
static VALUE
1156+
tcp_sysaccept(sock)
1157+
VALUE sock;
1158+
{
1159+
OpenFile *fptr;
1160+
struct sockaddr_storage from;
1161+
socklen_t fromlen;
1162+
1163+
GetOpenFile(sock, fptr);
1164+
fromlen = sizeof(from);
1165+
return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
1166+
}
1167+
11541168
#ifdef HAVE_SYS_UN_H
11551169
static VALUE
11561170
init_unixsock(sock, path, server)
@@ -1574,6 +1588,19 @@ unix_accept(sock)
15741588
(struct sockaddr*)&from, &fromlen);
15751589
}
15761590

1591+
static VALUE
1592+
unix_sysaccept(sock)
1593+
VALUE sock;
1594+
{
1595+
OpenFile *fptr;
1596+
struct sockaddr_un from;
1597+
socklen_t fromlen;
1598+
1599+
GetOpenFile(sock, fptr);
1600+
fromlen = sizeof(struct sockaddr_un);
1601+
return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
1602+
}
1603+
15771604
static VALUE
15781605
unixaddr(sockaddr)
15791606
struct sockaddr_un *sockaddr;
@@ -1836,6 +1863,21 @@ sock_accept(sock)
18361863
return rb_assoc_new(sock2, rb_tainted_str_new(buf, len));
18371864
}
18381865

1866+
static VALUE
1867+
sock_sysaccept(sock)
1868+
VALUE sock;
1869+
{
1870+
OpenFile *fptr;
1871+
VALUE sock2;
1872+
char buf[1024];
1873+
socklen_t len = sizeof buf;
1874+
1875+
GetOpenFile(sock, fptr);
1876+
sock2 = s_accept(0,fileno(fptr->f),(struct sockaddr*)buf,&len);
1877+
1878+
return rb_assoc_new(sock2, rb_tainted_str_new(buf, len));
1879+
}
1880+
18391881
#ifdef HAVE_GETHOSTNAME
18401882
static VALUE
18411883
sock_gethostname(obj)
@@ -2322,6 +2364,7 @@ Init_socket()
23222364
rb_cTCPServer = rb_define_class("TCPServer", rb_cTCPSocket);
23232365
rb_define_global_const("TCPserver", rb_cTCPServer);
23242366
rb_define_method(rb_cTCPServer, "accept", tcp_accept, 0);
2367+
rb_define_method(rb_cTCPServer, "sysaccept", tcp_sysaccept, 0);
23252368
rb_define_method(rb_cTCPServer, "initialize", tcp_svr_init, -1);
23262369
rb_define_method(rb_cTCPServer, "listen", sock_listen, 1);
23272370

@@ -2349,6 +2392,7 @@ Init_socket()
23492392
rb_define_global_const("UNIXserver", rb_cUNIXServer);
23502393
rb_define_method(rb_cUNIXServer, "initialize", unix_svr_init, 1);
23512394
rb_define_method(rb_cUNIXServer, "accept", unix_accept, 0);
2395+
rb_define_method(rb_cUNIXServer, "sysaccept", unix_sysaccept, 0);
23522396
rb_define_method(rb_cUNIXServer, "listen", sock_listen, 1);
23532397
#endif
23542398

@@ -2359,6 +2403,7 @@ Init_socket()
23592403
rb_define_method(rb_cSocket, "bind", sock_bind, 1);
23602404
rb_define_method(rb_cSocket, "listen", sock_listen, 1);
23612405
rb_define_method(rb_cSocket, "accept", sock_accept, 0);
2406+
rb_define_method(rb_cSocket, "sysaccept", sock_sysaccept, 0);
23622407

23632408
rb_define_method(rb_cSocket, "recvfrom", sock_recvfrom, -1);
23642409

io.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ rb_open_file(argc, argv, io)
19661966
VALUE *argv;
19671967
VALUE io;
19681968
{
1969-
VALUE fname, vmode, file, perm;
1969+
VALUE fname, vmode, perm;
19701970
char *path, *mode;
19711971
int flags, fmode;
19721972

@@ -1978,11 +1978,11 @@ rb_open_file(argc, argv, io)
19781978
flags = FIXNUM_P(vmode) ? NUM2INT(vmode) : rb_io_mode_modenum(StringValuePtr(vmode));
19791979
fmode = NIL_P(perm) ? 0666 : NUM2INT(perm);
19801980

1981-
file = rb_file_sysopen_internal(io, path, flags, fmode);
1981+
rb_file_sysopen_internal(io, path, flags, fmode);
19821982
}
19831983
else {
19841984
mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode);
1985-
file = rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
1985+
rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
19861986
}
19871987
return io;
19881988
}
@@ -2002,6 +2002,29 @@ rb_io_s_open(argc, argv, klass)
20022002
return io;
20032003
}
20042004

2005+
static VALUE
2006+
rb_io_s_sysopen(argc, argv)
2007+
int argc;
2008+
VALUE *argv;
2009+
{
2010+
VALUE fname, vmode, perm;
2011+
int flags, fmode, fd;
2012+
2013+
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
2014+
SafeStringValue(fname);
2015+
2016+
if (NIL_P(vmode)) flags = O_RDONLY;
2017+
else if (FIXNUM_P(vmode)) flags = NUM2INT(vmode);
2018+
else {
2019+
flags = rb_io_mode_modenum(StringValuePtr(vmode));
2020+
}
2021+
if (NIL_P(perm)) fmode = 0666;
2022+
else fmode = NUM2INT(perm);
2023+
2024+
fd = rb_sysopen(RSTRING(fname)->ptr, flags, fmode);
2025+
return INT2NUM(fd);
2026+
}
2027+
20052028
static VALUE
20062029
rb_f_open(argc, argv)
20072030
int argc;
@@ -3706,6 +3729,7 @@ Init_IO()
37063729
rb_define_singleton_method(rb_cIO, "allocate", rb_io_s_alloc, 0);
37073730
rb_define_singleton_method(rb_cIO, "new", rb_io_s_new, -1);
37083731
rb_define_singleton_method(rb_cIO, "open", rb_io_s_open, -1);
3732+
rb_define_singleton_method(rb_cIO, "sysopen", rb_io_s_sysopen, -1);
37093733
rb_define_singleton_method(rb_cIO, "for_fd", rb_class_new_instance, -1);
37103734
rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1);
37113735
rb_define_singleton_method(rb_cIO, "foreach", rb_io_s_foreach, -1);

misc/ruby-mode.el

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,10 @@ An end of a defun is found by moving forward from the beginning of one."
781781
'(lambda ()
782782
(make-local-variable 'font-lock-defaults)
783783
(make-local-variable 'font-lock-keywords)
784-
(make-local-variable 'font-lock-syntactic-keywords)
784+
(make-local-variable 'font-lock-syntax-table)
785785
(setq font-lock-defaults '((ruby-font-lock-keywords) nil nil))
786786
(setq font-lock-keywords ruby-font-lock-keywords)
787+
(setq font-lock-syntax-table ruby-font-lock-syntax-table)
787788
(setq font-lock-syntactic-keywords ruby-font-lock-syntactic-keywords)))))
788789

789790
(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."
812813
t)
813814
nil)))
814815

816+
(defvar ruby-font-lock-syntax-table
817+
(let* ((tbl (copy-syntax-table ruby-mode-syntax-table)))
818+
(modify-syntax-entry ?_ "w" tbl)
819+
tbl))
820+
815821
(defvar ruby-font-lock-keywords
816822
(list
817823
(cons (concat
@@ -855,10 +861,10 @@ An end of a defun is found by moving forward from the beginning of one."
855861
"yield"
856862
)
857863
"\\|")
858-
"\\)\\>\\([^_]\\|$\\)")
864+
"\\)\\>")
859865
2)
860866
;; variables
861-
'("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\b\\([^_]\\|$\\)"
867+
'("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\>"
862868
2 font-lock-variable-name-face)
863869
;; variables
864870
'("\\(\\$\\([^a-zA-Z0-9 \n]\\|[0-9]\\)\\)\\W"

ruby.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ proc_options(argc, argv)
561561
s += numlen;
562562
}
563563
rb_set_safe_level(v);
564+
s += numlen;
564565
}
565566
goto reswitch;
566567

@@ -572,7 +573,7 @@ proc_options(argc, argv)
572573
ruby_incpush(argv[1]);
573574
argc--,argv++;
574575
}
575-
break;
576+
goto reswitch;
576577

577578
case '0':
578579
{
@@ -624,11 +625,6 @@ proc_options(argc, argv)
624625
}
625626
break;
626627

627-
case '*':
628-
case ' ':
629-
if (s[1] == '-') s+=2;
630-
break;
631-
632628
default:
633629
fprintf(stderr, "%s: invalid option -%c (-h will show valid options)\n",
634630
origargv[0], *s);
@@ -657,10 +653,12 @@ proc_options(argc, argv)
657653
}
658654
else {
659655
while (s && *s) {
660-
while (ISSPACE(*s)) s++;
661656
if (*s == '-') {
662657
s++;
663-
if (ISSPACE(*s)) continue;
658+
if (ISSPACE(*s)) {
659+
do {s++;} while (ISSPACE(*s));
660+
continue;
661+
}
664662
}
665663
if (!*s) break;
666664
if (!strchr("IdvwrK", *s))

version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#define RUBY_VERSION "1.7.2"
2-
#define RUBY_RELEASE_DATE "2002-05-22"
2+
#define RUBY_RELEASE_DATE "2002-05-23"
33
#define RUBY_VERSION_CODE 172
4-
#define RUBY_RELEASE_CODE 20020522
4+
#define RUBY_RELEASE_CODE 20020523

0 commit comments

Comments
 (0)