summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog48
-rw-r--r--ToDo11
-rw-r--r--array.c91
-rw-r--r--class.c4
-rw-r--r--eval.c89
-rw-r--r--hash.c30
-rw-r--r--lib/find.rb1
-rw-r--r--lib/jcode.rb4
-rw-r--r--marshal.c25
-rw-r--r--misc/ruby-mode.el4
-rw-r--r--node.h4
-rw-r--r--parse.y36
-rw-r--r--string.c86
-rw-r--r--util.c15
-rw-r--r--variable.c9
-rw-r--r--version.h4
16 files changed, 305 insertions, 156 deletions
diff --git a/ChangeLog b/ChangeLog
index 13238e4..5284409 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,54 @@ Mon Dec 4 13:44:01 2000 WATANABE Hirofumi <eban@ruby-lang.org>
* lib/jcode.rb: consider multibyte. not /n.
+Mon Dec 4 09:49:36 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_inspect): output whole string contents. no more `...'
+
+ * string.c (rb_str_dump): should propagate taintness.
+
+ * hash.c (env_inspect): hash like human readable output.
+
+ * variable.c (rb_ivar_get): prohibiting instance variable access
+ is too much restriction.
+
+ * class.c (method_list): retrieving information should not be
+ restricted where $SAFE=4.
+
+ * class.c (rb_obj_singleton_methods): ditto.
+
+ * eval.c (rb_thread_priority): ditto.
+
+ * eval.c (rb_thread_local_aref): ditto.
+
+ * variable.c (rb_obj_instance_variables): ditto.
+
+ * variable.c (rb_mod_const_at): ditto.
+
+ * variable.c (rb_mod_class_variables): ditto.
+
+ * eval.c (rb_exec_end_proc): end_proc should be preserved.
+
+Sat Dec 2 22:32:43 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (rb_yield_0): || should accept exactly zero argument.
+
+ * parse.y (stmt): multiple right hand side for single assignment
+ (e.g. a = 1,2) is allowed.
+
+Wed Nov 29 07:55:29 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * marshal.c (w_long): dumping long should be smaller than 32bit max.
+
+ * marshal.c (w_long): shorter long format for small integers(-123..122).
+
+ * marshal.c (r_long): ditto.
+
+Tue Nov 28 18:10:51 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (rb_mod_define_method): quick hack to implement
+ on-the-fly method definition. experimental.
+
Mon Nov 27 17:00:35 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_eval): should not redefine builtin classes/modules
diff --git a/ToDo b/ToDo
index 6992c4c..effc73b 100644
--- a/ToDo
+++ b/ToDo
@@ -23,10 +23,11 @@ Language Spec.
* Fixnum 0 as false ????
* discourage use of symbol variable (e.g. $/, etc.) in manual
* discourage use of Perlish features by giving warnings.
-* `exception' method to be alternative for `$!'. ??
* non confusing in-block local variable (is it possible?)
+ remove scope by block
+ variables appears within block may have independent values.
+* Regexp: make /o thread safe.
+* decide if begin with rescue or ensure make do..while loop.
Hacking Interpreter
@@ -44,10 +45,11 @@ Hacking Interpreter
* scrambled script, or script filter
* setuid ruby
* performance tune for in-block (dynamic) local variables.
-* generational GC ?
+* generational GC
* give warnings to assign magic variables.
* export rb_io_{addstr,printf,puts,print}
* autoload should work with threads [ruby-talk:4589]
+* remove stdio dependency from IOs.
Standard Libraries
@@ -73,7 +75,7 @@ Standard Libraries
- performance tune for String's non-bang methods.
- 'w' template for pack/unpack
- alternative for interator? => block_given?
-- regex - /p (make obsolete), /m (new)
+- regex - /p (made obsolete), /m (new)
- consistent /, %, divmod
- unbound method object
- integrate final.rb into the core.
@@ -92,6 +94,7 @@ 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).
Extension Libraries
@@ -115,4 +118,4 @@ Tools
Misc
- publish Ruby books
-* publish Ruby books in English
+- publish Ruby books in English
diff --git a/array.c b/array.c
index 825227f..43f523d 100644
--- a/array.c
+++ b/array.c
@@ -14,6 +14,7 @@
#include "ruby.h"
#include "util.h"
+#include "st.h"
VALUE rb_cArray;
@@ -1435,21 +1436,50 @@ rb_ary_diff(ary1, ary2)
return ary3;
}
+static st_table*
+ary_make_hash(ary1, ary2, func)
+ VALUE ary1, ary2;
+ int (*func)();
+{
+ st_table *tbl = st_init_numtable();
+ 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);
+ }
+ }
+ 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);
+ }
+ }
+ }
+ return tbl;
+}
+
static VALUE
rb_ary_and(ary1, ary2)
VALUE ary1, ary2;
{
- VALUE ary3;
+ st_table *tbl = ary_make_hash(ary1, to_ary(ary2));
+ VALUE ary3 = rb_ary_new();
+ VALUE v;
long i;
+ int n;
- ary2 = to_ary(ary2);
- ary3 = rb_ary_new();
for (i=0; i<RARRAY(ary1)->len; i++) {
- if (rb_ary_includes(ary2, RARRAY(ary1)->ptr[i])
- && !rb_ary_includes(ary3, RARRAY(ary1)->ptr[i])) {
- rb_ary_push(ary3, RARRAY(ary1)->ptr[i]);
+ v = RARRAY(ary1)->ptr[i];
+ if (st_delete(tbl, &v, &n)) {
+ if (n == 2) rb_ary_push(ary3, v);
}
}
+ st_free_table(tbl);
+
return ary3;
}
@@ -1457,23 +1487,28 @@ static VALUE
rb_ary_or(ary1, ary2)
VALUE ary1, ary2;
{
- VALUE ary3;
+ st_table *tbl;
+ VALUE ary3 = rb_ary_new();
+ VALUE v;
long i;
- if (TYPE(ary2) != T_ARRAY) {
- if (rb_ary_includes(ary1, ary2)) return ary1;
- else return rb_ary_push(ary1, ary2);
- }
+ ary2 = to_ary(ary2);
+ tbl = ary_make_hash(ary1, ary2);
- ary3 = rb_ary_new();
for (i=0; i<RARRAY(ary1)->len; i++) {
- if (!rb_ary_includes(ary3, RARRAY(ary1)->ptr[i]))
- rb_ary_push(ary3, RARRAY(ary1)->ptr[i]);
+ v = RARRAY(ary1)->ptr[i];
+ if (st_delete(tbl, &v, 0)) {
+ rb_ary_push(ary3, v);
+ }
}
for (i=0; i<RARRAY(ary2)->len; i++) {
- if (!rb_ary_includes(ary3, RARRAY(ary2)->ptr[i]))
- rb_ary_push(ary3, RARRAY(ary2)->ptr[i]);
+ v = RARRAY(ary2)->ptr[i];
+ if (st_delete(tbl, &v, 0)) {
+ rb_ary_push(ary3, v);
+ }
}
+ st_free_table(tbl);
+
return ary3;
}
@@ -1481,27 +1516,25 @@ static VALUE
rb_ary_uniq_bang(ary)
VALUE ary;
{
- VALUE *p, *q, *t, *end;
+ st_table *tbl = ary_make_hash(ary, 0);
+ VALUE *p, *q, *end;
VALUE v;
+ if (RARRAY(ary)->len == tbl->num_entries) {
+ st_free_table(tbl);
+ return Qnil;
+ }
rb_ary_modify(ary);
- p = RARRAY(ary)->ptr;
- end = p + RARRAY(ary)->len;
+ p = q = RARRAY(ary)->ptr;
+ end = p + RARRAY(ary)->len;
while (p < end) {
v = *p++;
- q = t = p;
- while (q < end) {
- if (rb_equal(*q, v)) q++;
- else *t++ = *q++;
+ if (st_delete(tbl, &v, 0)) {
+ *q++ = v;
}
- end = t;
- }
- if (RARRAY(ary)->len == (end - RARRAY(ary)->ptr)) {
- return Qnil;
}
-
- RARRAY(ary)->len = (end - RARRAY(ary)->ptr);
+ RARRAY(ary)->len = (q - RARRAY(ary)->ptr);
return ary;
}
diff --git a/class.c b/class.c
index 946474c..544652a 100644
--- a/class.c
+++ b/class.c
@@ -365,8 +365,6 @@ method_list(mod, option, func)
VALUE klass;
VALUE *p, *q, *pend;
- if (!OBJ_TAINTED(mod) && rb_safe_level() >= 4)
- rb_raise(rb_eSecurityError, "Insecure: can't get metainfo");
ary = rb_ary_new();
for (klass = mod; klass; klass = RCLASS(klass)->super) {
st_foreach(RCLASS(klass)->m_tbl, func, ary);
@@ -428,8 +426,6 @@ rb_obj_singleton_methods(obj)
VALUE klass;
VALUE *p, *q, *pend;
- if (rb_safe_level() >= 4 && !OBJ_TAINTED(obj))
- rb_raise(rb_eSecurityError, "Insecure: can't get metainfo");
ary = rb_ary_new();
klass = CLASS_OF(obj);
while (klass && FL_TEST(klass, FL_SINGLETON)) {
diff --git a/eval.c b/eval.c
index 409da83..3b975ff 100644
--- a/eval.c
+++ b/eval.c
@@ -86,7 +86,10 @@ static VALUE rb_f_block_given_p _((void));
static VALUE block_pass _((VALUE,NODE*));
static VALUE rb_cMethod;
static VALUE method_proc _((VALUE));
+static VALUE method_call _((int, VALUE*, VALUE));
static VALUE rb_cUnboundMethod;
+static VALUE umethod_bind _((VALUE, VALUE));
+static VALUE rb_mod_define_method _((int, VALUE*, VALUE));
static int scope_vmode;
#define SCOPE_PUBLIC 0
@@ -1114,7 +1117,7 @@ ruby_options(argc, argv)
}
}
-static void rb_exec_end_proc _((void));
+void rb_exec_end_proc _((void));
void
ruby_finalize()
@@ -3458,14 +3461,24 @@ rb_yield_0(val, self, klass, acheck)
if (block->var) {
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
- if (nd_type(block->var) == NODE_MASGN)
- massign(self, block->var, val, acheck);
- else {
+ if (block->var == (NODE*)1) {
if (acheck && val != Qundef &&
- TYPE(val) == T_ARRAY && RARRAY(val)->len == 1) {
- val = RARRAY(val)->ptr[0];
+ TYPE(val) == T_ARRAY && RARRAY(val)->len != 0) {
+ rb_raise(rb_eArgError, "wrong # of arguments (%d for 0)",
+ RARRAY(val)->len);
+ }
+ }
+ else {
+ if (nd_type(block->var) == NODE_MASGN)
+ massign(self, block->var, val, acheck);
+ else {
+ /* argument adjust for proc_call etc. */
+ if (acheck && val != Qundef &&
+ TYPE(val) == T_ARRAY && RARRAY(val)->len == 1) {
+ val = RARRAY(val)->ptr[0];
+ }
+ assign(self, block->var, val, acheck);
}
- assign(self, block->var, val, acheck);
}
}
POP_TAG();
@@ -4210,6 +4223,14 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
result = rb_eval(recv, body);
break;
+ case NODE_DMETHOD:
+ result = method_call(argc, argv, umethod_bind(body->nd_cval, recv));
+ break;
+
+ case NODE_BMETHOD:
+ result = proc_call(body->nd_cval, rb_ary_new4(argc, argv));
+ break;
+
default:
{
int state;
@@ -5639,20 +5660,19 @@ rb_f_at_exit()
return proc;
}
-static void
+void
rb_exec_end_proc()
{
struct end_proc_data *link;
int status;
- while (end_procs) {
- link = end_procs;
- end_procs = link->next;
+ link = end_procs;
+ while (link) {
rb_protect((VALUE(*)())link->func, link->data, &status);
if (status) {
error_handle(status);
}
- free(link);
+ link = link->next;
}
while (ephemeral_end_procs) {
link = ephemeral_end_procs;
@@ -5737,6 +5757,7 @@ Init_eval()
rb_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, 1);
rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, 1);
rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2);
+ rb_define_private_method(rb_cModule, "define_method", rb_mod_define_method, -1);
rb_define_singleton_method(rb_cModule, "nesting", rb_mod_nesting, 0);
rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, 0);
@@ -6163,6 +6184,7 @@ proc_arity(proc)
Data_Get_Struct(proc, struct BLOCK, data);
if (data->var == 0) return INT2FIX(-1);
+ if (data->var == (NODE*)1) return INT2FIX(0);
switch (nd_type(data->var)) {
default:
return INT2FIX(-1);
@@ -6540,6 +6562,42 @@ umethod_proc(method)
return rb_iterate(mproc, 0, umcall, method);
}
+static VALUE
+rb_mod_define_method(argc, argv, mod)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
+{
+ ID id;
+ VALUE name, body;
+
+ if (argc == 1) {
+ id = rb_to_id(argv[0]);
+ body = rb_f_lambda();
+ }
+ else if (argc == 2) {
+ id = rb_to_id(argv[0]);
+ body = argv[1];
+ }
+ else {
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)", argc);
+ }
+ if (TYPE(body) != T_DATA) {
+ /* type error */
+ }
+ if (RDATA(body)->dmark == bm_mark) {
+ rb_add_method(mod, id, NEW_DMETHOD(method_unbind(body)), NOEX_PUBLIC);
+ }
+ else if (RDATA(body)->dmark != blk_mark) {
+ rb_add_method(mod, id, NEW_BMETHOD(body), NOEX_PUBLIC);
+ }
+ else {
+ /* type error */
+ }
+
+ return body;
+}
+
void
Init_Proc()
{
@@ -7609,12 +7667,7 @@ static VALUE
rb_thread_priority(thread)
VALUE thread;
{
- rb_thread_t th = rb_thread_check(thread);;
-
- if (rb_safe_level() >= 4 && th != curr_thread) {
- rb_raise(rb_eSecurityError, "Insecure: can't get priority");
- }
- return INT2NUM(th->priority);
+ return INT2NUM(rb_thread_check(thread)->priority);
}
static VALUE
diff --git a/hash.c b/hash.c
index 62d6145..cc58f60 100644
--- a/hash.c
+++ b/hash.c
@@ -1257,6 +1257,35 @@ env_to_s()
}
static VALUE
+env_inspect()
+{
+ char **env;
+ VALUE str = rb_str_new2("{");
+ VALUE i;
+
+ env = environ;
+ while (*env) {
+ char *s = strchr(*env, '=');
+
+ if (env != environ) {
+ rb_str_cat2(str, ", ");
+ }
+ if (s) {
+ rb_str_cat2(str, "\"");
+ rb_str_cat(str, *env, s-*env);
+ rb_str_cat2(str, "\"=>");
+ i = rb_inspect(rb_str_new2(s+1));
+ rb_str_append(str, i);
+ }
+ env++;
+ }
+ rb_str_cat2(str, "}");
+ OBJ_TAINT(str);
+
+ return str;
+}
+
+static VALUE
env_to_a()
{
char **env;
@@ -1473,6 +1502,7 @@ Init_Hash()
rb_define_singleton_method(envtbl,"reject", env_reject, 0);
rb_define_singleton_method(envtbl,"reject!", env_reject_bang, 0);
rb_define_singleton_method(envtbl,"to_s", env_to_s, 0);
+ rb_define_singleton_method(envtbl,"inspect", env_inspect, 0);
rb_define_singleton_method(envtbl,"rehash", env_none, 0);
rb_define_singleton_method(envtbl,"to_a", env_to_a, 0);
rb_define_singleton_method(envtbl,"index", env_index, 1);
diff --git a/lib/find.rb b/lib/find.rb
index 80bb5d6..b220018 100644
--- a/lib/find.rb
+++ b/lib/find.rb
@@ -9,6 +9,7 @@
module Find
def find(*path)
+ path.collect!{|d| d.dup}
while file = path.shift
catch(:prune) do
yield file
diff --git a/lib/jcode.rb b/lib/jcode.rb
index e566f96..7175c1b 100644
--- a/lib/jcode.rb
+++ b/lib/jcode.rb
@@ -1,5 +1,9 @@
# jcode.rb - ruby code to handle japanese (EUC/SJIS) string
+if $VERBOSE && $KCODE == "NONE"
+ STDERR.puts "Warning: $KCODE is NONE."
+end
+
$vsave, $VERBOSE = $VERBOSE, false
class String
printf STDERR, "feel free for some warnings:\n" if $VERBOSE
diff --git a/marshal.c b/marshal.c
index f777a0d..cf84e5e 100644
--- a/marshal.c
+++ b/marshal.c
@@ -52,7 +52,7 @@ shortlen(len, ds)
#endif
#define MARSHAL_MAJOR 4
-#define MARSHAL_MINOR 4
+#define MARSHAL_MINOR 5
#define TYPE_NIL '0'
#define TYPE_TRUE 'T'
@@ -143,10 +143,25 @@ w_long(x, arg)
char buf[sizeof(long)+1];
int i, len = 0;
+#if SIZEOF_LONG > 4
+ if (!(RSHIFT(x, 32) == 0 || RSHIFT(x, 32) == -1)) {
+ /* big long does not fit in 4 bytes */
+ rb_raise(rb_eTypeError, "long too big to dump");
+ }
+#endif
+
if (x == 0) {
w_byte(0, arg);
return;
}
+ if (0 < x && x < 123) {
+ w_byte(x + 5, arg);
+ return;
+ }
+ if (-124 < x && x < 0) {
+ w_byte((x - 5)&0xff, arg);
+ return;
+ }
for (i=1;i<sizeof(long)+1;i++) {
buf[i] = x & 0xff;
x = RSHIFT(x,8);
@@ -597,11 +612,14 @@ r_long(arg)
struct load_arg *arg;
{
register long x;
- int c = r_byte(arg);
+ int c = (char)r_byte(arg);
int i;
if (c == 0) return 0;
if (c > 0) {
+ if (4 < c && c < 128) {
+ return c - 5;
+ }
if (c > sizeof(long)) long_toobig(c);
x = 0;
for (i=0;i<c;i++) {
@@ -609,6 +627,9 @@ r_long(arg)
}
}
else {
+ if (-129 < c && c < -4) {
+ return c + 5;
+ }
c = -c;
if (c > sizeof(long)) long_toobig(c);
x = -1;
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index ed35801..cfb0b3a 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -52,7 +52,7 @@
(defconst ruby-negative
(concat "^[ \t]*\\(\\(" ruby-block-mid-re "\\)\\>\\|\\("
- ruby-block-end-re "\\)\\>\\|\\}\\|\\]\\)")
+ ruby-block-end-re "\\)\\>\\|}\\|\\]\\)")
)
(defconst ruby-operator-chars "-,.+*/%&|^~=<>:")
@@ -549,7 +549,7 @@ The variable ruby-indent-level controls the amount of indentation.
(and (not (eolp))
(progn
(forward-char -1)
- (not (looking-at "\\{")))
+ (not (looking-at "{")))
(progn
(forward-word -1)
(not (looking-at "do\\>[^_]")))))
diff --git a/node.h b/node.h
index 8140d66..1904a0a 100644
--- a/node.h
+++ b/node.h
@@ -117,6 +117,8 @@ enum node_type {
#ifdef C_ALLOCA
NODE_ALLOCA,
#endif
+ NODE_DMETHOD,
+ NODE_BMETHOD,
NODE_MEMO,
NODE_LAST
};
@@ -324,6 +326,8 @@ typedef struct RNode {
#define NEW_NEWLINE(n) rb_node_newnode(NODE_NEWLINE,0,0,n)
#define NEW_PREEXE(b) NEW_SCOPE(b)
#define NEW_POSTEXE() rb_node_newnode(NODE_POSTEXE,0,0,0)
+#define NEW_DMETHOD(b) rb_node_newnode(NODE_DMETHOD,0,0,b)
+#define NEW_BMETHOD(b) rb_node_newnode(NODE_BMETHOD,0,0,b)
#define NOEX_PUBLIC 0
#define NOEX_UNDEF 1
diff --git a/parse.y b/parse.y
index e767ea2..1121306 100644
--- a/parse.y
+++ b/parse.y
@@ -188,7 +188,7 @@ static void top_local_setup();
%type <node> if_tail opt_else case_body cases rescue exc_list exc_var ensure
%type <node> opt_call_args call_args ret_args args when_args
%type <node> aref_args opt_block_arg block_arg stmt_rhs
-%type <node> mrhs superclass generic_call block_call var_ref
+%type <node> mrhs mrhs_basic superclass generic_call block_call var_ref
%type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg
%type <node> assoc_list assocs assoc undef_list backref
%type <node> block_var opt_block_var brace_block do_block lhs none
@@ -407,6 +407,10 @@ stmt : block_call
$1->nd_value = $3;
$$ = $1;
}
+ | lhs '=' mrhs_basic
+ {
+ $$ = node_assign($1, $3);
+ }
| expr
expr : mlhs '=' mrhs
@@ -1009,17 +1013,17 @@ args : arg
$$ = list_append($1, $3);
}
-mrhs : args
+mrhs : arg
{
- if ($1 &&
- nd_type($1) == NODE_ARRAY &&
- $1->nd_next == 0)
- {
- $$ = $1->nd_head;
- }
- else {
- $$ = $1;
- }
+ value_expr($1);
+ $$ = $1;
+ }
+ | mrhs_basic
+
+mrhs_basic : args ',' arg
+ {
+ value_expr($1);
+ $$ = list_append($1, $3);
}
| args ',' tSTAR arg
{
@@ -1211,7 +1215,7 @@ primary : literal
compstmt
kEND
{
- value_expr($2);
+ value_expr($5);
$$ = NEW_FOR($2, $5, $8);
fixpos($$, $2);
}
@@ -1357,11 +1361,11 @@ block_var : lhs
opt_block_var : none
| '|' /* none */ '|'
{
- $$ = 0;
+ $$ = (NODE*)1;
}
| tOROP
{
- $$ = 0;
+ $$ = (NODE*)1;
}
| '|' block_var '|'
{
@@ -1390,7 +1394,7 @@ brace_block : '{'
compstmt '}'
{
$$ = NEW_ITER($3, 0, $4);
- fixpos($$, $3?$3:$4);
+ fixpos($$, $4);
dyna_pop($<vars>2);
}
| kDO2
@@ -1402,7 +1406,7 @@ brace_block : '{'
kEND
{
$$ = NEW_ITER($3, 0, $4);
- fixpos($$, $3?$3:$4);
+ fixpos($$, $4);
dyna_pop($<vars>2);
}
diff --git a/string.c b/string.c
index e068e44..573d694 100644
--- a/string.c
+++ b/string.c
@@ -1468,90 +1468,65 @@ VALUE
rb_str_inspect(str)
VALUE str;
{
-#define STRMAX 80
- char buf[STRMAX];
+ long len;
char *p, *pend;
- char *b;
- VALUE inspect;
+ char *q, *qend;
+ VALUE result = rb_str_new2("\"");
+ char s[5];
p = RSTRING(str)->ptr; pend = p + RSTRING(str)->len;
- b = buf;
- *b++ = '"';
-
-#define CHECK(n) {\
- if (b - buf + n > STRMAX - 4) {\
- strcpy(b, "...");\
- b += 3;\
- break;\
- }\
-}
-
while (p < pend) {
char c = *p++;
if (ismbchar(c) && p < pend) {
int len = mbclen(c);
-
- CHECK(len);
- *b++ = c;
- while (--len) {
- *b++ = *p++;
- }
+ rb_str_cat(result, p, len);
+ p += len;
}
else if (c == '"'|| c == '\\') {
- CHECK(2);
- *b++ = '\\';
- *b++ = c;
+ s[0] = '\\'; s[1] = c;
+ rb_str_cat(result, s, 2);
}
else if (ISPRINT(c)) {
- CHECK(1);
- *b++ = c;
+ s[0] = c;
+ rb_str_cat(result, s, 1);
}
else if (c == '\n') {
- CHECK(2);
- *b++ = '\\';
- *b++ = 'n';
+ s[0] = '\\'; s[1] = 'n';
+ rb_str_cat(result, s, 2);
}
else if (c == '\r') {
- CHECK(2);
- *b++ = '\\';
- *b++ = 'r';
+ s[0] = '\\'; s[1] = 'r';
+ rb_str_cat(result, s, 2);
}
else if (c == '\t') {
- CHECK(2);
- *b++ = '\\';
- *b++ = 't';
+ s[0] = '\\'; s[1] = 't';
+ rb_str_cat(result, s, 2);
}
else if (c == '\f') {
- CHECK(2);
- *b++ = '\\';
- *b++ = 'f';
+ s[0] = '\\'; s[1] = 'f';
+ rb_str_cat(result, s, 2);
}
else if (c == '\013') {
- CHECK(2);
- *b++ = '\\';
- *b++ = 'v';
+ s[0] = '\\'; s[1] = 'v';
+ rb_str_cat(result, s, 2);
}
else if (c == '\007') {
- CHECK(2);
- *b++ = '\\';
- *b++ = 'a';
+ s[0] = '\\'; s[1] = 'a';
+ rb_str_cat(result, s, 2);
}
else if (c == 033) {
- CHECK(2);
- *b++ = '\\';
- *b++ = 'e';
+ s[0] = '\\'; s[1] = 'e';
+ rb_str_cat(result, s, 2);
}
else {
- CHECK(4);
- *b++ = '\\';
- sprintf(b, "%03o", c & 0377);
- b += 3;
+ sprintf(s, "\\%03o", c & 0377);
+ rb_str_cat2(result, s);
}
}
- *b++ = '"';
- inspect = rb_str_new(buf, b - buf);
- OBJ_INFECT(inspect, str);
- return inspect;
+ rb_str_cat2(result, "\"");
+
+ OBJ_INFECT(result, str);
+ return result;
}
static VALUE
@@ -1641,6 +1616,7 @@ rb_str_dump(str)
}
*q++ = '"';
+ OBJ_INFECT(result, str);
return result;
}
diff --git a/util.c b/util.c
index d305af7..83c5a94 100644
--- a/util.c
+++ b/util.c
@@ -509,21 +509,6 @@ fixpath(const char *in, char *out)
break;
}
}
-
-#ifdef TEST
-
-int main (int argc, char *argv[])
-{
- char fixed[FILENAME_MAX];
- if (argc > 1)
- {
- _fixpath (argv[1], fixed);
- printf ("You mean %s?\n", fixed);
- }
- return 0;
-}
-
-#endif
#endif
/* mm.c */
diff --git a/variable.c b/variable.c
index d2669aa..214c76c 100644
--- a/variable.c
+++ b/variable.c
@@ -870,8 +870,6 @@ rb_ivar_get(obj, id)
{
VALUE val;
- if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)
- rb_raise(rb_eSecurityError, "Insecure: can't access instance variable");
switch (TYPE(obj)) {
case T_OBJECT:
case T_CLASS:
@@ -951,8 +949,6 @@ rb_obj_instance_variables(obj)
{
VALUE ary;
- if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)
- rb_raise(rb_eSecurityError, "Insecure: can't get metainfo");
ary = rb_ary_new();
switch (TYPE(obj)) {
case T_OBJECT:
@@ -1152,8 +1148,6 @@ VALUE
rb_mod_const_at(mod, ary)
VALUE mod, ary;
{
- if (!OBJ_TAINTED(mod) && rb_safe_level() >= 4)
- rb_raise(rb_eSecurityError, "Insecure: can't get metainfo");
if (RCLASS(mod)->iv_tbl) {
st_foreach(RCLASS(mod)->iv_tbl, sv_i, ary);
}
@@ -1477,9 +1471,6 @@ rb_mod_class_variables(obj)
{
VALUE ary = rb_ary_new();
- if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)
- rb_raise(rb_eSecurityError, "Insecure: can't get metainfo");
-
if (FL_TEST(obj, FL_SINGLETON)) {
obj = rb_cvar_singleton(rb_iv_get(obj, "__attached__"));
}
diff --git a/version.h b/version.h
index 807a73e..2e08320 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.6.2"
-#define RUBY_RELEASE_DATE "2000-11-27"
+#define RUBY_RELEASE_DATE "2000-12-05"
#define RUBY_VERSION_CODE 162
-#define RUBY_RELEASE_CODE 20001127
+#define RUBY_RELEASE_CODE 20001205