8000 matz · jruby/ruby@2322a13 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2322a13

Browse files
author
matz
committed
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent a721bd6 commit 2322a13

File tree

14 files changed

+95
-50
lines changed

14 files changed

+95
-50
lines changed

ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Fri Dec 8 10:44:05 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
2+
3+
* variable.c (rb_mod_remove_cvar): Module#remove_class_variable
4+
added.
5+
16
Thu Dec 7 17:35:51 2000 Shugo Maeda <shugo@ruby-lang.org>
27

38
* eval.c (stack_length): don't use __builtin_frame_address() on alpha.
@@ -8,6 +13,17 @@ Wed Dec 6 18:07:13 2000 WATANABE Hirofumi <eban@ruby-lang.org>
813

914
* eval.c (rb_mod_define_method): avoid VC4.0 warnings.
1015

16+
Wed Dec 6 13:38:08 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
17+
18+
* array.c (rb_ary_and): tuning, make hash from shorter operand.
1 10000 9+
20+
Wed Dec 6 01:28:50 2000 SHIROYAMA Takayuki <psi@fortune.nest.or.jp>
21+
22+
* gc.c (rb_gc): __builtin_frame_address() should not be used on
23+
MacOS X.
24+
25+
* gc.c (Init_stack): ditto.
26+
1127
Mon Dec 4 13:44:01 2000 WATANABE Hirofumi <eban@ruby-lang.org>
1228

1329
* lib/jcode.rb: consider multibyte. not /n.

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ win32.@OBJEXT@: $(srcdir)/win32/win32.c
237237
###
238238
parse.@OBJEXT@: parse.y ruby.h config.h defines.h intern.h env.h node.h st.h regex.h util.h lex.c
239239
###
240-
array.@OBJEXT@: array.c ruby.h config.h defines.h intern.h
240+
array.@OBJEXT@: array.c ruby.h config.h defines.h intern.h st.h
241241
bignum.@OBJEXT@: bignum.c ruby.h config.h defines.h intern.h
242242
class.@OBJEXT@: class.c ruby.h config.h defines.h intern.h node.h st.h
243243
compar.@OBJEXT@: compar.c ruby.h config.h defines.h intern.h

ToDo

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ Standard Libraries
9494
* Process::waitall [ruby-talk:4557]
9595
* synchronized method - synchronized{...}, synchronized :foo, :bar
9696
* move Time::times to Process.
97-
* Module#define_method which takes a name and a body (block, proc or method).
97+
- Module#define_method which takes a name and a body (block, proc or method).
98+
* IO#for_fd in general
99+
* Array#&, Array#| to allow duplication. ???
100+
- fork_and_kill_other_threads.
101+
* way to specify immortal (fork endurance) thread.
98102

99103
Extension Libraries
100104

array.c

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,49 +1436,45 @@ rb_ary_diff(ary1, ary2)
14361436
return ary3;
14371437
}
14381438

1439-
static st_table*
1439+
static VALUE
14401440
ary_make_hash(ary1, ary2, func)
14411441
VALUE ary1, ary2;
14421442
int (*func)();
14431443
{
1444-
st_table *tbl = st_init_numtable();
1444+
VALUE hash = rb_hash_new();
14451445
int i, n;
14461446

14471447
for (i=0; i<RARRAY(ary1)->len; i++) {
1448-
if (!st_lookup(tbl, RARRAY(ary1)->ptr[i], &n)) {
1449-
st_add_direct(tbl, RARRAY(ary1)->ptr[i], 0);
1450-
}
1448+
rb_hash_aset(hash, RARRAY(ary1)->ptr[i], Qtrue);
14511449
}
14521450
if (ary2) {
14531451
for (i=0; i<RARRAY(ary2)->len; i++) {
1454-
if (st_lookup(tbl, RARRAY(ary2)->ptr[i], &n)) {
1455-
st_insert(tbl, RARRAY(ary2)->ptr[i], 2);
1456-
}
1457-
else {
1458-
st_add_direct(tbl, RARRAY(ary2)->ptr[i], 1);
1459-
}
1452+
rb_hash_aset(hash, RARRAY(ary2)->ptr[i], Qtrue);
14601453
}
14611454
}
1462-
return tbl;
1455+
return hash;
14631456
}
14641457

14651458
static VALUE
14661459
rb_ary_and(ary1, ary2)
14671460
VALUE ary1, ary2;
14681461
{
1469-
st_table *tbl = ary_make_hash(ary1, to_ary(ary2));
1462+
VALUE hash;
14701463
VALUE ary3 = rb_ary_new();
1471-
VALUE v;
14721464
long i;
1473-
int n;
1465+
1466+
ary2 = to_ary(ary2);
1467+
if (RARRAY(ary1)->len < RARRAY(ary2)->len) { /* swap */
1468+
VALUE tmp = ary1; ary1 = ary2; ary2 = tmp;
1469+
}
1470+
hash = ary_make_hash(ary2, 0);
14741471

14751472
for (i=0; i<RARRAY(ary1)->len; i++) {
1476-
v = RARRAY(ary1)->ptr[i];
1477-
if (st_delete(tbl, &v, &n)) {
1478-
if (n == 2) rb_ary_push(ary3, v);
1473+
VALUE v = RARRAY(ary1)->ptr[i];
1474+
if (st_delete(RHASH(hash)->tbl, &v, 0)) {
1475+
rb_ary_push(ary3, v);
14791476
}
14801477
}
1481-
st_free_table(tbl);
14821478

14831479
return ary3;
14841480
}
@@ -1487,27 +1483,26 @@ static VALUE
14871483
rb_ary_or(ary1, ary2)
14881484
VALUE ary1, ary2;
14891485
{
1490-
st_table *tbl;
1486+
VALUE hash;
14911487
VALUE ary3 = rb_ary_new();
14921488
VALUE v;
14931489
long i;
14941490

14951491
ary2 = to_ary(ary2);
1496-
tbl = ary_make_hash(ary1, ary2);
1492+
hash = ary_make_hash(ary1, ary2);
14971493

14981494
for (i=0; i<RARRAY(ary1)->len; i++) {
14991495
v = RARRAY(ary1)->ptr[i];
1500-
if (st_delete(tbl, &v, 0)) {
1496+
if (st_delete(RHASH(hash)->tbl, &v, 0)) {
15011497
rb_ary_push(ary3, v);
15021498
}
15031499
}
15041500
for (i=0; i<RARRAY(ary2)->len; i++) {
15051501
v = RARRAY(ary2)->ptr[i];
1506-
if (st_delete(tbl, &v, 0)) {
1502+
if (st_delete(RHASH(hash)->tbl, &v, 0)) {
15071503
rb_ary_push(ary3, v);
15081504
}
15091505
}
1510-
st_free_table(tbl);
15111506

15121507
return ary3;
15131508
}
@@ -1516,21 +1511,19 @@ static VALUE
15161511
rb_ary_uniq_bang(ary)
15171512
VALUE ary;
15181513
{
1519-
st_table *tbl = ary_make_hash(ary, 0);
1514+
VALUE hash = ary_make_hash(ary, 0);
15201515
VALUE *p, *q, *end;
1521-
VALUE v;
15221516

1523-
if (RARRAY(ary)->len == tbl->num_entries) {
1524-
st_free_table(tbl);
1517+
if (RARRAY(ary)->len == RHASH(hash)->tbl->num_entries) {
15251518
return Qnil;
15261519
}
1527-
rb_ary_modify(ary);
15281520

1521+
rb_ary_modify(ary);
15291522
p = q = RARRAY(ary)->ptr;
15301523
end = p + RARRAY(ary)->len;
15311524
while (p < end) {
1532-
v = *p++;
1533-
if (st_delete(tbl, &v, 0)) {
1525+
VALUE v = *p++;
1526+
if (st_delete(RHASH(hash)->tbl, &v, 0)) {
15341527
*q++ = v;
15351528
}
15361529
}

eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4037,7 +4037,7 @@ stack_length(p)
40374037
alloca(0);
40384038
# define STACK_END (&stack_end)
40394039
#else
4040-
# if defined(__GNUC__) && !defined(__alpha__)
4040+
# if defined(__GNUC__) && !defined(__alpha__) && !defined(__APPLE__)
40414041
VALUE *stack_end = __builtin_frame_address(0);
40424042
# else
40434043
VALUE *stack_end = alloca(1);

gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ rb_gc()
925925
alloca(0);
926926
# define STACK_END (&stack_end)
927927
#else
928-
# if defined(__GNUC__) && !defined(__alpha__)
928+
# if defined(__GNUC__) && !defined(__alpha__) && !defined(__APPLE__)
929929
VALUE *stack_end = __builtin_frame_address(0);
930930
# else
931931
VALUE *stack_end = alloca(1);
@@ -1005,7 +1005,7 @@ Init_stack(addr)
10051005
#if defined(__human68k__)
10061006
extern void *_SEND;
10071007
rb_gc_stack_start = _SEND;
1008-
#elif defined(__GNUC__) && !defined(__alpha__)
1008+
#elif defined(__GNUC__) && !defined(__alpha__) && !defined(__APPLE__)
10091009
rb_gc_stack_start = __builtin_frame_address(2);
10101010
#else
10111011
VALUE start;

intern.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,12 @@ void rb_const_assign _((VALUE, ID, VALUE));
371371
VALUE rb_mod_constants _((VALUE));
372372
void rb_autoload_load _((ID));
373373
void rb_cvar_declare _((VALUE, ID, VALUE));
374-
int rb_cvar_defined _((VALUE, ID));
374+
VALUE rb_cvar_defined _((VALUE, ID));
375375
void rb_cvar_set _((VALUE, ID, VALUE));
376376
VALUE rb_cvar_get _((VALUE, ID));
377377
VALUE rb_cvar_singleton _((VALUE));
378378
VALUE rb_mod_class_variables _((VALUE));
379+
VALUE rb_mod_remove_cvar _((VALUE, VALUE));
379380
/* version.c */
380381
void ruby_show_version _((void));
381382
void ruby_show_copyright _((void));

lib/tempfile.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def Tempfile.callback(path, data)
2929
end
3030

3131
def initialize(basename, tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp')
32+
if $SAFE > 0 and tmpdir.tainted?
33+
tmpdir = '/tmp'
34+
end
3235
umask = File.umask(0177)
3336
begin
3437
n = 0

object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ Init_Object()
12031203
rb_define_private_method(rb_cModule, "remove_const", rb_mod_remove_const, 1);
12041204
rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1);
12051205
rb_define_method(rb_cModule, "class_variables", rb_mod_class_variables, 0);
1206+
rb_define_private_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1);
12061207

12071208
rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
12081209
rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);

variable.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,33 +1225,34 @@ rb_const_defined(klass, id)
12251225
}
12261226

12271227
static void
1228-
mod_av_set(klass, id, val, dest, once)
1228+
mod_av_set(klass, id, val, isconst)
12291229
VALUE klass;
12301230
ID id;
12311231
VALUE val;
1232-
char *dest;
1233-
int once;
1232+
int isconst;
12341233
{
1234+
char *dest = isconst ? "constant" : "class variable";
1235+
12351236
if (!OBJ_TAINTED(klass) && rb_safe_level() >= 4)
12361237
rb_raise(rb_eSecurityError, "Insecure: can't set %s", dest);
12371238
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
12381239
if (!RCLASS(klass)->iv_tbl) {
12391240
RCLASS(klass)->iv_tbl = st_init_numtable();
12401241
}
1241-
else if (once && st_lookup(RCLASS(klass)->iv_tbl, id, 0)) {
1242+
else if (isconst && st_lookup(RCLASS(klass)->iv_tbl, id, 0)) {
12421243
rb_warn("already initialized %s %s", dest, rb_id2name(id));
12431244
}
12441245

12451246
st_insert(RCLASS(klass)->iv_tbl, id, val);
12461247
}
1247-
1248+
12481249
void
12491250
rb_const_set(klass, id, val)
12501251
VALUE klass;
12511252
ID id;
12521253
VALUE val;
12531254
{
1254-
mod_av_set(klass, id, val, "constant", Qtrue);
1255+
mod_av_set(klass, id, val, Qtrue);
12551256
}
12561257

12571258
void
@@ -1377,7 +1378,7 @@ rb_cvar_declare(klass, id, val)
13771378
tmp = RCLASS(tmp)->super;
13781379
}
13791380

1380-
mod_av_set(klass, id, val, "class variable", Qfalse);
1381+
mod_av_set(klass, id, val, Qfalse);
13811382
}
13821383

13831384
VALUE
@@ -1401,7 +1402,7 @@ rb_cvar_get(klass, id)
14011402
return Qnil; /* not reached */
14021403
}
14031404

1404-
int
1405+
VALUE
14051406
rb_cvar_defined(klass, id)
14061407
VALUE klass;
14071408
ID id;
@@ -1485,6 +1486,32 @@ rb_mod_class_variables(obj)
14851486
return ary;
14861487
}
14871488

1489+
VALUE
1490+
rb_mod_remove_cvar(mod, name)
1491+
VALUE mod, name;
1492+
{
1493+
ID id = rb_to_id(name);
1494+
VALUE val;
1495+
1496+
if (!rb_is_class_id(id)) {
1497+
rb_raise(rb_eNameError, "wrong class variable name %s", name);
1498+
}
1499+
if (!OBJ_TAINTED(mod) && rb_safe_level() >= 4)
1500+
rb_raise(rb_eSecurityError, "Insecure: can't remove class variable");
1501+
if (OBJ_FROZEN(mod)) rb_error_frozen("class/module");
1502+
1503+
if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, &id, &val)) {
1504+
return val;
1505+
}
1506+
if (rb_cvar_defined(mod, id)) {
1507+
rb_raise(rb_eNameError, "cannot remove %s for %s",
1508+
rb_id2name(id), rb_class2name(mod));
1509+
}
1510+
rb_raise(rb_eNameError, "class variable %s not defined for %s",
1511+
rb_id2name(id), rb_class2name(mod));
1512+
return Qnil; /* not reached */
1513+
}
1514+
14881515
VALUE
14891516
rb_iv_get(obj, name)
14901517
VALUE obj;

0 commit comments

Comments
 (0)
0