Skip to content

Commit

Permalink
matz
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Dec 8, 2000
1 parent a721bd6 commit 2322a13
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 50 deletions.
16 changes: 16 additions & 0 deletions ChangeLog
@@ -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>

* eval.c (stack_length): don't use __builtin_frame_address() on alpha.
Expand All @@ -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.

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>

* lib/jcode.rb: consider multibyte. not /n.
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion ToDo
Expand Up @@ -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

Expand Down
55 changes: 24 additions & 31 deletions array.c
Expand Up @@ -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; i<RARRAY(ary1)->len; 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; i<RARRAY(ary2)->len; 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; i<RARRAY(ary1)->len; 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;
}
Expand All @@ -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; i<RARRAY(ary1)->len; 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; i<RARRAY(ary2)->len; 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;
}
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion eval.c
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions gc.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion intern.h
Expand Up @@ -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));
3 changes: 3 additions & 0 deletions lib/tempfile.rb
Expand Up @@ -29,6 +29,9 @@ def Tempfile.callback(path, data)
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
Expand Down
1 change: 1 addition & 0 deletions object.c
Expand Up @@ -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);
Expand Down
43 changes: 35 additions & 8 deletions variable.c
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -1401,7 +1402,7 @@ rb_cvar_get(klass, id)
return Qnil; /* not reached */
}

int
VALUE
rb_cvar_defined(klass, id)
VALUE klass;
ID id;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions 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
2 changes: 1 addition & 1 deletion win32/Makefile.sub
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
2 changes: 1 addition & 1 deletion win32/win32.c
Expand Up @@ -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);
Expand Down

0 comments on commit 2322a13

Please sign in to comment.