Skip to content

Commit 75eee0b

Browse files
author
matz
committed
* ext/socket/socket.c (unix_addr): getsockname(2) may result len = 0.
* ext/socket/socket.c (unix_peeraddr): getpeername(2) may result len = 0. * string.c (rb_str_subpat_set): support function for new argument pattern String#[re,offset] = val. [new] * eval.c (POP_BLOCK): rb_gc_force_recycle() was called too much. Should not be called if SCOPE_DONT_RECYCLE is set. * string.c (rb_str_aref_m): new argument pattern String#[re,offset]. [new] * string.c (rb_str_substr): should return an instance of receiver's class. * string.c (rb_str_succ): ditto. * array.c (rb_ary_subseq): ditto. * array.c (rb_ary_initialize): Array.new([1,2,3]) => [1,2,3]. [new] * string.c (rb_str_reverse): should return an instance of receiver's class. * string.c (rb_str_times): ditto. * array.c (rb_ary_times): ditto * string.c (str_gsub): ditto. * string.c (rb_str_ljust): ditto. * string.c (rb_str_rjust): ditto. * string.c (rb_str_center): ditto. * eval.c (eval): retrieves file, line information from binding. * eval.c (intersect_fds): counts intersecting fds. * eval.c (rb_thread_schedule): only fds requested by each thread count as select_value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 34a3123 commit 75eee0b

File tree

17 files changed

+254
-150
lines changed

17 files changed

+254
-150
lines changed

ChangeLog

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@ Tue Oct 2 08:04:52 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
22

33
* marshal.c (r_object): TYPE_UCLASS check should be inversed.
44

5+
Mon Oct 1 19:18:54 2001 Tanaka Akira <akr@m17n.org>
6+
7+
* ext/socket/socket.c (unix_addr): getsockname(2) may result len = 0.
8+
9+
* ext/socket/socket.c (unix_peeraddr): getpeername(2) may result
10+
len = 0.
11+
12+
Mon Oct 1 09:59:07 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
13+
14+
* string.c (rb_str_subpat_set): support function for new argument
15+
pattern String#[re,offset] = val. [new]
16+
17+
Sat Sep 29 02:30:06 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
18+
19+
* eval.c (POP_BLOCK): rb_gc_force_recycle() was called too much.
20+
Should not be called if SCOPE_DONT_RECYCLE is set.
21+
22+
Wed Sep 26 22:21:52 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
23+
24+
* string.c (rb_str_aref_m): new argument pattern
25+
String#[re,offset]. [new]
26+
527
Wed Sep 26 19:02:39 2001 Guy Decoux <ts@moulon.inra.fr>
628

729
* parse.y: allow 'primary[] = arg'
@@ -11,6 +33,38 @@ Tue Sep 25 10:46:42 2001 Usaku Nakamura <usa@ruby-lang.org>
1133
* win32/win32.c (isInternalCmd): check return value of NtMakeCmdVector
1234
(Tietew <tietew@tietew.net>'s patch).
1335

36+
Mon Sep 24 00:55:06 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
37+
38+
* string.c (rb_str_substr): should return an instance of
39+
receiver's class.
40+
41+
* string.c (rb_str_succ): ditto.
42+
43+
* array.c (rb_ary_subseq): ditto.
44+
45+
* array.c (rb_ary_initialize): Array.new([1,2,3]) => [1,2,3]. [new]
46+
47+
Sat Sep 22 22:16:08 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
48+
49+
* string.c (rb_str_reverse): should return an instance of
50+
receiver's class.
51+
52+
* string.c (rb_str_times): ditto.
53+
54+
* array.c (rb_ary_times): ditto
55+
56+
* string.c (str_gsub): ditto.
57+
58+
* string.c (rb_str_ljust): ditto.
59+
60+
* string.c (rb_str_rjust): ditto.
61+
62+
* string.c (rb_str_center): ditto.
63+
64+
Sat Sep 22 12:13:39 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
65+
66+
* eval.c (eval): retrieves file, line information from binding.
67+
1468
Thu Sep 20 21:25:00 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
1569

1670
* eval.c (MATCH_DATA): access via rb_svar().
@@ -52,7 +106,7 @@ Thu Sep 20 15:20:00 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
52106

53107
Tue Sep 18 11:44:26 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
54108

55-
* string.c (rb_str_init): String.new() => ""
109+
* string.c (rb_str_init): String.new() => "" [new]
56110

57111
Tue Sep 11 20:53:56 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
58112

@@ -250,6 +304,13 @@ Wed Aug 22 23:20:03 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
250304

251305
* hash.c (rb_hash_equal): check identiry equality first.
252306

307+
Wed Aug 22 19:58:59 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
308+
309+
* eval.c (intersect_fds): counts intersecting fds.
310+
311+
* eval.c (rb_thread_schedule): only fds requested by
312+
each thread count as select_value.
313+
253314
Tue Aug 21 22:28:09 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
254315

255316
* file.c (group_member): should check real gid only.

ToDo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Language Spec.
2929
* resumable Exception via Exception#resume.
3030
* method combination, e.g. before, after, around, etc.
3131
* .. or something like defadvice in Emacs.
32+
* Class#allocate - basicNew
3233

3334
Hacking Interpreter
3435

@@ -105,6 +106,7 @@ Ruby Libraries
105106
Tools
106107

107108
* freeze or undump to bundle everything
109+
* bundle using zlib
108110

109111
Misc
110112

array.c

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ rb_ary_s_new(argc, argv, klass)
178178
return ary;
179179
}
180180

181+
static VALUE
182+
to_ary(ary)
183+
VALUE ary;
184+
{
185+
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
186+
}
187+
188+
static VALUE
189+
to_ary_failed(failed)
190+
int *failed;
191+
{
192+
*failed = Qtrue;
193+
}
194+
195+
static VALUE rb_ary_replace _((VALUE, VALUE));
196+
181197
static VALUE
182198
rb_ary_initialize(argc, argv, ary)
183199
int argc;
@@ -187,11 +203,17 @@ rb_ary_initialize(argc, argv, ary)
187203
long len;
188204
VALUE size, val;
189205

206+
rb_ary_modify(ary);
190207
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
208+
RARRAY(ary)->len = 0;
209+
return ary;
210+
}
211+
212+
if (argc == 1 && !FIXNUM_P(size) && rb_respond_to(size, rb_intern("to_ary"))) {
213+
rb_ary_replace(ary, rb_convert_type(size, T_ARRAY, "Array", "to_ary"));
191214
return ary;
192215
}
193216

194-
rb_ary_modify(ary);
195217
len = NUM2LONG(size);
196218
if (len < 0) {
197219
rb_raise(rb_eArgError, "negative array size");
@@ -409,6 +431,7 @@ rb_ary_subseq(ary, beg, len)
409431
ary2 = rb_ary_new2(len);
410432
MEMCPY(RARRAY(ary2)->ptr, RARRAY(ary)->ptr+beg, VALUE, len);
411433
RARRAY(ary2)->len = len;
434+
RBASIC(ary2)->klass = rb_obj_class(ary);
412435

413436
return ary2;
414437
}
@@ -544,6 +567,20 @@ rb_ary_indexes(argc, argv, ary)
544567
return new_ary;
545568
}
546569

570+
VALUE
571+
rb_ary_to_ary(obj)
572+
VALUE obj;
573+
{
574+
if (NIL_P(obj)) return rb_ary_new2(0);
575+
if (TYPE(obj) == T_ARRAY) {
576+
return obj;
577+
}
578+
if (rb_respond_to(obj, rb_intern("to_ary"))) {
579+
return rb_convert_type(obj, T_ARRAY, "Array", "to_ary");
580+
}
581+
return rb_ary_new3(1, obj);
582+
}
583+
547584
static void
548585
rb_ary_update(ary, beg, len, rpl)
549586
VALUE ary;
@@ -552,12 +589,7 @@ rb_ary_update(ary, beg, len, rpl)
552589
{
553590
long rlen;
554591

555-
if (NIL_P(rpl)) {
556-
rpl = rb_ary_new2(0);
557-
}
558-
else if (TYPE(rpl) != T_ARRAY) {
559-
rpl = rb_ary_new3(1, rpl);
560-
}
592+
rpl = rb_ary_to_ary(rpl);
561593
rlen = RARRAY(rpl)->len;
562594

563595
if (len < 0) rb_raise(rb_eIndexError, "negative length %d", len);
@@ -739,27 +771,6 @@ rb_ary_dup(ary)
739771
return dup;
740772
}
741773

742-
static VALUE
743-
to_ary(ary)
744-
VALUE ary;
745-
{
746-
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
747-
}
748-
749-
VALUE
750-
rb_ary_to_ary(obj)
751-
VALUE obj;
752-
{
753-
if (NIL_P(obj)) return rb_ary_new2(0);
754-
if (TYPE(obj) == T_ARRAY) {
755-
return obj;
756-
}
757-
if (rb_respond_to(obj, rb_intern("to_ary"))) {
758-
return rb_convert_type(obj, T_ARRAY, "Array", "to_ary");
759-
}
760-
return rb_ary_new3(1, obj);
761-
}
762-
763774
extern VALUE rb_output_fs;
764775

765776
static VALUE
@@ -1342,6 +1353,8 @@ rb_ary_times(ary, times)
13421353
for (i=0; i<len; i+=RARRAY(ary)->len) {
13431354
MEMCPY(RARRAY(ary2)->ptr+i, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
13441355
}
1356+
OBJ_INFECT(ary2, ary);
1357+
RBASIC(ary2)->klass = rb_obj_class(ary);
13451358

13461359
return ary2;
13471360
}

configure.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ if test "$with_dln_a_out" != yes; then
635635
LDFLAGS=""
636636
DLDFLAGS="$ARCH_FLAG"
637637
rb_cv_dlopen=yes ;;
638-
darwin*) LDSHARED='cc -dynamic -bundle -undefined suppress'
638+
darwin*) LDSHARED='cc -dynamic -bundle -undefined suppress -flat_namespace'
639639
LDFLAGS=""
640640
DLDFLAGS="$ARCH_FLAG"
641641
rb_cv_dlopen=yes ;;
@@ -921,7 +921,7 @@ if test "$enable_shared" = 'yes'; then
921921
;;
922922
darwin*)
923923
LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).$(MAJOR).$(MINOR).$(TEENY).dylib'
924-
LIBRUBY_LDSHARED='cc -dynamiclib -undefined suppress'
924+
LIBRUBY_LDSHARED='cc -dynamiclib -undefined suppress -flat_namespace'
925925
LIBRUBY_DLDFLAGS='-install_name lib$(RUBY_INSTALL_NAME).dylib -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(MAJOR).$(MINOR)'
926926
LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_INSTALL_NAME).dylib'
927927
;;

eval.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -585,15 +585,11 @@ new_blktag()
585585
_block.wrapper = ruby_wrapper; \
586586
ruby_block = &_block;
587587

588-
#define POP_BLOCK_TAG(tag) do { \
589-
if ((tag)->flags & BLOCK_DYNAMIC) \
590-
(tag)->flags |= BLOCK_ORPHAN; \
591-
else \
592-
rb_gc_force_recycle((VALUE)tag); \
593-
} while (0)
594-
595588
#define POP_BLOCK() \
596-
POP_BLOCK_TAG(_block.tag); \
589+
if (_block.tag->flags & (BLOCK_DYNAMIC)) \
590+
_block.tag->flags |= BLOCK_ORPHAN; \
591+
else if (!(_block.scope->flags & SCOPE_DONT_RECYCLE)) \
592+
rb_gc_force_recycle((VALUE)_block.tag); \
597593
ruby_block = _block.prev; \
598594
}
599595

@@ -4631,7 +4627,8 @@ rb_call(klass, recv, mid, argc, argv, scope)
46314627
struct cache_entry *ent;
46324628

46334629
if (!klass) {
4634-
rb_raise(rb_eNotImpError, "method call on terminated object");
4630+
rb_raise(rb_eNotImpError, "method `%s' called on terminated object (0x%x)",
4631+
rb_id2name(mid), recv);
46354632
}
46364633
/* is it in the method cache? */
46374634
ent = cache + EXPR1(klass, mid);
@@ -4909,10 +4906,6 @@ eval(self, src, scope, file, line)
49094906
volatile int iter = ruby_frame->iter;
49104907
int state;
49114908

4912-
if (file == 0) {
4913-
file = ruby_sourcefile;
4914-
line = ruby_sourceline;
4915-
}
49164909
if (!NIL_P(scope)) {
49174910
if (!rb_obj_is_block(scope)) {
49184911
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Binding)",
@@ -4936,6 +4929,11 @@ eval(self, src, scope, file, line)
49364929
ruby_cref = (NODE*)ruby_frame->cbase;
49374930
old_wrapper = ruby_wrapper;
49384931
ruby_wrapper = data->wrapper;
4932+
if ((file == 0 || (line == 1 && strcmp(file, "(eval)") == 0)) &&
4933+
data->body && data->body->nd_file) {
4934+
file = data->body->nd_file;
4935+
line = nd_line(data->body);
4936+
}
49394937

49404938
self = data->self;
49414939
ruby_frame->iter = data->iter;
@@ -4945,6 +4943,10 @@ eval(self, src, scope, file, line)
49454943
ruby_frame->iter = ruby_frame->prev->iter;
49464944
}
49474945
}
4946+
if (file == 0) {
4947+
file = ruby_sourcefile;
4948+
line = ruby_sourceline;
4949+
}
49484950
PUSH_CLASS();
49494951
ruby_class = ruby_cbase;
49504952

@@ -7520,24 +7522,26 @@ match_fds(dst, src, max)
75207522
return Qfalse;
75217523
}
75227524

7523-
static void
7525+
static int
75247526
intersect_fds(src, dst, max)
75257527
fd_set *src, *dst;
75267528
int max;
75277529
{
7528-
int i;
7530+
int i, n = 0;
75297531

75307532
for (i=0; i<=max; i++) {
75317533
if (FD_ISSET(i, dst)) {
75327534
if (FD_ISSET(i, src)) {
75337535
/* Wake up only one thread per fd. */
75347536
FD_CLR(i, src);
7537+
++n;
75357538
}
75367539
else {
75377540
FD_CLR(i, dst);
75387541
}
75397542
}
75407543
}
7544+
return n;
75417545
}
75427546

75437547
static int
@@ -7693,9 +7697,9 @@ rb_thread_schedule()
76937697
/* Wake up only one thread per fd. */
76947698
th->status = THREAD_RUNNABLE;
76957699
th->wait_for = 0;
7696-
intersect_fds(&readfds, &th->readfds, max);
7697-
intersect_fds(&writefds, &th->writefds, max);
7698-
intersect_fds(&exceptfds, &th->exceptfds, max);
7700+
n = intersect_fds(&readfds, &th->readfds, max) +
7701+
intersect_fds(&writefds, &th->writefds, max) +
7702+
intersect_fds(&exceptfds, &th->exceptfds, max);
76997703
th->select_value = n;
77007704
found = 1;
77017705
}

ext/socket/getnameinfo.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
180180
/* what we should do? */
181181
} else if (flags & NI_NUMERICSERV) {
182182
snprintf(numserv, sizeof(numserv), "%d", ntohs(port));
183-
if (strlen(numserv) > servlen)
183+
if (strlen(numserv) + 1 > servlen)
184184
return ENI_MEMORY;
185185
strcpy(serv, numserv);
186186
} else {
187187
#if defined(HAVE_GETSERVBYPORT)
188188
sp = getservbyport(port, (flags & NI_DGRAM) ? "udp" : "tcp");
189189
if (sp) {
190-
if (strlen(sp->s_name) > servlen)
190+
if (strlen(sp->s_name) + 1 > servlen)
191191
return ENI_MEMORY;
192192
strcpy(serv, sp->s_name);
193193
} else
@@ -199,11 +199,11 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
199199

200200
switch (sa->sa_family) {
201201
case AF_INET:
202-
v4a = ((struct sockaddr_in *)sa)->sin_addr.s_addr;
202+
v4a = ntohl(((struct sockaddr_in *)sa)->sin_addr.s_addr);
203203
if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a))
204204
flags |= NI_NUMERICHOST;
205205
v4a >>= IN_CLASSA_NSHIFT;
206-
if (v4a == 0 || v4a == IN_LOOPBACKNET)
206+
if (v4a == 0)
207207
flags |= NI_NUMERICHOST;
208208
break;
209209
#ifdef INET6
@@ -236,7 +236,7 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
236236
p = strchr(hp->h_name, '.');
237237
if (p) *p = '\0';
238238
}
239-
if (strlen(hp->h_name) > hostlen) {
239+
if (strlen(hp->h_name) + 1 > hostlen) {
240240
#ifdef INET6
241241
freehostent(hp);
242242
#endif

0 commit comments

Comments
 (0)