1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

2000-01-17

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2000-01-17 08:37:53 +00:00
parent e43877719b
commit dde62bcd2e
21 changed files with 391 additions and 256 deletions

View file

@ -1,3 +1,40 @@
Sat Jan 15 22:21:08 2000 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* eval.c (search_method): argument klass may be 0.
Sat Jan 15 15:03:46 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* enum.c (enum_index): remove this method.
* enum.c: remove use of pointers to local variables. find,
find_all, min, max, index, member?, each_with_index,
* eval.c (massign): multiple assignment does not use to_a anymore.
experimental.
Fri Jan 14 12:22:04 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* string.c (rb_str_replace): use memmove instead of memcpy for
overwrapping strings (e.g. a[1] = a).
Thu Jan 13 11:12:40 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* parse.y (arg_add): use new node, ARGSPUSH.
Mon Jan 10 18:32:28 2000 Koji Arai <JCA02266@nifty.ne.jp>
* marshal.c (w_object): forgot an argument to call w_ivar().
Sun Jan 9 18:13:51 2000 Katsuyuki Komatsu <komatsu@sarion.co.jp>
* random.c: first was not defined unless HAVE_RANDOM.
Sat Jan 8 19:02:49 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* io.c (rb_io_sysread): raise IOError for buffered IO.
* ext/socket/socket.c (s_recv): ditto.
Fri Jan 7 00:59:29 2000 Masahiro Tomita <tommy@tmtm.org> Fri Jan 7 00:59:29 2000 Masahiro Tomita <tommy@tmtm.org>
* io.c (io_fread): TRAP_BEG/TRAP_END added around getc(). * io.c (io_fread): TRAP_BEG/TRAP_END added around getc().
@ -123,6 +160,10 @@ Tue Dec 21 17:21:28 1999 Koji Oda <oda@bsd1.qnes.nec.co.jp>
* ext/socket/socket.c (sock_finalize): mswin32: fix FILE* leak. * ext/socket/socket.c (sock_finalize): mswin32: fix FILE* leak.
Mon Dec 20 19:08:12 1999 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* file.c (rb_file_s_expand_path): handle dir separetor correctly.
Sun Dec 19 22:56:31 1999 KANEKO Naoshi <wbs01621@mail.wbs.ne.jp> Sun Dec 19 22:56:31 1999 KANEKO Naoshi <wbs01621@mail.wbs.ne.jp>
* lib/find.rb: support dosish root directory. * lib/find.rb: support dosish root directory.

1
ToDo
View file

@ -34,6 +34,7 @@ Hacking Interpreter
* syntax tree -> bytecode ??? * syntax tree -> bytecode ???
* scrambled script, or script filter * scrambled script, or script filter
* setuid ruby * setuid ruby
* freeze all object
Standard Libraries Standard Libraries

165
enum.c
View file

@ -11,6 +11,7 @@
************************************************/ ************************************************/
#include "ruby.h" #include "ruby.h"
#include "node.h"
VALUE rb_mEnumerable; VALUE rb_mEnumerable;
static ID id_each, id_eqq, id_cmp; static ID id_each, id_eqq, id_cmp;
@ -58,19 +59,14 @@ enum_grep(obj, pat)
return tmp; return tmp;
} }
struct find_arg {
int found;
VALUE val;
};
static VALUE static VALUE
find_i(i, arg) find_i(i, memo)
VALUE i; VALUE i;
struct find_arg *arg; NODE *memo;
{ {
if (RTEST(rb_yield(i))) { if (RTEST(rb_yield(i))) {
arg->found = Qtrue; memo->u2.value = Qtrue;
arg->val = i; memo->u1.value = i;
rb_iter_break(); rb_iter_break();
} }
return Qnil; return Qnil;
@ -82,18 +78,19 @@ enum_find(argc, argv, obj)
VALUE* argv; VALUE* argv;
VALUE obj; VALUE obj;
{ {
struct find_arg arg; NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, Qfalse, 0);
VALUE if_none; VALUE if_none;
rb_scan_args(argc, argv, "01", &if_none); rb_scan_args(argc, argv, "01", &if_none);
arg.found = Qfalse; rb_iterate(rb_each, obj, find_i, (VALUE)memo);
rb_iterate(rb_each, obj, find_i, (VALUE)&arg); if (memo->u2.value) {
if (arg.found) { rb_gc_force_recycle((VALUE)memo);
return arg.val; return memo->u1.value;
} }
if (!NIL_P(if_none)) { if (!NIL_P(if_none)) {
rb_eval_cmd(if_none, Qnil); rb_eval_cmd(if_none, Qnil);
} }
rb_gc_force_recycle((VALUE)memo);
return Qnil; return Qnil;
} }
@ -189,33 +186,35 @@ enum_sort(obj)
} }
static VALUE static VALUE
min_i(i, min) min_i(i, memo)
VALUE i, *min; VALUE i;
NODE *memo;
{ {
VALUE cmp; VALUE cmp;
if (NIL_P(*min)) if (NIL_P(memo->u1.value))
*min = i; memo->u1.value = i;
else { else {
cmp = rb_funcall(i, id_cmp, 1, *min); cmp = rb_funcall(i, id_cmp, 1, memo->u1.value);
if (NUM2LONG(cmp) < 0) if (NUM2LONG(cmp) < 0)
*min = i; memo->u1.value = i;
} }
return Qnil; return Qnil;
} }
static VALUE static VALUE
min_ii(i, min) min_ii(i, memo)
VALUE i, *min; VALUE i;
NODE *memo;
{ {
VALUE cmp; VALUE cmp;
if (NIL_P(*min)) if (NIL_P(memo->u1.value))
*min = i; memo->u1.value = i;
else { else {
cmp = rb_yield(rb_assoc_new(i, *min)); cmp = rb_yield(rb_assoc_new(i, memo->u1.value));
if (NUM2LONG(cmp) < 0) if (NUM2LONG(cmp) < 0)
*min = i; memo->u1.value = i;
} }
return Qnil; return Qnil;
} }
@ -224,40 +223,43 @@ static VALUE
enum_min(obj) enum_min(obj)
VALUE obj; VALUE obj;
{ {
VALUE min = Qnil; NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, 0, 0);
rb_iterate(rb_each, obj, rb_iterator_p()?min_ii:min_i, (VALUE)&min); rb_iterate(rb_each, obj, rb_iterator_p()?min_ii:min_i, (VALUE)memo);
return min; rb_gc_force_recycle((VALUE)memo);
return memo->u1.value;
} }
static VALUE static VALUE
max_i(i, max) max_i(i, memo)
VALUE i, *max; VALUE i;
NODE *memo;
{ {
VALUE cmp; VALUE cmp;
if (NIL_P(*max)) if (NIL_P(memo->u1.value))
*max = i; memo->u1.value = i;
else { else {
cmp = rb_funcall(i, id_cmp, 1, *max); cmp = rb_funcall(i, id_cmp, 1, memo->u1.value);
if (NUM2LONG(cmp) > 0) if (NUM2LONG(cmp) > 0)
*max = i; memo->u1.value = i;
} }
return Qnil; return Qnil;
} }
static VALUE static VALUE
max_ii(i, max) max_ii(i, memo)
VALUE i, *max; VALUE i;
NODE *memo;
{ {
VALUE cmp; VALUE cmp;
if (NIL_P(*max)) if (NIL_P(memo->u1.value))
*max = i; memo->u1.value = i;
else { else {
cmp = rb_yield(rb_assoc_new(i, *max)); cmp = rb_yield(rb_assoc_new(i, memo->u1.value));
if (NUM2LONG(cmp) > 0) if (NUM2LONG(cmp) > 0)
*max = i; memo->u1.value = i;
} }
return Qnil; return Qnil;
} }
@ -266,54 +268,20 @@ static VALUE
enum_max(obj) enum_max(obj)
VALUE obj; VALUE obj;
{ {
VALUE max = Qnil; NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, 0, 0);
rb_iterate(rb_each, obj, rb_iterator_p()?max_ii:max_i, (VALUE)&max); rb_iterate(rb_each, obj, rb_iterator_p()?max_ii:max_i, (VALUE)memo);
return max; rb_gc_force_recycle((VALUE)memo);
return memo->u1.value;
} }
struct i_v_pair {
int i;
VALUE v;
int found;
};
static VALUE static VALUE
index_i(item, iv) member_i(item, memo)
VALUE item; VALUE item;
struct i_v_pair *iv; NODE *memo;
{ {
if (rb_equal(item, iv->v)) { if (rb_equal(item, memo->u1.value)) {
iv->found = 1; memo->u2.value = Qtrue;
rb_iter_break();
}
else {
iv->i++;
}
return Qnil;
}
static VALUE
enum_index(obj, val)
VALUE obj, val;
{
struct i_v_pair iv;
iv.i = 0;
iv.v = val;
iv.found = 0;
rb_iterate(rb_each, obj, index_i, (VALUE)&iv);
if (iv.found) return INT2FIX(iv.i);
return Qnil; /* not found */
}
static VALUE
member_i(item, iv)
VALUE item;
struct i_v_pair *iv;
{
if (rb_equal(item, iv->v)) {
iv->i = 1;
rb_iter_break(); rb_iter_break();
} }
return Qnil; return Qnil;
@ -323,26 +291,23 @@ static VALUE
enum_member(obj, val) enum_member(obj, val)
VALUE obj, val; VALUE obj, val;
{ {
struct i_v_pair iv; VALUE result;
iv.i = 0; NODE *memo = rb_node_newnode(NODE_MEMO, val, Qfalse, 0);
iv.v = val;
rb_iterate(rb_each, obj, member_i, (VALUE)&iv); rb_iterate(rb_each, obj, member_i, (VALUE)memo);
if (iv.i) return Qtrue; result = memo->u2.value;
return Qfalse; rb_gc_force_recycle((VALUE)memo);
return result;
} }
static VALUE static VALUE
each_with_index_i(val, indexp) each_with_index_i(val, memo)
VALUE val; VALUE val;
int *indexp; NODE *memo;
{ {
#if 1 rb_yield(rb_assoc_new(val, INT2FIX(memo->u3.cnt)));
rb_yield(rb_assoc_new(val, INT2FIX(*indexp))); memo->u3.cnt++;
#else
rb_yield(rb_ary_concat(rb_Array(val), INT2FIX(*indexp)));
#endif
(*indexp)++;
return Qnil; return Qnil;
} }
@ -350,9 +315,10 @@ static VALUE
enum_each_with_index(obj) enum_each_with_index(obj)
VALUE obj; VALUE obj;
{ {
int index = 0; NODE *memo = rb_node_newnode(NODE_MEMO, 0, 0, 0);
rb_iterate(rb_each, obj, each_with_index_i, (VALUE)&index); rb_iterate(rb_each, obj, each_with_index_i, (VALUE)memo);
rb_gc_force_recycle((VALUE)memo);
return Qnil; return Qnil;
} }
@ -374,7 +340,6 @@ Init_Enumerable()
rb_define_method(rb_mEnumerable,"collect", enum_collect, 0); rb_define_method(rb_mEnumerable,"collect", enum_collect, 0);
rb_define_method(rb_mEnumerable,"min", enum_min, 0); rb_define_method(rb_mEnumerable,"min", enum_min, 0);
rb_define_method(rb_mEnumerable,"max", enum_max, 0); rb_define_method(rb_mEnumerable,"max", enum_max, 0);
rb_define_method(rb_mEnumerable,"index", enum_index, 1);
rb_define_method(rb_mEnumerable,"member?", enum_member, 1); rb_define_method(rb_mEnumerable,"member?", enum_member, 1);
rb_define_method(rb_mEnumerable,"include?", enum_member, 1); rb_define_method(rb_mEnumerable,"include?", enum_member, 1);
rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, 0); rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, 0);

18
eval.c
View file

@ -239,6 +239,7 @@ search_method(klass, id, origin)
{ {
NODE *body; NODE *body;
if (!klass) return 0;
while (!st_lookup(RCLASS(klass)->m_tbl, id, &body)) { while (!st_lookup(RCLASS(klass)->m_tbl, id, &body)) {
klass = RCLASS(klass)->super; klass = RCLASS(klass)->super;
if (!klass) return 0; if (!klass) return 0;
@ -2284,6 +2285,11 @@ rb_eval(self, node)
rb_eval(self, node->nd_body)); rb_eval(self, node->nd_body));
break; break;
case NODE_ARGSPUSH:
result = rb_ary_push(rb_eval(self, node->nd_head),
rb_eval(self, node->nd_body));
break;
case NODE_CALL: case NODE_CALL:
{ {
VALUE recv; VALUE recv;
@ -3333,10 +3339,13 @@ rb_yield_0(val, self, klass, acheck)
!FL_TEST(ruby_dyna_vars, DVAR_DONT_RECYCLE)) { !FL_TEST(ruby_dyna_vars, DVAR_DONT_RECYCLE)) {
struct RVarmap *vars = ruby_dyna_vars; struct RVarmap *vars = ruby_dyna_vars;
do { while (vars && vars->id != 0) {
rb_gc_force_recycle((VALUE)vars); rb_gc_force_recycle((VALUE)vars);
vars = vars->next; vars = vars->next;
} while (vars && vars->id != 0); }
if (ruby_dyna_vars->id == 0) {
rb_gc_force_recycle((VALUE)ruby_dyna_vars);
}
} }
POP_VARS(); POP_VARS();
ruby_block = block; ruby_block = block;
@ -3379,7 +3388,10 @@ massign(self, node, val, check)
if (val) { if (val) {
if (TYPE(val) != T_ARRAY) { if (TYPE(val) != T_ARRAY) {
val = rb_Array(val); if (NIL_P(val))
val = rb_ary_new2(0);
else
val = rb_ary_new3(1, val);
} }
len = RARRAY(val)->len; len = RARRAY(val)->len;
for (i=0; list && i<len; i++) { for (i=0; list && i<len; i++) {

View file

@ -373,10 +373,14 @@ s_recv(sock, argc, argv, from)
if (flg == Qnil) flags = 0; if (flg == Qnil) flags = 0;
else flags = NUM2INT(flg); else flags = NUM2INT(flg);
GetOpenFile(sock, fptr);
if (rb_read_pending(fptr->f)) {
rb_raise(rb_eIOError, "recv for buffered IO");
}
fd = fileno(fptr->f);
str = rb_str_new(0, NUM2INT(len)); str = rb_str_new(0, NUM2INT(len));
GetOpenFile(sock, fptr);
fd = fileno(fptr->f);
rb_thread_wait_fd(fd); rb_thread_wait_fd(fd);
TRAP_BEG; TRAP_BEG;
retry: retry:

View file

@ -235,7 +235,7 @@ module TkComm
return format("rb_out %s", id); return format("rb_out %s", id);
end end
def uninstall_cmd(id) def uninstall_cmd(id)
id = $1 if /rb_out (c\d+)/ id = $1 if /rb_out (c\d+)/ =~ id
Tk_CMDTBL[id] = nil Tk_CMDTBL[id] = nil
end end
private :install_cmd, :uninstall_cmd private :install_cmd, :uninstall_cmd
@ -347,15 +347,6 @@ module TkComm
def _bind_append(what, context, cmd, args=nil) def _bind_append(what, context, cmd, args=nil)
_bind_core('+', what, context, cmd, args) _bind_core('+', what, context, cmd, args)
end end
private :install_bind, :tk_event_sequence, :_bind_core, :_bind, :_bind_append
def bind_all(context, cmd=Proc.new, args=nil)
_bind(['bind', 'all'], context, cmd, args)
end
def bind_append_all(context, cmd=Proc.new, args=nil)
_bind_append(['bind', 'all'], context, cmd, args)
end
def _bindinfo(what, context=nil) def _bindinfo(what, context=nil)
if context if context
@ -372,11 +363,33 @@ module TkComm
} }
end end
end end
private :install_bind, :tk_event_sequence,
:_bind_core, :_bind, :_bind_append, :_bindinfo
def bind(tagOrClass, context, cmd=Proc.new, args=nil)
_bind(["bind", tagOrClass], context, cmd, args)
end
def bind_append(tagOrClass, context, cmd=Proc.new, args=nil)
_bind_append(["bind", tagOrClass], context, cmd, args)
end
def bindinfo(tagOrClass, context=nil) def bindinfo(tagOrClass, context=nil)
_bindinfo(['bind', tagOrClass], context) _bindinfo(['bind', tagOrClass], context)
end end
def bind_all(context, cmd=Proc.new, args=nil)
_bind(['bind', 'all'], context, cmd, args)
end
def bind_append_all(context, cmd=Proc.new, args=nil)
_bind_append(['bind', 'all'], context, cmd, args)
end
def bindinfo_all(context=nil)
_bindinfo(['bind', 'all'], context)
end
def pack(*args) def pack(*args)
TkPack.configure *args TkPack.configure *args
end end
@ -401,7 +414,7 @@ module TkCore
INTERP = TclTkIp.new INTERP = TclTkIp.new
INTERP._invoke("proc", "rb_out", "args", "if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $args]} ret]] != 0} {return -code $st $ret} {return $ret}") INTERP._invoke("proc", "rb_out", "args", "if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $args]} ret]] != 0} {if {[regsub -all {!} $args {\\!} newargs] == 0} {return -code $st $ret} {if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $newargs]} ret]] != 0} {return -code $st $ret} {return $ret}}} {return $ret}")
def callback_break def callback_break
raise TkCallbackBreak, "Tk callback returns 'break' status" raise TkCallbackBreak, "Tk callback returns 'break' status"
@ -575,8 +588,8 @@ module Tk
module Wm module Wm
include TkComm include TkComm
def aspect(*args) def aspect(*args)
w = window(tk_call('wm', 'grid', path, *args)) w = tk_call('wm', 'aspect', path, *args)
w.split.collect{|s|s.to_i} if args.length == 0 list(w) if args.length == 0
end end
def client(name=None) def client(name=None)
tk_call 'wm', 'client', path, name tk_call 'wm', 'client', path, name
@ -594,17 +607,18 @@ module Tk
tk_call 'wm', 'focusmodel', path, *args tk_call 'wm', 'focusmodel', path, *args
end end
def frame def frame
tk_call 'wm', 'frame', path tk_call('wm', 'frame', path)
end end
def geometry(*args) def geometry(*args)
list(tk_call('wm', 'geometry', path, *args)) tk_call('wm', 'geometry', path, *args)
end end
def grid(*args) def grid(*args)
w = tk_call('wm', 'grid', path, *args) w = tk_call('wm', 'grid', path, *args)
list(w) if args.size == 0 list(w) if args.size == 0
end end
def group(*args) def group(*args)
tk_call 'wm', 'group', path, *args w = tk_call 'wm', 'group', path, *args
window(w) if args.size == 0
end end
def iconbitmap(*args) def iconbitmap(*args)
tk_call 'wm', 'iconbitmap', path, *args tk_call 'wm', 'iconbitmap', path, *args
@ -628,7 +642,7 @@ module Tk
end end
def maxsize(*args) def maxsize(*args)
w = tk_call('wm', 'maxsize', path, *args) w = tk_call('wm', 'maxsize', path, *args)
list(w) if not args.size == 0 list(w) if args.size == 0
end end
def minsize(*args) def minsize(*args)
w = tk_call('wm', 'minsize', path, *args) w = tk_call('wm', 'minsize', path, *args)
@ -661,7 +675,7 @@ module Tk
end end
end end
def sizefrom(*args) def sizefrom(*args)
list(tk_call('wm', 'sizefrom', path, *args)) tk_call('wm', 'sizefrom', path, *args)
end end
def state def state
tk_call 'wm', 'state', path tk_call 'wm', 'state', path
@ -670,7 +684,7 @@ module Tk
tk_call 'wm', 'title', path, *args tk_call 'wm', 'title', path, *args
end end
def transient(*args) def transient(*args)
tk_call 'wm', 'transient', path, *args window(tk_call 'wm', 'transient', path, *args)
end end
def withdraw def withdraw
tk_call 'wm', 'withdraw', path tk_call 'wm', 'withdraw', path
@ -678,6 +692,46 @@ module Tk
end end
end end
module TkBindCore
def bind(context, cmd=Proc.new, args=nil)
Tk.bind(to_eval, context, cmd, args)
end
def bind_append(context, cmd=Proc.new, args=nil)
Tk.bind_append(to_eval, context, cmd, args)
end
def bindinfo(context=nil)
Tk.bindinfo(to_eval, context)
end
end
class TkBindTag
include TkBindCore
BTagID_TBL = {}
Tk_BINDTAG_ID = ["btag00000"]
def TkBindTag.id2obj(id)
BTagID_TBL[id]? BTagID_TBL[id]: id
end
def initialize(*args)
@id = Tk_BINDTAG_ID[0]
Tk_BINDTAG_ID[0] = Tk_BINDTAG_ID[0].succ
BTagID_TBL[@id] = self
bind(*args) if args != []
end
def to_eval
@id
end
def inspect
format "#<TkBindTag: %s>", @id
end
end
class TkVariable class TkVariable
include Tk include Tk
extend TkCore extend TkCore
@ -790,7 +844,7 @@ class TkVariable
end end
def inspect def inspect
format "<TkVariable: %s>", @id format "#<TkVariable: %s>", @id
end end
def ==(other) def ==(other)
@ -1063,19 +1117,19 @@ module TkWinfo
include Tk include Tk
extend Tk extend Tk
def TkWinfo.atom(name) def TkWinfo.atom(name)
tk_call 'winfo', name number(tk_call 'winfo', 'atom', name)
end end
def winfo_atom(name) def winfo_atom(name)
TkWinfo.atom name TkWinfo.atom name
end end
def TkWinfo.atomname(id) def TkWinfo.atomname(id)
tk_call 'winfo', id tk_call 'winfo', 'atomname', id
end end
def winfo_atomname(id) def winfo_atomname(id)
TkWinfo.atomname id TkWinfo.atomname id
end end
def TkWinfo.cells(window) def TkWinfo.cells(window)
number(tk_call('winfo', window.path)) number(tk_call('winfo', 'cells', window.path))
end end
def winfo_cells def winfo_cells
TkWinfo.cells self TkWinfo.cells self
@ -1093,6 +1147,12 @@ module TkWinfo
def winfo_classname def winfo_classname
TkWinfo.classname self TkWinfo.classname self
end end
def TkWinfo.colormapfull(window)
bool(tk_call('winfo', 'colormapfull', window.path))
end
def winfo_colormapfull
TkWinfo.colormapfull self
end
def TkWinfo.containing(rootX, rootY) def TkWinfo.containing(rootX, rootY)
path = tk_call('winfo', 'containing', rootX, rootY) path = tk_call('winfo', 'containing', rootX, rootY)
window(path) window(path)
@ -1119,7 +1179,7 @@ module TkWinfo
TkWinfo.fpixels self, number TkWinfo.fpixels self, number
end end
def TkWinfo.geometry(window) def TkWinfo.geometry(window)
list(tk_call('winfo', 'geometry', window.path)) tk_call('winfo', 'geometry', window.path)
end end
def winfo_geometry def winfo_geometry
TkWinfo.geometry self TkWinfo.geometry self
@ -1131,15 +1191,15 @@ module TkWinfo
TkWinfo.height self TkWinfo.height self
end end
def TkWinfo.id(window) def TkWinfo.id(window)
number(tk_call('winfo', 'id', window.path)) tk_call('winfo', 'id', window.path)
end end
def winfo_id def winfo_id
TkWinfo.id self TkWinfo.id self
end end
def TkWinfo.interps(window=nil) def TkWinfo.interps(window=nil)
if window if window
tk_split_simplelist(tk_call('winfo', '-displayof', window.path, tk_split_simplelist(tk_call('winfo', 'interps',
'interps')) '-displayof', window.path))
else else
tk_split_simplelist(tk_call('winfo', 'interps')) tk_split_simplelist(tk_call('winfo', 'interps'))
end end
@ -1153,8 +1213,14 @@ module TkWinfo
def winfo_mapped? def winfo_mapped?
TkWinfo.mapped? self TkWinfo.mapped? self
end end
def TkWinfo.manager(window)
tk_call('winfo', 'manager', window.path)
end
def winfo_manager
TkWinfo.manager self
end
def TkWinfo.appname(window) def TkWinfo.appname(window)
bool(tk_call('winfo', 'name', window.path)) tk_call('winfo', 'name', window.path)
end end
def winfo_appname def winfo_appname
TkWinfo.appname self TkWinfo.appname self
@ -1255,6 +1321,12 @@ module TkWinfo
def winfo_screenwidth def winfo_screenwidth
TkWinfo.screenwidth self TkWinfo.screenwidth self
end end
def TkWinfo.server(window)
tk_call 'winfo', 'server', window.path
end
def winfo_server
TkWinfo.server self
end
def TkWinfo.toplevel(window) def TkWinfo.toplevel(window)
window(tk_call('winfo', 'toplevel', window.path)) window(tk_call('winfo', 'toplevel', window.path))
end end
@ -1267,7 +1339,24 @@ module TkWinfo
def winfo_visual def winfo_visual
TkWinfo.visual self TkWinfo.visual self
end end
def TkWinfo.vrootheigh(window) def TkWinfo.visualid(window)
tk_call 'winfo', 'visualid', window.path
end
def winfo_visualid
TkWinfo.visualid self
end
def TkWinfo.visualsavailable(window, includeids=false)
if includeids
v = tk_call('winfo', 'visualsavailable', window.path, "includeids")
else
v = tk_call('winfo', 'visualsavailable', window.path)
end
list(v)
end
def winfo_visualsavailable(includeids=false)
TkWinfo.visualsavailable self, includeids
end
def TkWinfo.vrootheight(window)
number(tk_call('winfo', 'vrootheight', window.path)) number(tk_call('winfo', 'vrootheight', window.path))
end end
def winfo_vrootheight def winfo_vrootheight
@ -1540,6 +1629,7 @@ end
class TkObject<TkKernel class TkObject<TkKernel
include Tk include Tk
include TkTreatFont include TkTreatFont
include TkBindCore
def path def path
return @path return @path
@ -1636,18 +1726,6 @@ class TkObject<TkKernel
end end
end end
def bind(context, cmd=Proc.new, args=nil)
_bind(["bind", to_eval], context, cmd, args)
end
def bind_append(context, cmd=Proc.new, args=nil)
_bind_append(["bind", to_eval], context, cmd, args)
end
def bindinfo(context=nil)
_bindinfo(['bind', to_eval], context)
end
def event_generate(context, keys=nil) def event_generate(context, keys=nil)
if keys if keys
tk_call('event', 'generate', path, tk_call('event', 'generate', path,
@ -1671,7 +1749,7 @@ class TkObject<TkKernel
end end
class TkWindow<TkObject class TkWindow<TkObject
# extend TkClassBind extend TkBindCore
def initialize(parent=nil, keys=nil) def initialize(parent=nil, keys=nil)
install_win(if parent then parent.path end) install_win(if parent then parent.path end)
@ -1819,11 +1897,15 @@ class TkWindow<TkObject
fail unless taglist.kind_of? Array fail unless taglist.kind_of? Array
tk_call('bindtags', path, taglist) tk_call('bindtags', path, taglist)
else else
tk_split_list(tk_call('bindtags', path)).collect{|tag| list(tk_call('bindtags', path)).collect{|tag|
if tag == nil if tag.kind_of?(String)
'.' if cls = WidgetClassNames[tag]
elsif tag.kind_of?(String) && (cls = WidgetClassNames[tag]) cls
cls elsif btag = TkBindTag.id2obj(tag)
btag
else
tag
end
else else
tag tag
end end
@ -1874,12 +1956,12 @@ class TkToplevel<TkWindow
@classname = classname @classname = classname
if keys.kind_of? Hash if keys.kind_of? Hash
keys = keys.dup keys = keys.dup
@classname = keys.delete('classname') @classname = keys.delete('classname') if keys.key?('classname')
@colormap = keys.delete('colormap') @colormap = keys.delete('colormap') if keys.key?('colormap')
@container = keys.delete('container') @container = keys.delete('container') if keys.key?('container')
@screen = keys.delete('screen') @screen = keys.delete('screen') if keys.key?('screen')
@use = keys.delete('use') @use = keys.delete('use') if keys.key?('use')
@visual = keys.delete('visual') @visual = keys.delete('visual') if keys.key?('visual')
end end
super(parent, keys) super(parent, keys)
end end
@ -1910,10 +1992,10 @@ class TkFrame<TkWindow
def initialize(parent=nil, keys=nil) def initialize(parent=nil, keys=nil)
if keys.kind_of? Hash if keys.kind_of? Hash
keys = keys.dup keys = keys.dup
@classname = keys.delete('classname') @classname = keys.delete('classname') if keys.key?('classname')
@colormap = keys.delete('colormap') @colormap = keys.delete('colormap') if keys.key?('colormap')
@container = keys.delete('container') @container = keys.delete('container') if keys.key?('container')
@visual = keys.delete('visual') @visual = keys.delete('visual') if keys.key?('visual')
end end
super(parent, keys) super(parent, keys)
end end

View file

@ -489,15 +489,15 @@ class TkcTag<TkObject
CTagID_TBL[id]? CTagID_TBL[id]: id CTagID_TBL[id]? CTagID_TBL[id]: id
end end
$tk_canvas_tag = 'ctag0000' Tk_CanvasTag_ID = ['ctag0000']
def initialize(parent, mode=nil, *args) def initialize(parent, mode=nil, *args)
if not parent.kind_of?(TkCanvas) if not parent.kind_of?(TkCanvas)
fail format("%s need to be TkCanvas", parent.inspect) fail format("%s need to be TkCanvas", parent.inspect)
end end
@c = parent @c = parent
@path = @id = $tk_canvas_tag @path = @id = Tk_CanvasTag_ID[0]
CTagID_TBL[@id] = self CTagID_TBL[@id] = self
$tk_canvas_tag = $tk_canvas_tag.succ Tk_CanvasTag_ID[0] = Tk_CanvasTag_ID[0].succ
if mode if mode
tk_call @c.path, "addtag", @id, mode, *args tk_call @c.path, "addtag", @id, mode, *args
end end
@ -572,15 +572,15 @@ class TkcTagCurrent<TkcTag
end end
class TkcGroup<TkcTag class TkcGroup<TkcTag
$tk_group_id = 'tkg00000' Tk_cGroup_ID = ['tkcg00000']
def create_self(parent, *args) def create_self(parent, *args)
if not parent.kind_of?(TkCanvas) if not parent.kind_of?(TkCanvas)
fail format("%s need to be TkCanvas", parent.inspect) fail format("%s need to be TkCanvas", parent.inspect)
end end
@c = parent @c = parent
@path = @id = $tk_group_id @path = @id = Tk_cGroup_ID[0]
CTagID_TBL[@id] = self CTagID_TBL[@id] = self
$tk_group_id = $tk_group_id.succ Tk_cGroup_ID[0] = Tk_cGroup_ID[0].succ
add(*args) if args != [] add(*args) if args != []
end end
@ -702,10 +702,10 @@ class TkImage<TkObject
Tk_IMGTBL = {} Tk_IMGTBL = {}
$tk_image_id = 'i00000' Tk_Image_ID = ['i00000']
def initialize(keys=nil) def initialize(keys=nil)
@path = $tk_image_id @path = Tk_Image_ID[0]
$tk_image_id = $tk_image_id.succ Tk_Image_ID[0] = Tk_Image_ID[0].succ
tk_call 'image', 'create', @type, @path, *hash_kv(keys) tk_call 'image', 'create', @type, @path, *hash_kv(keys)
Tk_IMGTBL[@path] = self Tk_IMGTBL[@path] = self
end end

View file

@ -123,30 +123,48 @@ end
class TkText<TkTextWin class TkText<TkTextWin
include TkTreatTextTagFont include TkTreatTextTagFont
include Scrollable
WidgetClassName = 'Text'.freeze WidgetClassName = 'Text'.freeze
WidgetClassNames[WidgetClassName] = self WidgetClassNames[WidgetClassName] = self
def self.to_eval def self.to_eval
WidgetClassName WidgetClassName
end end
include Scrollable
def create_self def self.new(*args)
tk_call 'text', @path obj = super(*args){}
obj.init_instance_variable
obj.instance_eval &block if defined? yield
obj
end
def init_instance_variable
@tags = {} @tags = {}
end end
def create_self
tk_call 'text', @path
init_instance_variable
end
def index(index) def index(index)
tk_send 'index', index tk_send 'index', index
end end
def value def value
tk_send 'get', "1.0", "end - 1 char" tk_send 'get', "1.0", "end - 1 char"
end end
def value= (val) def value= (val)
tk_send 'delete', "1.0", 'end' tk_send 'delete', "1.0", 'end'
tk_send 'insert', "1.0", val tk_send 'insert', "1.0", val
end end
def _addcmd(cmd) def _addcmd(cmd)
@cmdtbl.push cmd @cmdtbl.push cmd
end end
def _addtag(name, obj) def _addtag(name, obj)
@tags[name] = obj @tags[name] = obj
end end
@ -164,11 +182,19 @@ class TkText<TkTextWin
tagid2obj(elt) tagid2obj(elt)
} }
end end
def mark_names
tk_split_list(tk_send('mark', 'names')).collect{|elt|
tagid2obj(elt)
}
end
def window_names def window_names
tk_send('window', 'names').collect{|elt| tk_send('window', 'names').collect{|elt|
tagid2obj(elt) tagid2obj(elt)
} }
end end
def image_names def image_names
tk_send('image', 'names').collect{|elt| tk_send('image', 'names').collect{|elt|
tagid2obj(elt) tagid2obj(elt)
@ -178,6 +204,7 @@ class TkText<TkTextWin
def set_insert(index) def set_insert(index)
tk_send 'mark', 'set', 'insert', index tk_send 'mark', 'set', 'insert', index
end end
def set_current(index) def set_current(index)
tk_send 'mark', 'set', 'current', index tk_send 'mark', 'set', 'current', index
end end
@ -187,6 +214,7 @@ class TkText<TkTextWin
end end
def destroy def destroy
@tags = {} unless @tags
@tags.each_value do |t| @tags.each_value do |t|
t.destroy t.destroy
end end
@ -404,14 +432,15 @@ end
class TkTextTag<TkObject class TkTextTag<TkObject
include TkTreatTagFont include TkTreatTagFont
$tk_text_tag = 'tag0000' Tk_TextTag_ID = ['tag0000']
def initialize(parent, *args) def initialize(parent, *args)
if not parent.kind_of?(TkText) if not parent.kind_of?(TkText)
fail format("%s need to be TkText", parent.inspect) fail format("%s need to be TkText", parent.inspect)
end end
@parent = @t = parent @parent = @t = parent
@path = @id = $tk_text_tag @path = @id = Tk_TextTag_ID[0]
$tk_text_tag = $tk_text_tag.succ Tk_TextTag_ID[0] = Tk_TextTag_ID[0].succ
#tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
if args != [] then if args != [] then
keys = args.pop keys = args.pop
@ -537,14 +566,14 @@ class TkTextTagSel<TkTextTag
end end
class TkTextMark<TkObject class TkTextMark<TkObject
$tk_text_mark = 'mark0000' Tk_TextMark_ID = ['mark0000']
def initialize(parent, index) def initialize(parent, index)
if not parent.kind_of?(TkText) if not parent.kind_of?(TkText)
fail format("%s need to be TkText", parent.inspect) fail format("%s need to be TkText", parent.inspect)
end end
@t = parent @t = parent
@path = @id = $tk_text_mark @path = @id = Tk_TextMark_ID[0]
$tk_text_mark = $tk_text_mark.succ Tk_TextMark_ID[0] = Tk_TextMark_ID[0].succ
tk_call @t.path, 'mark', 'set', @id, index tk_call @t.path, 'mark', 'set', @id, index
@t._addtag id, self @t._addtag id, self
end end
@ -568,6 +597,14 @@ class TkTextMark<TkObject
def gravity=(direction) def gravity=(direction)
tk_call @t.path, 'mark', 'gravity', @id, direction tk_call @t.path, 'mark', 'gravity', @id, direction
end end
def next(index)
@t.tagid2obj(tk_call(@t.path, 'mark', 'next', index))
end
def previous(index)
@t.tagid2obj(tk_call(@t.path, 'mark', 'previous', index))
end
end end
class TkTextMarkInsert<TkTextMark class TkTextMarkInsert<TkTextMark

5
file.c
View file

@ -1245,7 +1245,7 @@ rb_file_s_expand_path(argc, argv)
p = &buf[strlen(buf)]; p = &buf[strlen(buf)];
while (p > buf && *(p - 1) == '/') p--; while (p > buf && *(p - 1) == '/') p--;
} }
else if (isdirsep(*s)) { else {
while (*s && isdirsep(*s)) { while (*s && isdirsep(*s)) {
*p++ = '/'; *p++ = '/';
s++; s++;
@ -1267,7 +1267,8 @@ rb_file_s_expand_path(argc, argv)
} }
else { else {
*++p = '.'; *++p = '.';
*++p = '.'; do *++p = '.'; while (*++s == '.');
--s;
} }
break; break;
case '/': case '/':

11
io.c
View file

@ -160,13 +160,11 @@ rb_io_check_writable(fptr)
} }
} }
void int
rb_read_check(fp) rb_read_pending(fp)
FILE *fp; FILE *fp;
{ {
if (!READ_DATA_PENDING(fp)) { return READ_DATA_PENDING(fp);
rb_thread_wait_fd(fileno(fp));
}
} }
/* writing functions */ /* writing functions */
@ -1076,6 +1074,9 @@ rb_io_sysread(io, len)
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
rb_io_check_readable(fptr); rb_io_check_readable(fptr);
if (READ_DATA_PENDING(fptr->f)) {
rb_raise(rb_eIOError, "sysread for buffered IO");
}
str = rb_str_new(0, ilen); str = rb_str_new(0, ilen);
rb_thread_wait_fd(fileno(fptr->f)); rb_thread_wait_fd(fileno(fptr->f));

View file

@ -20,7 +20,7 @@
# Complex::/ # Complex::/
# Complex::** # Complex::**
# Complex::% # Complex::%
# Complex::divmod # Complex::divmod -- obsolete
# Complex::abs # Complex::abs
# Complex::abs2 # Complex::abs2
# Complex::arg # Complex::arg
@ -51,6 +51,12 @@
def Complex(a, b = 0) def Complex(a, b = 0)
if a.kind_of?(Complex) and b == 0 if a.kind_of?(Complex) and b == 0
a a
elsif b.kind_of?(Complex)
if a.kind_of?(Complex)
Complex(a.real-b.image, a.image + b.real)
else
Complex(a-b.image, b.real)
end
elsif b == 0 and defined? Complex::Unify elsif b == 0 and defined? Complex::Unify
a a
else else
@ -181,18 +187,18 @@ class Complex < Numeric
end end
end end
def divmod(other) # def divmod(other)
if other.kind_of?(Complex) # if other.kind_of?(Complex)
rdiv, rmod = @real.divmod(other.real) # rdiv, rmod = @real.divmod(other.real)
idiv, imod = @image.divmod(other.image) # idiv, imod = @image.divmod(other.image)
return Complex(rdiv, idiv), Complex(rmod, rdiv) # return Complex(rdiv, idiv), Complex(rmod, rmod)
elsif Complex.generic?(other) # elsif Complex.generic?(other)
Complex(@real.divmod(other), @image.divmod(other)) # Complex(@real.divmod(other), @image.divmod(other))
else # else
x , y = other.coerce(self) # x , y = other.coerce(self)
x.divmod(y) # x.divmod(y)
end # end
end # end
def abs def abs
Math.sqrt!((@real*@real + @image*@image).to_f) Math.sqrt!((@real*@real + @image*@image).to_f)

View file

@ -27,7 +27,7 @@ module ParseDate
if date.sub!(/(#{DAYPAT})[a-z]*,?/i, ' ') if date.sub!(/(#{DAYPAT})[a-z]*,?/i, ' ')
wday = DAYS[$1.downcase] wday = DAYS[$1.downcase]
end end
if date.sub!(/(\d+):(\d+)(?::(\d+))?(?:\s*(am|pm))?(?:\s+([a-z]{1,4}(?:\s+[a-z]{1,4})?|[-+]\d{4}))?/i, ' ') if date.sub!(/(\d+):(\d+)(?::(\d+))?(?:\s*(am|pm))?(?:\s+([a-z]{1,4}(?:\s+[a-z]{1,4}|[-+]\d{4})?))?/i, ' ')
hour = $1.to_i hour = $1.to_i
min = $2.to_i min = $2.to_i
if $3 if $3

View file

@ -25,8 +25,6 @@
class TimeoutError<StandardError class TimeoutError<StandardError
end end
Thread.abort_on_exception = true
def timeout(sec) def timeout(sec)
begin begin
x = Thread.current x = Thread.current

View file

@ -224,7 +224,7 @@ w_object(obj, arg, limit)
int limit; int limit;
{ {
struct dump_call_arg c_arg; struct dump_call_arg c_arg;
st_table *ivtbl = 0;; st_table *ivtbl = 0;
if (limit == 0) { if (limit == 0) {
rb_raise(rb_eRuntimeError, "exceed depth limit"); rb_raise(rb_eRuntimeError, "exceed depth limit");
@ -397,7 +397,7 @@ w_object(obj, arg, limit)
} }
path = rb_class2name(klass); path = rb_class2name(klass);
w_unique(path, arg); w_unique(path, arg);
w_ivar(ROBJECT(obj)->iv_tbl); w_ivar(ROBJECT(obj)->iv_tbl, &c_arg);
} }
break; break;

View file

@ -1,3 +1,15 @@
#ifdef _MSC_VER
#include <float.h>
int
isnan(n)
double n;
{
return _isnan(n);
}
#else
static int double_ne(); static int double_ne();
int int
@ -14,3 +26,4 @@ double_ne(n1, n2)
{ {
return n1 != n2; return n1 != n2;
} }
#endif

3
node.h
View file

@ -84,6 +84,7 @@ enum node_type {
NODE_DREGX_ONCE, NODE_DREGX_ONCE,
NODE_ARGS, NODE_ARGS,
NODE_ARGSCAT, NODE_ARGSCAT,
NODE_ARGSPUSH,
NODE_RESTARGS, NODE_RESTARGS,
NODE_BLOCK_ARG, NODE_BLOCK_ARG,
NODE_BLOCK_PASS, NODE_BLOCK_PASS,
@ -114,6 +115,7 @@ enum node_type {
#ifdef C_ALLOCA #ifdef C_ALLOCA
NODE_ALLOCA, NODE_ALLOCA,
#endif #endif
NODE_MEMO,
}; };
typedef struct RNode { typedef struct RNode {
@ -290,6 +292,7 @@ typedef struct RNode {
#define NEW_ZSUPER() rb_node_newnode(NODE_ZSUPER,0,0,0) #define NEW_ZSUPER() rb_node_newnode(NODE_ZSUPER,0,0,0)
#define NEW_ARGS(f,o,r) rb_node_newnode(NODE_ARGS,o,r,f) #define NEW_ARGS(f,o,r) rb_node_newnode(NODE_ARGS,o,r,f)
#define NEW_ARGSCAT(a,b) rb_node_newnode(NODE_ARGSCAT,a,b,0) #define NEW_ARGSCAT(a,b) rb_node_newnode(NODE_ARGSCAT,a,b,0)
#define NEW_ARGSPUSH(a,b) rb_node_newnode(NODE_ARGSPUSH,a,b,0)
#define NEW_RESTARGS(a) rb_node_newnode(NODE_RESTARGS,a,0,0) #define NEW_RESTARGS(a) rb_node_newnode(NODE_RESTARGS,a,0,0)
#define NEW_BLOCK_ARG(v) rb_node_newnode(NODE_BLOCK_ARG,v,0,local_cnt(v)) #define NEW_BLOCK_ARG(v) rb_node_newnode(NODE_BLOCK_ARG,v,0,local_cnt(v))
#define NEW_BLOCK_PASS(b) rb_node_newnode(NODE_BLOCK_PASS,0,b,0) #define NEW_BLOCK_PASS(b) rb_node_newnode(NODE_BLOCK_PASS,0,b,0)

25
parse.y
View file

@ -3007,11 +3007,8 @@ yylex()
case ':': case ':':
c = nextc(); c = nextc();
if (c == ':') { if (c == ':') {
if (lex_state == EXPR_BEG || lex_state == EXPR_MID) { if (lex_state == EXPR_BEG || lex_state == EXPR_MID ||
lex_state = EXPR_BEG; (lex_state == EXPR_ARG && space_seen)) {
return tCOLON3;
}
if (lex_state == EXPR_ARG && space_seen) {
lex_state = EXPR_BEG; lex_state = EXPR_BEG;
return tCOLON3; return tCOLON3;
} }
@ -3284,7 +3281,7 @@ yylex()
tokfix(); tokfix();
{ {
int result; int result = 0;
switch (tok()[0]) { switch (tok()[0]) {
case '$': case '$':
@ -3312,22 +3309,25 @@ yylex()
} }
} }
if (ISUPPER(tok()[0])) { if (toklast() == '!' || toklast() == '?') {
result = tCONSTANT;
}
else if (toklast() == '!' || toklast() == '?') {
result = tFID; result = tFID;
} }
else { else {
result = tIDENTIFIER;
if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) { if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
if ((c = nextc()) == '=' && !peek('=')) { if ((c = nextc()) == '=' && !peek('=')) {
result = tIDENTIFIER;
tokadd(c); tokadd(c);
} }
else { else {
pushback(c); pushback(c);
} }
} }
if (result == 0 && ISUPPER(tok()[0])) {
result = tCONSTANT;
}
else {
result = tIDENTIFIER;
}
} }
if (lex_state == EXPR_BEG || if (lex_state == EXPR_BEG ||
lex_state == EXPR_DOT || lex_state == EXPR_DOT ||
@ -3841,6 +3841,7 @@ arg_concat(node1, node2)
NODE *node1; NODE *node1;
NODE *node2; NODE *node2;
{ {
if (!node2) return node1;
return NEW_ARGSCAT(node1, node2); return NEW_ARGSCAT(node1, node2);
} }
@ -3854,7 +3855,7 @@ arg_add(node1, node2)
return list_append(node1, node2); return list_append(node1, node2);
} }
else { else {
return NEW_ARGSCAT(node1, node2); return NEW_ARGSPUSH(node1, node2);
} }
} }

View file

@ -76,8 +76,8 @@ void srand48 _((long));
#endif /* not HAVE_DRAND48 */ #endif /* not HAVE_DRAND48 */
#ifdef HAVE_RANDOM
static int first = 1; static int first = 1;
#if !defined HAVE_DRAND48 && defined HAVE_RANDOM
static char state[256]; static char state[256];
#endif #endif
@ -88,15 +88,15 @@ rand_init(seed)
int old; int old;
static unsigned int saved_seed; static unsigned int saved_seed;
#ifdef HAVE_RANDOM #if !defined HAVE_DRAND48 && defined HAVE_RANDOM
if (first == 1) { if (first == 1) {
initstate(1, state, sizeof state); initstate(1, state, sizeof state);
first = 0;
} }
else { else {
setstate(state); setstate(state);
} }
#endif #endif
first = 0;
SRANDOM(seed); SRANDOM(seed);
old = saved_seed; old = saved_seed;
@ -135,8 +135,6 @@ rb_f_rand(obj, vmax)
{ {
long val, max; long val, max;
static initialized = 0;
if (first) { if (first) {
struct timeval tv; struct timeval tv;

View file

@ -58,6 +58,5 @@ void rb_io_synchronized _((OpenFile*));
void rb_io_check_closed _((OpenFile*)); void rb_io_check_closed _((OpenFile*));
void rb_eof_error _((void)); void rb_eof_error _((void));
void rb_read_check _((FILE*)); /* thread aware check */ int rb_read_pending _((FILE*));
#endif #endif

View file

@ -863,7 +863,7 @@ rb_str_replace(str, beg, len, val)
if (RSTRING(str)->len < beg && len < 0) { if (RSTRING(str)->len < beg && len < 0) {
MEMZERO(RSTRING(str)->ptr + RSTRING(str)->len, char, -len); MEMZERO(RSTRING(str)->ptr + RSTRING(str)->len, char, -len);
} }
memcpy(RSTRING(str)->ptr+beg, RSTRING(val)->ptr, RSTRING(val)->len); memmove(RSTRING(str)->ptr+beg, RSTRING(val)->ptr, RSTRING(val)->len);
RSTRING(str)->len += RSTRING(val)->len - len; RSTRING(str)->len += RSTRING(val)->len - len;
RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
} }
@ -2193,32 +2193,6 @@ rb_str_each_line(argc, argv, str)
return str; return str;
} }
#ifdef STR_TO_A_USE_EACH
static VALUE
to_a_push(str, ary)
VALUE str, ary;
{
return rb_ary_push(ary, str);
}
#endif
static VALUE
rb_str_to_a(str)
VALUE str;
{
#ifdef STR_TO_A_USE_EACH
VALUE ary;
if (RSTRING(str)->len == 0) return rb_ary_new3(1, str);
ary = rb_ary_new();
rb_iterate(rb_each, str, to_a_push, ary);
return ary;
#else
return rb_ary_new3(1, str);
#endif
}
static VALUE static VALUE
rb_str_each_byte(str) rb_str_each_byte(str)
VALUE str; VALUE str;
@ -2652,7 +2626,6 @@ Init_String()
rb_define_method(rb_cString, "to_i", rb_str_to_i, 0); rb_define_method(rb_cString, "to_i", rb_str_to_i, 0);
rb_define_method(rb_cString, "to_f", rb_str_to_f, 0); rb_define_method(rb_cString, "to_f", rb_str_to_f, 0);
rb_define_method(rb_cString, "to_a", rb_str_to_a, 0);
rb_define_method(rb_cString, "to_s", rb_str_to_s, 0); rb_define_method(rb_cString, "to_s", rb_str_to_s, 0);
rb_define_method(rb_cString, "to_str", rb_str_to_s, 0); rb_define_method(rb_cString, "to_str", rb_str_to_s, 0);
rb_define_method(rb_cString, "inspect", rb_str_inspect, 0); rb_define_method(rb_cString, "inspect", rb_str_inspect, 0);

View file

@ -1,4 +1,4 @@
#define RUBY_VERSION "1.5.0" #define RUBY_VERSION "1.5.2"
#define RUBY_RELEASE_DATE "2000-01-08" #define RUBY_RELEASE_DATE "2000-01-17"
#define RUBY_VERSION_CODE 150 #define RUBY_VERSION_CODE 152
#define RUBY_RELEASE_CODE 20000108 #define RUBY_RELEASE_CODE 20000117