From 2322a131272f705139fb1e6bbcf1d85a0205e8b0 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 8 Dec 2000 07:10:38 +0000 Subject: matz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 16 +++++++++++++++ Makefile.in | 2 +- ToDo | 6 +++++- array.c | 55 ++++++++++++++++++++++---------------------------- eval.c | 2 +- gc.c | 4 ++-- intern.h | 3 ++- lib/tempfile.rb | 3 +++ object.c | 1 + variable.c | 43 +++++++++++++++++++++++++++++++-------- version.h | 4 ++-- win32/Makefile.sub | 2 +- win32/config.status.in | 2 +- win32/win32.c | 2 +- 14 files changed, 95 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb4aeb0bb7..01ae9453a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Dec 8 10:44:05 2000 Yukihiro Matsumoto + + * variable.c (rb_mod_remove_cvar): Module#remove_class_variable + added. + Thu Dec 7 17:35:51 2000 Shugo Maeda * 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 * eval.c (rb_mod_define_method): avoid VC4.0 warnings. +Wed Dec 6 13:38:08 2000 Yukihiro Matsumoto + + * array.c (rb_ary_and): tuning, make hash from shorter operand. + +Wed Dec 6 01:28:50 2000 SHIROYAMA Takayuki + + * gc.c (rb_gc): __builtin_frame_address() should not be used on + MacOS X. + + * gc.c (Init_stack): ditto. + Mon Dec 4 13:44:01 2000 WATANABE Hirofumi * lib/jcode.rb: consider multibyte. not /n. diff --git a/Makefile.in b/Makefile.in index 94ebfb9a8c..34e6dda080 100644 --- a/Makefile.in +++ b/Makefile.in @@ -237,7 +237,7 @@ win32.@OBJEXT@: $(srcdir)/win32/win32.c ### parse.@OBJEXT@: parse.y ruby.h config.h defines.h intern.h env.h node.h st.h regex.h util.h lex.c ### -array.@OBJEXT@: array.c ruby.h config.h defines.h intern.h +array.@OBJEXT@: array.c ruby.h config.h defines.h intern.h st.h bignum.@OBJEXT@: bignum.c ruby.h config.h defines.h intern.h class.@OBJEXT@: class.c ruby.h config.h defines.h intern.h node.h st.h compar.@OBJEXT@: compar.c ruby.h config.h defines.h intern.h diff --git a/ToDo b/ToDo index effc73bf60..0f9b9f55e0 100644 --- a/ToDo +++ b/ToDo @@ -94,7 +94,11 @@ Standard Libraries * Process::waitall [ruby-talk:4557] * synchronized method - synchronized{...}, synchronized :foo, :bar * move Time::times to Process. -* Module#define_method which takes a name and a body (block, proc or method). +- Module#define_method which takes a name and a body (block, proc or method). +* IO#for_fd in general +* Array#&, Array#| to allow duplication. ??? +- fork_and_kill_other_threads. +* way to specify immortal (fork endurance) thread. Extension Libraries diff --git a/array.c b/array.c index 43f523d32f..2794e8dbf9 100644 --- a/array.c +++ b/array.c @@ -1436,49 +1436,45 @@ rb_ary_diff(ary1, ary2) return ary3; } -static st_table* +static VALUE ary_make_hash(ary1, ary2, func) VALUE ary1, ary2; int (*func)(); { - st_table *tbl = st_init_numtable(); + VALUE hash = rb_hash_new(); int i, n; for (i=0; ilen; i++) { - if (!st_lookup(tbl, RARRAY(ary1)->ptr[i], &n)) { - st_add_direct(tbl, RARRAY(ary1)->ptr[i], 0); - } + rb_hash_aset(hash, RARRAY(ary1)->ptr[i], Qtrue); } if (ary2) { for (i=0; ilen; i++) { - if (st_lookup(tbl, RARRAY(ary2)->ptr[i], &n)) { - st_insert(tbl, RARRAY(ary2)->ptr[i], 2); - } - else { - st_add_direct(tbl, RARRAY(ary2)->ptr[i], 1); - } + rb_hash_aset(hash, RARRAY(ary2)->ptr[i], Qtrue); } } - return tbl; + return hash; } static VALUE rb_ary_and(ary1, ary2) VALUE ary1, ary2; { - st_table *tbl = ary_make_hash(ary1, to_ary(ary2)); + VALUE hash; VALUE ary3 = rb_ary_new(); - VALUE v; long i; - int n; + + ary2 = to_ary(ary2); + if (RARRAY(ary1)->len < RARRAY(ary2)->len) { /* swap */ + VALUE tmp = ary1; ary1 = ary2; ary2 = tmp; + } + hash = ary_make_hash(ary2, 0); for (i=0; ilen; i++) { - v = RARRAY(ary1)->ptr[i]; - if (st_delete(tbl, &v, &n)) { - if (n == 2) rb_ary_push(ary3, v); + VALUE v = RARRAY(ary1)->ptr[i]; + if (st_delete(RHASH(hash)->tbl, &v, 0)) { + rb_ary_push(ary3, v); } } - st_free_table(tbl); return ary3; } @@ -1487,27 +1483,26 @@ static VALUE rb_ary_or(ary1, ary2) VALUE ary1, ary2; { - st_table *tbl; + VALUE hash; VALUE ary3 = rb_ary_new(); VALUE v; long i; ary2 = to_ary(ary2); - tbl = ary_make_hash(ary1, ary2); + hash = ary_make_hash(ary1, ary2); for (i=0; ilen; i++) { v = RARRAY(ary1)->ptr[i]; - if (st_delete(tbl, &v, 0)) { + if (st_delete(RHASH(hash)->tbl, &v, 0)) { rb_ary_push(ary3, v); } } for (i=0; ilen; i++) { v = RARRAY(ary2)->ptr[i]; - if (st_delete(tbl, &v, 0)) { + if (st_delete(RHASH(hash)->tbl, &v, 0)) { rb_ary_push(ary3, v); } } - st_free_table(tbl); return ary3; } @@ -1516,21 +1511,19 @@ static VALUE rb_ary_uniq_bang(ary) VALUE ary; { - st_table *tbl = ary_make_hash(ary, 0); + VALUE hash = ary_make_hash(ary, 0); VALUE *p, *q, *end; - VALUE v; - if (RARRAY(ary)->len == tbl->num_entries) { - st_free_table(tbl); + if (RARRAY(ary)->len == RHASH(hash)->tbl->num_entries) { return Qnil; } - rb_ary_modify(ary); + rb_ary_modify(ary); p = q = RARRAY(ary)->ptr; end = p + RARRAY(ary)->len; while (p < end) { - v = *p++; - if (st_delete(tbl, &v, 0)) { + VALUE v = *p++; + if (st_delete(RHASH(hash)->tbl, &v, 0)) { *q++ = v; } } diff --git a/eval.c b/eval.c index 732ae7f9c3..2e90e78f32 100644 --- a/eval.c +++ b/eval.c @@ -4037,7 +4037,7 @@ stack_length(p) alloca(0); # define STACK_END (&stack_end) #else -# if defined(__GNUC__) && !defined(__alpha__) +# if defined(__GNUC__) && !defined(__alpha__) && !defined(__APPLE__) VALUE *stack_end = __builtin_frame_address(0); # else VALUE *stack_end = alloca(1); diff --git a/gc.c b/gc.c index ce1fb31734..6cd36bef7a 100644 --- a/gc.c +++ b/gc.c @@ -925,7 +925,7 @@ rb_gc() alloca(0); # define STACK_END (&stack_end) #else -# if defined(__GNUC__) && !defined(__alpha__) +# if defined(__GNUC__) && !defined(__alpha__) && !defined(__APPLE__) VALUE *stack_end = __builtin_frame_address(0); # else VALUE *stack_end = alloca(1); @@ -1005,7 +1005,7 @@ Init_stack(addr) #if defined(__human68k__) extern void *_SEND; rb_gc_stack_start = _SEND; -#elif defined(__GNUC__) && !defined(__alpha__) +#elif defined(__GNUC__) && !defined(__alpha__) && !defined(__APPLE__) rb_gc_stack_start = __builtin_frame_address(2); #else VALUE start; diff --git a/intern.h b/intern.h index b60180a291..1b55522921 100644 --- a/intern.h +++ b/intern.h @@ -371,11 +371,12 @@ void rb_const_assign _((VALUE, ID, VALUE)); VALUE rb_mod_constants _((VALUE)); void rb_autoload_load _((ID)); void rb_cvar_declare _((VALUE, ID, VALUE)); -int rb_cvar_defined _((VALUE, ID)); +VALUE rb_cvar_defined _((VALUE, ID)); void rb_cvar_set _((VALUE, ID, VALUE)); VALUE rb_cvar_get _((VALUE, ID)); VALUE rb_cvar_singleton _((VALUE)); VALUE rb_mod_class_variables _((VALUE)); +VALUE rb_mod_remove_cvar _((VALUE, VALUE)); /* version.c */ void ruby_show_version _((void)); void ruby_show_copyright _((void)); diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 10f05a3b2b..ab97f457a8 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -29,6 +29,9 @@ class Tempfile < SimpleDelegator end def initialize(basename, tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp') + if $SAFE > 0 and tmpdir.tainted? + tmpdir = '/tmp' + end umask = File.umask(0177) begin n = 0 diff --git a/object.c b/object.c index c4283cb069..e7f202a5eb 100644 --- a/object.c +++ b/object.c @@ -1203,6 +1203,7 @@ Init_Object() rb_define_private_method(rb_cModule, "remove_const", rb_mod_remove_const, 1); rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1); rb_define_method(rb_cModule, "class_variables", rb_mod_class_variables, 0); + rb_define_private_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1); rb_define_method(rb_cClass, "new", rb_class_new_instance, -1); rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0); diff --git a/variable.c b/variable.c index 214c76c934..69791ab26d 100644 --- a/variable.c +++ b/variable.c @@ -1225,33 +1225,34 @@ rb_const_defined(klass, id) } static void -mod_av_set(klass, id, val, dest, once) +mod_av_set(klass, id, val, isconst) VALUE klass; ID id; VALUE val; - char *dest; - int once; + int isconst; { + char *dest = isconst ? "constant" : "class variable"; + if (!OBJ_TAINTED(klass) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't set %s", dest); if (OBJ_FROZEN(klass)) rb_error_frozen("class/module"); if (!RCLASS(klass)->iv_tbl) { RCLASS(klass)->iv_tbl = st_init_numtable(); } - else if (once && st_lookup(RCLASS(klass)->iv_tbl, id, 0)) { + else if (isconst && st_lookup(RCLASS(klass)->iv_tbl, id, 0)) { rb_warn("already initialized %s %s", dest, rb_id2name(id)); } st_insert(RCLASS(klass)->iv_tbl, id, val); } - + void rb_const_set(klass, id, val) VALUE klass; ID id; VALUE val; { - mod_av_set(klass, id, val, "constant", Qtrue); + mod_av_set(klass, id, val, Qtrue); } void @@ -1377,7 +1378,7 @@ rb_cvar_declare(klass, id, val) tmp = RCLASS(tmp)->super; } - mod_av_set(klass, id, val, "class variable", Qfalse); + mod_av_set(klass, id, val, Qfalse); } VALUE @@ -1401,7 +1402,7 @@ rb_cvar_get(klass, id) return Qnil; /* not reached */ } -int +VALUE rb_cvar_defined(klass, id) VALUE klass; ID id; @@ -1485,6 +1486,32 @@ rb_mod_class_variables(obj) return ary; } +VALUE +rb_mod_remove_cvar(mod, name) + VALUE mod, name; +{ + ID id = rb_to_id(name); + VALUE val; + + if (!rb_is_class_id(id)) { + rb_raise(rb_eNameError, "wrong class variable name %s", name); + } + if (!OBJ_TAINTED(mod) && rb_safe_level() >= 4) + rb_raise(rb_eSecurityError, "Insecure: can't remove class variable"); + if (OBJ_FROZEN(mod)) rb_error_frozen("class/module"); + + if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, &id, &val)) { + return val; + } + if (rb_cvar_defined(mod, id)) { + rb_raise(rb_eNameError, "cannot remove %s for %s", + rb_id2name(id), rb_class2name(mod)); + } + rb_raise(rb_eNameError, "class variable %s not defined for %s", + rb_id2name(id), rb_class2name(mod)); + return Qnil; /* not reached */ +} + VALUE rb_iv_get(obj, name) VALUE obj; diff --git a/version.h b/version.h index 2e0832037c..0449043114 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.6.2" -#define RUBY_RELEASE_DATE "2000-12-05" +#define RUBY_RELEASE_DATE "2000-12-08" #define RUBY_VERSION_CODE 162 -#define RUBY_RELEASE_CODE 20001205 +#define RUBY_RELEASE_CODE 20001208 diff --git a/win32/Makefile.sub b/win32/Makefile.sub index f8ebcd7815..36df32cfab 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -29,7 +29,7 @@ AUTOCONF = autoconf prefix = /usr -CFLAGS = -nologo -DNT=1 -Zi -O2b2x -G5 +CFLAGS = -nologo -DNT=1 -Zi -MD -O2b2x -G5 CPPFLAGS = -I$(srcdir) -I$(srcdir)/missing LDFLAGS = $(CFLAGS) -Fm XLDFLAGS = diff --git a/win32/config.status.in b/win32/config.status.in index 2b81802718..f3636581aa 100644 --- a/win32/config.status.in +++ b/win32/config.status.in @@ -1,5 +1,5 @@ s%@SHELL@%%g -s%@CFLAGS@%-nologo -DNT=1 -Zi -O2b2x -G5%g +s%@CFLAGS@%-nologo -DNT=1 -Zi -MD -O2b2x -G5%g s%@CPPFLAGS@%%g s%@CXXFLAGS@%%g s%@FFLAGS@%%g diff --git a/win32/win32.c b/win32/win32.c index e2799eee23..22f3af9ed9 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1767,7 +1767,7 @@ myfddup (int fd) void myfdclose(FILE *fp) { -#if !defined __MINGW32__ +#if !defined MSVCRT_THREADS _free_osfhnd(fileno(fp)); #endif fclose(fp); -- cgit v1.2.3