diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-03-28 10:57:41 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-03-28 10:57:41 +0000 |
commit | 7253910df83611f0c2aa4f6c5a5718680b9aea60 (patch) | |
tree | bf2f689810676d5395ed2404d679a2e0877d1ff8 | |
parent | a0cf52c331badeed096e4e913961a38d48b0c6fc (diff) |
1.1b9_05 bug fix
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | class.c | 22 | ||||
-rw-r--r-- | dln.h | 14 | ||||
-rw-r--r-- | eval.c | 89 | ||||
-rw-r--r-- | ext/socket/socket.c | 2 | ||||
-rw-r--r-- | intern.h | 1 | ||||
-rw-r--r-- | io.c | 10 | ||||
-rw-r--r-- | object.c | 9 | ||||
-rw-r--r-- | ruby.h | 2 | ||||
-rw-r--r-- | variable.c | 43 |
10 files changed, 138 insertions, 67 deletions
@@ -1,3 +1,16 @@ +Sat Mar 28 00:47:19 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + + * 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 <matz@netlab.co.jp> * ruby.c (ruby_prog_init): load-path order changed. Paths in @@ -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 <varargs.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 @@ -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; i<n; i++) { /* skip first 2 ($_ and $~) */ + ary_push(ary, str_new2(rb_id2name(tbl[i]))); + } + } + + vars = the_dyna_vars; + while (vars) { + ary_push(ary, str_new2(rb_id2name(vars->id))); + 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; @@ -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)); @@ -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); @@ -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; i<argc; i++) { - rb_define_attr(klass, rb_to_id(argv[i]), 1, 0); + rb_attr(klass, rb_to_id(argv[i]), 1, 0, TRUE); } return Qnil; } @@ -572,7 +572,7 @@ mod_attr_writer(argc, argv, klass) int i; for (i=0; i<argc; i++) { - rb_define_attr(klass, rb_to_id(argv[i]), 0, 1); + rb_attr(klass, rb_to_id(argv[i]), 0, 1, TRUE); } return Qnil; } @@ -586,7 +586,7 @@ mod_attr_accessor(argc, argv, klass) int i; for (i=0; i<argc; i++) { - rb_define_attr(klass, rb_to_id(argv[i]), 1, 1); + rb_attr(klass, rb_to_id(argv[i]), 1, 1, TRUE); } return Qnil; } @@ -855,6 +855,7 @@ Init_Object() rb_define_method(mKernel, "hash", obj_id, 0); rb_define_method(mKernel, "id", obj_id, 0); + rb_define_method(mKernel, "__id__", obj_id, 0); rb_define_method(mKernel, "type", obj_type, 0); rb_define_method(mKernel, "clone", obj_clone, 0); @@ -385,7 +385,7 @@ void rb_define_global_function _((char *, VALUE (*)(), int)); void rb_undef_method _((VALUE,char*)); void rb_define_alias _((VALUE,char*,char*)); -void rb_define_attr _((VALUE,ID,int,int)); +void rb_define_attr _((VALUE,char*,int,int)); ID rb_intern _((char*)); char *rb_id2name _((ID)); diff --git a/variable.c b/variable.c index fa3a79516f..0827ebbec6 100644 --- a/variable.c +++ b/variable.c @@ -640,12 +640,12 @@ rb_gvar_defined(entry) } static int -gvar_i(key, entry, ary) +var_i(key, entry, ary) ID key; struct global_entry *entry; VALUE ary; { - ary_push(ary, str_new2(rb_id2name(entry->id))); + 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 |