From 7253910df83611f0c2aa4f6c5a5718680b9aea60 Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 28 Mar 1998 10:57:41 +0000 Subject: 1.1b9_05 bug fix git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 ++++++++ class.c | 22 ++----------- dln.h | 14 +++++++-- eval.c | 89 +++++++++++++++++++++++++++++++++++++++++++++-------- ext/socket/socket.c | 2 ++ intern.h | 1 + io.c | 10 +++++- object.c | 9 +++--- ruby.h | 2 +- variable.c | 43 ++++++++++---------------- 10 files changed, 138 insertions(+), 67 deletions(-) diff --git a/ChangeLog b/ChangeLog index 75a856ef55..bbc7ffd683 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Sat Mar 28 00:47:19 1998 Yukihiro Matsumoto + + * ruby.c (ruby_prog_init): `site_ruby' added to load_path. + + * eval.c (f_local_variables): new method to return an array of + local variable names. + + * variable.c (obj_instance_variables): now returns an array of + variable names, as described in the reference. + + * eval.c (rb_attr): honors default method visibility of the + current scope. + Fri Mar 27 13:49:27 1998 Yukihiro Matsumoto * ruby.c (ruby_prog_init): load-path order changed. Paths in diff --git a/class.c b/class.c index 11b1b883de..bed83ef792 100644 --- a/class.c +++ b/class.c @@ -503,28 +503,12 @@ rb_define_alias(klass, name1, name2) } void -rb_define_attr(klass, id, read, write) +rb_define_attr(klass, name, read, write) VALUE klass; - ID id; + char *name; int read, write; { - char *name; - char *buf; - ID attr, attreq, attriv; - - name = rb_id2name(id); - attr = rb_intern(name); - buf = ALLOCA_N(char,strlen(name)+2); - sprintf(buf, "%s=", name); - attreq = rb_intern(buf); - sprintf(buf, "@%s", name); - attriv = rb_intern(buf); - if (read) { - rb_add_method(klass, attr, NEW_IVAR(attriv), 0); - } - if (write) { - rb_add_method(klass, attreq, NEW_ATTRSET(attriv), 0); - } + rb_attr(klass, rb_intern(name), read, write, FALSE); } #include diff --git a/dln.h b/dln.h index 0e16170a02..7af1f63a9d 100644 --- a/dln.h +++ b/dln.h @@ -11,12 +11,20 @@ #ifndef DLN_H #define DLN_H -char *dln_find_exe(); -char *dln_find_file(); +#ifndef _ +#ifndef __STDC__ +# define _(args) () +#else +# define _(args) args +#endif +#endif + +char *dln_find_exe _((char*,char*)); +char *dln_find_file _((char*,char*)); #ifdef USE_DLN_A_OUT extern char *dln_argv0; #endif -void dln_load(); +void dln_load _((char*)); #endif diff --git a/eval.c b/eval.c index 1e5dcbb9a4..d24a24ef75 100644 --- a/eval.c +++ b/eval.c @@ -48,8 +48,8 @@ static VALUE method_proc _((VALUE)); #define SCOPE_PUBLIC 0 #define SCOPE_PRIVATE FL_USER4 #define SCOPE_PROTECTED FL_USER5 -#define SCOPE_MODFUNC (FL_USER4|FL_USER4) -#define SCOPE_MASK (FL_USER4|FL_USER4) +#define SCOPE_MODFUNC (FL_USER4|FL_USER5) +#define SCOPE_MASK (FL_USER4|FL_USER5) #define SCOPE_SET(x,f) do {FL_UNSET(x,SCOPE_MASK);FL_SET(x,(f))} while(0) #define CACHE_SIZE 0x200 @@ -311,6 +311,46 @@ rb_method_boundp(klass, id, ex) return FALSE; } +void +rb_attr(klass, id, read, write, ex) + VALUE klass; + ID id; + int read, write, ex; +{ + char *name; + char *buf; + ID attr, attreq, attriv; + int noex; + + if (!ex) noex = NOEX_PUBLIC; + else { + if (FL_TEST(the_scope, SCOPE_PRIVATE)) { + noex = NOEX_PRIVATE; + Warning("private attribute?"); + } + else if (FL_TEST(the_scope, SCOPE_PROTECTED)) { + noex = NOEX_PROTECTED; + } + else { + noex = NOEX_PUBLIC; + } + } + + name = rb_id2name(id); + attr = rb_intern(name); + buf = ALLOCA_N(char,strlen(name)+2); + sprintf(buf, "%s=", name); + attreq = rb_intern(buf); + sprintf(buf, "@%s", name); + attriv = rb_intern(buf); + if (read) { + rb_add_method(klass, attr, NEW_IVAR(attriv), noex); + } + if (write) { + rb_add_method(klass, attreq, NEW_ATTRSET(attriv), noex); + } +} + static ID init, eqq, each, aref, aset, match; VALUE errinfo = Qnil, errat = Qnil; extern NODE *eval_tree0; @@ -633,7 +673,7 @@ extern int sourceline; extern char *sourcefile; static VALUE trace_func = 0; -static void call_trace_func(); +static void call_trace_func _((char*,char*,int,VALUE,ID)); static void error_pos() @@ -828,14 +868,14 @@ eval_node(self) int rb_in_eval; #ifdef THREAD -static void thread_cleanup(); -static void thread_wait_other_threads(); -static VALUE thread_current(); +static void thread_cleanup _((void)); +static void thread_wait_other_threads _((void)); +static VALUE thread_current _((void)); #endif static int exit_status; -static void exec_end_proc(); +static void exec_end_proc _((void)); void ruby_run() @@ -1384,8 +1424,7 @@ is_defined(self, node, buf) return 0; } -static int handle_rescue(); -VALUE rb_yield_0(); +static int handle_rescue _((VALUE,NODE*)); static void blk_free(); @@ -2575,7 +2614,7 @@ rb_iter_break() static volatile voidfn rb_longjmp; #endif -static VALUE make_backtrace(); +static VALUE make_backtrace _((void)); static VALUE check_errat(val) @@ -3835,8 +3874,6 @@ mod_module_eval(mod, src) VALUE rb_load_path; -char *dln_find_file(); - static char* find_file(file) char *file; @@ -4303,6 +4340,33 @@ errat_setter(val, id, var) } VALUE f_global_variables(); +VALUE f_instance_variables(); + +VALUE +f_local_variables() +{ + ID *tbl; + int n, i; + VALUE ary = ary_new(); + struct RVarmap *vars; + + tbl = the_scope->local_tbl; + if (tbl) { + n = *tbl++; + for (i=2; iid))); + vars = vars->next; + } + + return ary; +} + static VALUE f_catch(); static VALUE f_throw(); @@ -4402,6 +4466,7 @@ Init_eval() rb_define_global_function("catch", f_catch, 1); rb_define_global_function("throw", f_throw, -1); rb_define_global_function("global_variables", f_global_variables, 0); + rb_define_global_function("local_variables", f_local_variables, 0); rb_define_method(mKernel, "send", f_send, -1); rb_define_method(mKernel, "__send__", f_send, -1); diff --git a/ext/socket/socket.c b/ext/socket/socket.c index a4e4c40e52..1b87ae9146 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -85,6 +85,7 @@ sock_new(class, fd) NEWOBJ(sock, struct RFile); OBJSETUP(sock, class, T_FILE); + rb_secure(4); MakeOpenFile(sock, fp); fp->f = rb_fdopen(fd, "r"); #ifdef NT @@ -107,6 +108,7 @@ bsock_shutdown(argc, argv, sock) int how; OpenFile *fptr; + rb_secure(4); rb_scan_args(argc, argv, "01", &howto); if (howto == Qnil) how = 2; diff --git a/intern.h b/intern.h index ba4a99506b..600d0fc213 100644 --- a/intern.h +++ b/intern.h @@ -98,6 +98,7 @@ void rb_disable_super _((VALUE, char *)); void rb_enable_super _((VALUE, char *)); void rb_clear_cache _((void)); void rb_alias _((VALUE, ID, ID)); +void rb_attr _((VALUE,ID,int,int,int)); int rb_method_boundp _((VALUE, ID, int)); VALUE dyna_var_defined _((ID)); VALUE dyna_var_ref _((ID)); diff --git a/io.c b/io.c index 75afeb5ec4..9bda7a8d73 100644 --- a/io.c +++ b/io.c @@ -725,6 +725,14 @@ io_close(io) return Qnil; } +VALUE +io_close_method(io) + VALUE io; +{ + rb_secure(4); + return io_close(io); +} + static VALUE io_closed(io) VALUE io; @@ -2446,7 +2454,7 @@ Init_IO() rb_define_method(cIO, "eof", io_eof, 0); rb_define_method(cIO, "eof?", io_eof, 0); - rb_define_method(cIO, "close", io_close, 0); + rb_define_method(cIO, "close", io_close_method, 0); rb_define_method(cIO, "closed?", io_closed, 0); rb_define_method(cIO, "isatty", io_isatty, 0); diff --git a/object.c b/object.c index 286fc589e6..7de7225caf 100644 --- a/object.c +++ b/object.c @@ -545,7 +545,7 @@ mod_attr(argc, argv, klass) VALUE name, pub; rb_scan_args(argc, argv, "11", &name, &pub); - rb_define_attr(klass, rb_to_id(name), 1, RTEST(pub)); + rb_attr(klass, rb_to_id(name), 1, RTEST(pub), TRUE); return Qnil; } @@ -558,7 +558,7 @@ mod_attr_reader(argc, argv, klass) int i; for (i=0; iid))); + ary_push(ary, str_new2(rb_id2name(key))); return ST_CONTINUE; } @@ -653,13 +653,15 @@ VALUE f_global_variables() { VALUE ary = ary_new(); - char buf[3]; - char *s = "^&`'+123456789"; - - st_foreach(global_tbl, gvar_i, ary); - while (*s) { - sprintf(buf, "$%c", *s++); - ary_push(ary, str_new2(buf)); + char buf[4]; + char *s = "&`'+123456789"; + + st_foreach(global_tbl, var_i, ary); + if (!NIL_P(backref_get())) { + while (*s) { + sprintf(buf, "$%c", *s++); + ary_push(ary, str_new2(buf)); + } } return ary; } @@ -746,36 +748,23 @@ rb_ivar_defined(obj, id) return FALSE; } -static int -ivar_i(key, value, hash) - ID key; - VALUE value; - VALUE hash; -{ - if (rb_is_instance_id(key)) { - hash_aset(hash, str_new2(rb_id2name(key)), value); - } - return ST_CONTINUE; -} - VALUE obj_instance_variables(obj) VALUE obj; { - VALUE hash = hash_new(); + VALUE ary; switch (TYPE(obj)) { case T_OBJECT: case T_CLASS: case T_MODULE: + ary = ary_new(); if (ROBJECT(obj)->iv_tbl) { - st_foreach(ROBJECT(obj)->iv_tbl, ivar_i, hash); + st_foreach(ROBJECT(obj)->iv_tbl, var_i, ary); } - break; - default: - break; + return ary; } - return hash; + return Qnil; } VALUE -- cgit v1.2.3