1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2000-12-08 07:10:38 +00:00
parent a721bd628e
commit 2322a13127
14 changed files with 95 additions and 50 deletions

View file

@ -1,3 +1,8 @@
Fri Dec 8 10:44:05 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
* variable.c (rb_mod_remove_cvar): Module#remove_class_variable
added.
Thu Dec 7 17:35:51 2000 Shugo Maeda <shugo@ruby-lang.org> Thu Dec 7 17:35:51 2000 Shugo Maeda <shugo@ruby-lang.org>
* eval.c (stack_length): don't use __builtin_frame_address() on alpha. * 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>
* eval.c (rb_mod_define_method): avoid VC4.0 warnings. * eval.c (rb_mod_define_method): avoid VC4.0 warnings.
Wed Dec 6 13:38:08 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_and): tuning, make hash from shorter operand.
Wed Dec 6 01:28:50 2000 SHIROYAMA Takayuki <psi@fortune.nest.or.jp>
* 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 <eban@ruby-lang.org> Mon Dec 4 13:44:01 2000 WATANABE Hirofumi <eban@ruby-lang.org>
* lib/jcode.rb: consider multibyte. not /n. * lib/jcode.rb: consider multibyte. not /n.

View file

@ -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 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 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 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 compar.@OBJEXT@: compar.c ruby.h config.h defines.h intern.h

6
ToDo
View file

@ -94,7 +94,11 @@ Standard Libraries
* Process::waitall [ruby-talk:4557] * Process::waitall [ruby-talk:4557]
* synchronized method - synchronized{...}, synchronized :foo, :bar * synchronized method - synchronized{...}, synchronized :foo, :bar
* move Time::times to Process. * 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 Extension Libraries

55
array.c
View file

@ -1436,49 +1436,45 @@ rb_ary_diff(ary1, ary2)
return ary3; return ary3;
} }
static st_table* static VALUE
ary_make_hash(ary1, ary2, func) ary_make_hash(ary1, ary2, func)
VALUE ary1, ary2; VALUE ary1, ary2;
int (*func)(); int (*func)();
{ {
st_table *tbl = st_init_numtable(); VALUE hash = rb_hash_new();
int i, n; int i, n;
for (i=0; i<RARRAY(ary1)->len; i++) { for (i=0; i<RARRAY(ary1)->len; i++) {
if (!st_lookup(tbl, RARRAY(ary1)->ptr[i], &n)) { rb_hash_aset(hash, RARRAY(ary1)->ptr[i], Qtrue);
st_add_direct(tbl, RARRAY(ary1)->ptr[i], 0);
}
} }
if (ary2) { if (ary2) {
for (i=0; i<RARRAY(ary2)->len; i++) { for (i=0; i<RARRAY(ary2)->len; i++) {
if (st_lookup(tbl, RARRAY(ary2)->ptr[i], &n)) { rb_hash_aset(hash, RARRAY(ary2)->ptr[i], Qtrue);
st_insert(tbl, RARRAY(ary2)->ptr[i], 2);
}
else {
st_add_direct(tbl, RARRAY(ary2)->ptr[i], 1);
}
} }
} }
return tbl; return hash;
} }
static VALUE static VALUE
rb_ary_and(ary1, ary2) rb_ary_and(ary1, ary2)
VALUE ary1, ary2; VALUE ary1, ary2;
{ {
st_table *tbl = ary_make_hash(ary1, to_ary(ary2)); VALUE hash;
VALUE ary3 = rb_ary_new(); VALUE ary3 = rb_ary_new();
VALUE v;
long i; 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; i<RARRAY(ary1)->len; i++) { for (i=0; i<RARRAY(ary1)->len; i++) {
v = RARRAY(ary1)->ptr[i]; VALUE v = RARRAY(ary1)->ptr[i];
if (st_delete(tbl, &v, &n)) { if (st_delete(RHASH(hash)->tbl, &v, 0)) {
if (n == 2) rb_ary_push(ary3, v); rb_ary_push(ary3, v);
} }
} }
st_free_table(tbl);
return ary3; return ary3;
} }
@ -1487,27 +1483,26 @@ static VALUE
rb_ary_or(ary1, ary2) rb_ary_or(ary1, ary2)
VALUE ary1, ary2; VALUE ary1, ary2;
{ {
st_table *tbl; VALUE hash;
VALUE ary3 = rb_ary_new(); VALUE ary3 = rb_ary_new();
VALUE v; VALUE v;
long i; long i;
ary2 = to_ary(ary2); ary2 = to_ary(ary2);
tbl = ary_make_hash(ary1, ary2); hash = ary_make_hash(ary1, ary2);
for (i=0; i<RARRAY(ary1)->len; i++) { for (i=0; i<RARRAY(ary1)->len; i++) {
v = RARRAY(ary1)->ptr[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); rb_ary_push(ary3, v);
} }
} }
for (i=0; i<RARRAY(ary2)->len; i++) { for (i=0; i<RARRAY(ary2)->len; i++) {
v = RARRAY(ary2)->ptr[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); rb_ary_push(ary3, v);
} }
} }
st_free_table(tbl);
return ary3; return ary3;
} }
@ -1516,21 +1511,19 @@ static VALUE
rb_ary_uniq_bang(ary) rb_ary_uniq_bang(ary)
VALUE ary; VALUE ary;
{ {
st_table *tbl = ary_make_hash(ary, 0); VALUE hash = ary_make_hash(ary, 0);
VALUE *p, *q, *end; VALUE *p, *q, *end;
VALUE v;
if (RARRAY(ary)->len == tbl->num_entries) { if (RARRAY(ary)->len == RHASH(hash)->tbl->num_entries) {
st_free_table(tbl);
return Qnil; return Qnil;
} }
rb_ary_modify(ary);
rb_ary_modify(ary);
p = q = RARRAY(ary)->ptr; p = q = RARRAY(ary)->ptr;
end = p + RARRAY(ary)->len; end = p + RARRAY(ary)->len;
while (p < end) { while (p < end) {
v = *p++; VALUE v = *p++;
if (st_delete(tbl, &v, 0)) { if (st_delete(RHASH(hash)->tbl, &v, 0)) {
*q++ = v; *q++ = v;
} }
} }

2
eval.c
View file

@ -4037,7 +4037,7 @@ stack_length(p)
alloca(0); alloca(0);
# define STACK_END (&stack_end) # define STACK_END (&stack_end)
#else #else
# if defined(__GNUC__) && !defined(__alpha__) # if defined(__GNUC__) && !defined(__alpha__) && !defined(__APPLE__)
VALUE *stack_end = __builtin_frame_address(0); VALUE *stack_end = __builtin_frame_address(0);
# else # else
VALUE *stack_end = alloca(1); VALUE *stack_end = alloca(1);

4
gc.c
View file

@ -925,7 +925,7 @@ rb_gc()
alloca(0); alloca(0);
# define STACK_END (&stack_end) # define STACK_END (&stack_end)
#else #else
# if defined(__GNUC__) && !defined(__alpha__) # if defined(__GNUC__) && !defined(__alpha__) && !defined(__APPLE__)
VALUE *stack_end = __builtin_frame_address(0); VALUE *stack_end = __builtin_frame_address(0);
# else # else
VALUE *stack_end = alloca(1); VALUE *stack_end = alloca(1);
@ -1005,7 +1005,7 @@ Init_stack(addr)
#if defined(__human68k__) #if defined(__human68k__)
extern void *_SEND; extern void *_SEND;
rb_gc_stack_start = _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); rb_gc_stack_start = __builtin_frame_address(2);
#else #else
VALUE start; VALUE start;

View file

@ -371,11 +371,12 @@ void rb_const_assign _((VALUE, ID, VALUE));
VALUE rb_mod_constants _((VALUE)); VALUE rb_mod_constants _((VALUE));
void rb_autoload_load _((ID)); void rb_autoload_load _((ID));
void rb_cvar_declare _((VALUE, ID, VALUE)); 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)); void rb_cvar_set _((VALUE, ID, VALUE));
VALUE rb_cvar_get _((VALUE, ID)); VALUE rb_cvar_get _((VALUE, ID));
VALUE rb_cvar_singleton _((VALUE)); VALUE rb_cvar_singleton _((VALUE));
VALUE rb_mod_class_variables _((VALUE)); VALUE rb_mod_class_variables _((VALUE));
VALUE rb_mod_remove_cvar _((VALUE, VALUE));
/* version.c */ /* version.c */
void ruby_show_version _((void)); void ruby_show_version _((void));
void ruby_show_copyright _((void)); void ruby_show_copyright _((void));

View file

@ -29,6 +29,9 @@ class Tempfile < SimpleDelegator
end end
def initialize(basename, tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp') def initialize(basename, tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp')
if $SAFE > 0 and tmpdir.tainted?
tmpdir = '/tmp'
end
umask = File.umask(0177) umask = File.umask(0177)
begin begin
n = 0 n = 0

View file

@ -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, "remove_const", rb_mod_remove_const, 1);
rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 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_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, "new", rb_class_new_instance, -1);
rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0); rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);

View file

@ -1225,20 +1225,21 @@ rb_const_defined(klass, id)
} }
static void static void
mod_av_set(klass, id, val, dest, once) mod_av_set(klass, id, val, isconst)
VALUE klass; VALUE klass;
ID id; ID id;
VALUE val; VALUE val;
char *dest; int isconst;
int once;
{ {
char *dest = isconst ? "constant" : "class variable";
if (!OBJ_TAINTED(klass) && rb_safe_level() >= 4) if (!OBJ_TAINTED(klass) && rb_safe_level() >= 4)
rb_raise(rb_eSecurityError, "Insecure: can't set %s", dest); rb_raise(rb_eSecurityError, "Insecure: can't set %s", dest);
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module"); if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
if (!RCLASS(klass)->iv_tbl) { if (!RCLASS(klass)->iv_tbl) {
RCLASS(klass)->iv_tbl = st_init_numtable(); 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)); rb_warn("already initialized %s %s", dest, rb_id2name(id));
} }
@ -1251,7 +1252,7 @@ rb_const_set(klass, id, val)
ID id; ID id;
VALUE val; VALUE val;
{ {
mod_av_set(klass, id, val, "constant", Qtrue); mod_av_set(klass, id, val, Qtrue);
} }
void void
@ -1377,7 +1378,7 @@ rb_cvar_declare(klass, id, val)
tmp = RCLASS(tmp)->super; tmp = RCLASS(tmp)->super;
} }
mod_av_set(klass, id, val, "class variable", Qfalse); mod_av_set(klass, id, val, Qfalse);
} }
VALUE VALUE
@ -1401,7 +1402,7 @@ rb_cvar_get(klass, id)
return Qnil; /* not reached */ return Qnil; /* not reached */
} }
int VALUE
rb_cvar_defined(klass, id) rb_cvar_defined(klass, id)
VALUE klass; VALUE klass;
ID id; ID id;
@ -1485,6 +1486,32 @@ rb_mod_class_variables(obj)
return ary; 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 VALUE
rb_iv_get(obj, name) rb_iv_get(obj, name)
VALUE obj; VALUE obj;

View file

@ -1,4 +1,4 @@
#define RUBY_VERSION "1.6.2" #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_VERSION_CODE 162
#define RUBY_RELEASE_CODE 20001205 #define RUBY_RELEASE_CODE 20001208

View file

@ -29,7 +29,7 @@ AUTOCONF = autoconf
prefix = /usr prefix = /usr
CFLAGS = -nologo -DNT=1 -Zi -O2b2x -G5 CFLAGS = -nologo -DNT=1 -Zi -MD -O2b2x -G5
CPPFLAGS = -I$(srcdir) -I$(srcdir)/missing CPPFLAGS = -I$(srcdir) -I$(srcdir)/missing
LDFLAGS = $(CFLAGS) -Fm LDFLAGS = $(CFLAGS) -Fm
XLDFLAGS = XLDFLAGS =

View file

@ -1,5 +1,5 @@
s%@SHELL@%%g 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%@CPPFLAGS@%%g
s%@CXXFLAGS@%%g s%@CXXFLAGS@%%g
s%@FFLAGS@%%g s%@FFLAGS@%%g

View file

@ -1767,7 +1767,7 @@ myfddup (int fd)
void void
myfdclose(FILE *fp) myfdclose(FILE *fp)
{ {
#if !defined __MINGW32__ #if !defined MSVCRT_THREADS
_free_osfhnd(fileno(fp)); _free_osfhnd(fileno(fp));
#endif #endif
fclose(fp); fclose(fp);