From ab801dbdb7ff8a99b5e0976516b879b27bcf3e1b Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 3 Jul 1998 07:06:51 +0000 Subject: 1.1b9_29 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 37 ++++ MANIFEST | 1 + bignum.c | 40 ++-- configure | 4 +- configure.in | 4 +- enum.c | 8 +- eval.c | 19 +- ext/socket/socket.c | 2 +- hash.c | 2 +- io.c | 34 ++-- lib/mkmf.rb | 2 +- lib/readbytes.rb | 36 ++++ lib/tk.rb | 82 ++++---- lib/tkafter.rb | 76 ++++--- lib/tkcanvas.rb | 560 +++++++++++++++++++++++++++++++++++++++++----------- lib/tkentry.rb | 24 +-- lib/tktext.rb | 242 +++++++++++++++++++++-- marshal.c | 23 +-- missing/nt.h | 2 +- numeric.c | 130 ++++++------ object.c | 2 +- process.c | 31 ++- sample/test.rb | 14 +- sprintf.c | 9 +- version.h | 4 +- 25 files changed, 1037 insertions(+), 351 deletions(-) create mode 100644 lib/readbytes.rb diff --git a/ChangeLog b/ChangeLog index b9fbf551b4..53ec606730 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,40 @@ +Fri Jul 3 16:05:11 1998 Yukihiro Matsumoto + + * experimental release 1.1b9_29. + +Fri Jul 3 11:20:46 1998 Yukihiro Matsumoto + + * marshal.c (r_byte): byte should not extend sign bit. + + * numeric.c (fix_mul): use FIX2LONG() instead of FIX2INT() for + 64bit architectures. + + * marshal.c (r_bytes): use weird casting bwetween pointer and int. + + * process.c (proc_setsid): new method Process#setsid(). + +Thu Jul 2 12:49:21 1998 Yukihiro Matsumoto + + * marshal.c (w_object): remove `write_bignum' label for 64bit + architectures. + + * marshal.c (r_bytes): needs int, not long. + +Wed Jul 1 14:21:06 1998 Yukihiro Matsumoto + + * numeric.c (flo_plus): should not allow addition with strings. + +Wed Jul 1 13:09:01 1998 Keiju ISHITSUKA + + * numeric.c (num_uminus): wrong coerce direction. + +Tue Jun 30 10:13:44 1998 Yukihiro Matsumoto + + * io.c (f_p): accepts arbitrary number of arguments. + + * eval.c (rb_yield_0): there's some case that iterator_p() returns + true even if the_block was not set. check added. + Tue Jun 30 01:05:20 1998 Yukihiro Matsumoto * eval.c (BEGIN_CALLARGS): adjust the_block before evaluating the diff --git a/MANIFEST b/MANIFEST index 5863d5db70..199e11af99 100644 --- a/MANIFEST +++ b/MANIFEST @@ -115,6 +115,7 @@ lib/parsedate.rb lib/ping.rb lib/pstore.rb lib/rational.rb +lib/readbytes.rb lib/shellwords.rb lib/sync.rb lib/telnet.rb diff --git a/bignum.c b/bignum.c index dc0c5492d1..ec16c991ea 100644 --- a/bignum.c +++ b/bignum.c @@ -20,7 +20,7 @@ typedef unsigned short USHORT; #define BIGRAD (1L << BITSPERDIG) #define DIGSPERINT ((unsigned int)(sizeof(long)/sizeof(short))) #define BIGUP(x) ((unsigned int)(x) << BITSPERDIG) -#define BIGDN(x) RSHIFT((x),BITSPERDIG) +#define BIGDN(x) (((x)<0) ? ~((~(x))>>BITSPERDIG) : (x)>>BITSPERDIG) #define BIGLO(x) ((x) & (BIGRAD-1)) static VALUE @@ -61,7 +61,7 @@ big_2comp(x) /* get 2's complement */ while (i--) ds[i] = ~ds[i]; i = 0; num = 1; do { - num += (long)ds[i]; + num += ds[i]; ds[i++] = BIGLO(num); num = BIGDN(num); } while (i < RBIGNUM(x)->len); @@ -441,7 +441,7 @@ big_cmp(x, y) switch (TYPE(y)) { case T_FIXNUM: - y = int2big(FIX2INT(y)); + y = int2big(FIX2LONG(y)); break; case T_BIGNUM: @@ -585,7 +585,7 @@ bigadd(x, y, sign) len = RBIGNUM(x)->len; for (i = 0, num = 0; i < len; i++) { - num += (long)(BDIGITS(x)[i] + BDIGITS(y)[i]); + num += BDIGITS(x)[i] + BDIGITS(y)[i]; BDIGITS(z)[i] = BIGLO(num); num = BIGDN(num); } @@ -610,7 +610,7 @@ big_plus(x, y) { switch (TYPE(y)) { case T_FIXNUM: - y = int2big(FIX2INT(y)); + y = int2big(FIX2LONG(y)); /* fall through */ case T_BIGNUM: return bigadd(x, y, 1); @@ -629,7 +629,7 @@ big_minus(x, y) { switch (TYPE(y)) { case T_FIXNUM: - y = int2big(FIX2INT(y)); + y = int2big(FIX2LONG(y)); /* fall through */ case T_BIGNUM: return bigadd(x, y, 0); @@ -651,10 +651,10 @@ big_mul(x, y) VALUE z; USHORT *zds; - if (FIXNUM_P(x)) x = int2big(FIX2INT(x)); + if (FIXNUM_P(x)) x = int2big(FIX2LONG(x)); switch (TYPE(y)) { case T_FIXNUM: - y = int2big(FIX2INT(y)); + y = int2big(FIX2LONG(y)); break; case T_BIGNUM: @@ -737,7 +737,7 @@ bigdivmod(x, y, div, mod, modulo) j = 0; num = 0; while (j 0) goto pos_big; - d = (double)FIX2INT(y); + if (FIX2LONG(y) > 0) goto pos_big; + d = (double)FIX2LONG(y); break; default: @@ -964,7 +964,7 @@ big_and(x, y) char sign; if (FIXNUM_P(y)) { - y = int2big(FIX2INT(y)); + y = int2big(FIX2LONG(y)); } else { Check_Type(y, T_BIGNUM); @@ -1015,7 +1015,7 @@ big_or(x, y) char sign; if (FIXNUM_P(y)) { - y = int2big(FIX2INT(y)); + y = int2big(FIX2LONG(y)); } else { Check_Type(y, T_BIGNUM); @@ -1067,7 +1067,7 @@ big_xor(x, y) char sign; if (FIXNUM_P(y)) { - y = int2big(FIX2INT(y)); + y = int2big(FIX2LONG(y)); } else { Check_Type(y, T_BIGNUM); @@ -1219,7 +1219,7 @@ big_coerce(x, y) VALUE x, y; { if (FIXNUM_P(y)) { - return assoc_new(int2big(FIX2INT(y)), x); + return assoc_new(int2big(FIX2LONG(y)), x); } else { TypeError("can't coerce %s to Bignum", rb_class2name(CLASS_OF(y))); diff --git a/configure b/configure index a8233bb955..00befc12b2 100644 --- a/configure +++ b/configure @@ -2694,7 +2694,7 @@ for ac_func in fmod killpg drand48 random wait4 waitpid syscall getcwd\ truncate chsize times utimes fcntl lockf setitimer\ setruid seteuid setreuid setrgid setegid setregid\ setpgrp2 getpgid getgroups getpriority\ - dlopen sigprocmask sigaction _setjmp setpgrp + dlopen sigprocmask sigaction _setjmp setpgrp setsid do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:2701: checking for $ac_func" >&5 @@ -3181,7 +3181,7 @@ else int main() { - if (-1==((-1)>>1)) + if (-1==(-1>>1)) return 0; return 1; } diff --git a/configure.in b/configure.in index 9d5c4ccb5c..f1f7bd00fb 100644 --- a/configure.in +++ b/configure.in @@ -164,7 +164,7 @@ AC_CHECK_FUNCS(fmod killpg drand48 random wait4 waitpid syscall getcwd\ truncate chsize times utimes fcntl lockf setitimer\ setruid seteuid setreuid setrgid setegid setregid\ setpgrp2 getpgid getgroups getpriority\ - dlopen sigprocmask sigaction _setjmp setpgrp) + dlopen sigprocmask sigaction _setjmp setpgrp setsid) if test "$ac_cv_func_strftime" = no; then AC_STRUCT_TIMEZONE AC_TRY_LINK([], @@ -237,7 +237,7 @@ AC_CACHE_VAL(rb_cv_rshift_sign, int main() { - if (-1==((-1)>>1)) + if (-1==(-1>>1)) return 0; return 1; } diff --git a/enum.c b/enum.c index 1e0ec9c30d..4cf490e4ca 100644 --- a/enum.c +++ b/enum.c @@ -198,7 +198,7 @@ min_i(i, min) *min = i; else { cmp = rb_funcall(i, id_cmp, 1, *min); - if (FIX2INT(cmp) < 0) + if (FIX2LONG(cmp) < 0) *min = i; } return Qnil; @@ -214,7 +214,7 @@ min_ii(i, min) *min = i; else { cmp = rb_yield(assoc_new(i, *min)); - if (FIX2INT(cmp) < 0) + if (FIX2LONG(cmp) < 0) *min = i; } return Qnil; @@ -240,7 +240,7 @@ max_i(i, max) *max = i; else { cmp = rb_funcall(i, id_cmp, 1, *max); - if (FIX2INT(cmp) > 0) + if (FIX2LONG(cmp) > 0) *max = i; } return Qnil; @@ -256,7 +256,7 @@ max_ii(i, max) *max = i; else { cmp = rb_yield(assoc_new(i, *max)); - if (FIX2INT(cmp) > 0) + if (FIX2LONG(cmp) > 0) *max = i; } return Qnil; diff --git a/eval.c b/eval.c index f7852cbefb..a24ffc5872 100644 --- a/eval.c +++ b/eval.c @@ -981,27 +981,27 @@ ruby_run() case TAG_RETURN: error_pos(); - fprintf(stderr, "unexpected return\n"); + fprintf(stderr, ": unexpected return\n"); exit(1); break; case TAG_NEXT: error_pos(); - fprintf(stderr, "unexpected next\n"); + fprintf(stderr, ": unexpected next\n"); exit(1); break; case TAG_BREAK: error_pos(); - fprintf(stderr, "unexpected break\n"); + fprintf(stderr, ": unexpected break\n"); exit(1); break; case TAG_REDO: error_pos(); - fprintf(stderr, "unexpected redo\n"); + fprintf(stderr, ": unexpected redo\n"); exit(1); break; case TAG_RETRY: error_pos(); - fprintf(stderr, "retry outside of rescue clause\n"); + fprintf(stderr, ": retry outside of rescue clause\n"); exit(1); break; case TAG_RAISE: @@ -2340,6 +2340,9 @@ rb_eval(self, node) VALUE origin; int noex; + if (the_class == cObject && node->nd_mid == init) { + Warn("re-defining Object#initialize may cause infinite loop"); + } body = search_method(the_class, node->nd_mid, &origin); if (body) { if (origin == the_class) { @@ -2844,7 +2847,7 @@ rb_yield_0(val, self) int state; static unsigned serial = 1; - if (!iterator_p()) { + if (!iterator_p() || !the_block) { Raise(eLocalJumpError, "yield called out of iterator"); } @@ -6220,12 +6223,12 @@ thread_create(fn, arg) tval.it_interval.tv_usec = 100000; tval.it_value = tval.it_interval; setitimer(ITIMER_VIRTUAL, &tval, NULL); - +#if 1 tval.it_interval.tv_sec = 2; /* unblock system calls */ tval.it_interval.tv_usec = 0; tval.it_value = tval.it_interval; setitimer(ITIMER_REAL, &tval, NULL); - +#endif init = 1; } #endif diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 18ab8bc9f6..d235da1b83 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -1367,7 +1367,7 @@ sock_s_gethostbyaddr(argc, argv) int alen; struct hostent *h; - rb_scan_args(argc, argv, "11", &addr, &vtype); + rb_scan_args(argc, argv, "11", &vaddr, &vtype); addr = str2cstr(vaddr, &alen); if (!NIL_P(vtype)) { type = NUM2INT(vtype); diff --git a/hash.c b/hash.c index a1da061bd8..2c4616f2f0 100644 --- a/hash.c +++ b/hash.c @@ -103,7 +103,7 @@ any_hash(a, mod) hval = rb_funcall(hval, '%', 1, INT2FIX(65439)); } ENABLE_INTS; - hval = FIX2INT(hval); + hval = FIX2LONG(hval); } return hval % mod; } diff --git a/io.c b/io.c index 8349da0be8..826c0f0238 100644 --- a/io.c +++ b/io.c @@ -512,7 +512,10 @@ io_gets_method(argc, argv, io) TRAP_BEG; c = getc(f); TRAP_END; - if (c == EOF) break; + if (c == EOF) { + if (errno == EINTR) continue; + break; + } if ((*bp++ = c) == newline) break; if (bp == bpe) break; } @@ -599,7 +602,10 @@ io_gets(io) TRAP_BEG; c = getc(f); TRAP_END; - if (c == EOF) break; + if (c == EOF) { + if (errno == EINTR) continue; + break; + } if ((*bp++ = c) == '\n') break; if (bp == bpe) break; } @@ -1599,21 +1605,25 @@ f_puts(argc, argv) return Qnil; } -static VALUE -f_p(self, obj) - VALUE self, obj; +void +rb_p(obj) /* for debug print within C code */ + VALUE obj; { io_write(rb_defout, rb_inspect(obj)); io_write(rb_defout, RS_default); - - return Qnil; } -void -rb_p(obj) /* for debug print within C code */ - VALUE obj; +static VALUE +f_p(argc, argv) + int argc; + VALUE *argv; { - f_p(0, obj); + int i; + + for (i=0; i +# 1998/07/02 by Hidetoshi Nagai # require 'tk' @@ -20,10 +20,9 @@ class TkAfter @after_id = nil arg = Array(tk_split_list(arg)) obj_id = arg.shift - return nil if Tk_CBTBL[obj_id] == nil; # canceled - ret = _get_eval_string(Tk_CBTBL[obj_id].do_callback(*arg)) - Tk_CBTBL[obj_id].set_next_callback(*arg) - ret + ex_obj = Tk_CBTBL[obj_id] + return nil if ex_obj == nil; # canceled + _get_eval_string(ex_obj.do_callback(*arg)) end def TkAfter.info @@ -37,7 +36,15 @@ class TkAfter # instance methods ############################### def do_callback(*args) - @current_proc.call(*args) + @in_callback = true + ret = @current_proc.call(*args) + if @set_next + set_next_callback(*args) + else + @set_next = true + end + @in_callback = false + ret end def set_callback(sleep, args=nil) @@ -49,6 +56,7 @@ class TkAfter def set_next_callback(*args) if @running == false || @proc_max == 0 || @do_loop == 0 Tk_CBTBL[@id] = nil ;# for GC + @running = false return end if @current_pos >= @proc_max @@ -56,6 +64,7 @@ class TkAfter @current_pos = 0 else Tk_CBTBL[@id] = nil ;# for GC + @running = false return end end @@ -88,9 +97,11 @@ class TkAfter @id = format("a%.4d", Tk_CBID[0]) Tk_CBID[0] += 1 - @init_sleep=0 - @init_proc=nil - @init_args=[] + @set_next = true + + @init_sleep = 0 + @init_proc = nil + @init_args = [] @current_script = [] @current_proc = nil @@ -188,37 +199,56 @@ class TkAfter self end - def start(sleep=0, init_proc=nil, *init_args) + def set_start_proc(sleep, init_proc, *init_args) + if !sleep == 'idle' && !sleep.kind_of?(Integer) + fail format("%s need to be Integer", sleep.inspect) + end + @init_proc = init_proc + @init_args = init_args + self + end + + def start(*init_args) return nil if @running Tk_CBTBL[@id] = self @do_loop = @loop_exec @current_pos = 0 - if !sleep == 'idle' && !sleep.kind_of?(Integer) - fail format("%s need to be Integer", sleep.inspect) + argc = init_args.size + if argc > 0 + sleep = init_args.shift + if !sleep == 'idle' && !sleep.kind_of?(Integer) + fail format("%s need to be Integer", sleep.inspect) + end + @init_sleep = sleep end + @init_proc = init_args.shift if argc > 1 + @init_args = init_args if argc > 0 - @init_proc = init_proc - @init_args = init_args - @current_sleep = @init_sleep = sleep + @current_sleep = @init_sleep @running = true - if init_proc - if not init_proc.kind_of? Proc - fail format("%s need to be Proc", init_proc.inspect) + if @init_proc + if not @init_proc.kind_of? Proc + fail format("%s need to be Proc", @init_proc.inspect) end - @current_proc = init_proc - set_callback(sleep, init_args) + @current_proc = @init_proc + set_callback(sleep, @init_args) + @set_next = false if @in_callback else - set_next_callback(*init_args) + set_next_callback(*@init_args) end self end - def restart + def restart(*restart_args) cancel if @running - start(@init_sleep, @init_proc, @init_args) + if restart_args == [] + start(@init_sleep, @init_proc, *@init_args) + else + start(*restart_args) + end end def cancel diff --git a/lib/tkcanvas.rb b/lib/tkcanvas.rb index a02db097fd..1d4c4c583a 100644 --- a/lib/tkcanvas.rb +++ b/lib/tkcanvas.rb @@ -2,6 +2,8 @@ # tkcanvas.rb - Tk canvas classes # $Date$ # by Yukihiro Matsumoto +# $Date$ +# by Hidetoshi Nagai require "tk" @@ -9,107 +11,224 @@ class TkCanvas", id - @cmdtbl.push id + + def itembind(tag, context, cmd=Proc.new, args=nil) + context = context.join("><") if context.kind_of? Array + if /,/ =~ context + context = context.split(/\s*,\s*/).join("><") + end + id = install_bind(cmd, args) + begin + tk_send 'bind', tagid(tag), "<#{context}>", id + rescue + uninstall_cmd(cmd) + fail + end + # @cmdtbl.push id end + def canvasx(x, *args) - tk_send 'canvasx', x, *args + tk_tcl2ruby(tk_send 'canvasx', x, *args) end def canvasy(y, *args) - tk_send 'canvasy', y, *args + tk_tcl2ruby(tk_send 'canvasy', y, *args) end + def coords(tag, *args) - tk_send 'coords', tagid(tag), *args + if args == [] + tk_split_list(tk_send('coords', tagid(tag))) + else + tk_send('coords', tagid(tag), *args) + end end + def dchars(tag, first, last=None) tk_send 'dchars', tagid(tag), first, last end + def delete(*args) tk_send 'delete', *args end alias remove delete + def dtag(tag, tag_to_del=None) tk_send 'dtag', tagid(tag), tag_to_del end - def find(*args) - tk_send 'find', *args + + def find(mode, *args) + list(tk_send 'find', mode, *args).filter{|id| + TkcItem.id2obj(id) + } + end + def find_above(target) + find('above', tagid(target)) + end + def find_all + find('all') + end + def find_below(target) + find('below', tagid(target)) + end + def find_closest(x, y, halo=None, start=None) + find('closest', x, y, halo, start) + end + def find_enclosed(x1, y1, x2, y2) + find('enclosed', x1, y1, x2, y2) + end + def find_overlapping(x1, y1, x2, y2) + find('overlapping', x1, y1, x2, y2) + end + def find_withtag(tag) + find('withtag', tag) + end + + def itemfocus(tagOrId=nil) + if tagOrId + tk_send 'focus', tagid(tagOrId) + else + ret = tk_send('focus') + if ret == "" + nil + else + TkcItem.id2obj(ret) + end + end + end + + def gettags(tagOrId) + list(tk_send('gettags', tagid(tagOrId))).collect{|tag| + TkcTag.id2obj(tag) + } + end + + def icursor(tagOrId, index) + tk_send 'icursor', tagid(tagOrId), index + end + + def index(tagOrId, index) + tk_send 'index', tagid(tagOrId), index end - def itemfocus(tag) - tk_send 'find', tagid(tag) + + def insert(tagOrId, index, string) + tk_send 'insert', tagid(tagOrId), index, string end - def gettags(tag) - tk_send 'gettags', tagid(tag) + + def itemcget(tagOrId, option) + tk_send 'itemcget', tagid(tagOrId), option end - def icursor(tag, index) - tk_send 'icursor', tagid(tag), index + + def itemconfigure(tagOrId, key, value=None) + if key.kind_of? Hash + tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key) + else + tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value + end end - def index(tag) - tk_send 'index', tagid(tag), index +# def itemconfigure(tagOrId, keys) +# tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(keys) +# end + + def itemconfiginfo(tagOrId, key=nil) + if key + conf = tk_split_list(tk_send 'itemconfigure', tagid(tagOrId), "-#{key}") + conf[0] = conf[0][1..-1] + conf + else + tk_split_list(tk_send 'itemconfigure', tagid(tagOrId)).collect{|conf| + conf[0] = conf[0][1..-1] + conf + } + end end - def lower(tag, below=None) + + def lower(tag, below=None) tk_send 'lower', tagid(tag), below end + def move(tag, x, y) tk_send 'move', tagid(tag), x, y end - def itemtype(tag) - tk_send 'type', tagid(tag) - end + def postscript(keys) tk_send "postscript", *hash_kv(keys) end + def raise(tag, above=None) tk_send 'raise', tagid(tag), above end + def scale(tag, x, y, xs, ys) tk_send 'scale', tagid(tag), x, y, xs, ys end + def scan_mark(x, y) tk_send 'scan', 'mark', x, y end def scan_dragto(x, y) tk_send 'scan', 'dragto', x, y end - def select(*args) - tk_send 'select', *args + + def select(mode, *args) + tk_send 'select', mode, *args + end + def select_adjust(tagOrId, index) + select('adjust', tagid(tagOrId), index) + end + def select_clear + select('clear') + end + def select_from(tagOrId, index) + select('from', tagid(tagOrId), index) + end + def select_item + select('item') end + def select_to(tagOrId, index) + select('to', tagid(tagOrId), index) + end + + def itemtype(tag) + TkcItem.type2class(tk_send 'type', tagid(tag)) + end + def xview(*index) tk_send 'xview', *index end @@ -118,168 +237,337 @@ class TkCanvas<") if seq.kind_of? Array + if /,/ =~ seq + seq = seq.split(/\s*,\s*/).join("><") + end + id = install_bind(cmd, args) + tk_send 'tag', 'bind', tag, "<#{seq}>", id + # _addcmd cmd + end + + def tag_bindinfo(tag) + tk_split_list(tk_send('tag', 'bind', tag)).filter{|seq| + seq.tr('<>',' ').strip.gsub(/\s+/,',') + } + end + + def tag_cget(tag, key) + tk_call @t.path, 'tag', 'cget', tag, "-#{key}" + end + + def tag_configure(tag, key, val=None) + if key.kind_of? Hash + tk_send 'tag', 'configure', tag, *hash_kv(key) + else + tk_send 'tag', 'configure', tag, "-#{key}", val + end + end + + def configinfo(tag, key=nil) + if key + conf = tk_split_list(tk_send('tag','configure',tag,"-#{key}")) + conf[0] = conf[0][1..-1] + conf + else + tk_split_list(tk_send('tag', 'configure', tag)).collect{|conf| + conf[0] = conf[0][1..-1] + conf + } + end + end + + def tag_raise(tag, above=None) + tk_send 'tag', 'raise', tag, above + end + + def tag_lower(tag, below=None) + tk_send 'tag', 'lower', tag, below + end + + def tag_remove(tag, *index) + tk_send 'tag', 'remove', tag, *index + end + + def tag_ranges(tag) + l = tk_split_list(tk_send('tag', 'ranges', tag)) + r = [] + while key=l.shift + r.push [key, l.shift] + end + r + end + + def tag_nextrange(tag, first, last=None) + tk_split_list(tk_send('tag', 'nextrange', tag, first, last)) + end + + def tag_prevrange(tag, first, last=None) + tk_split_list(tk_send('tag', 'prevrange', tag, first, last)) + end + + def search_with_length(pat,start,stop=None) + pat = pat.char if pat.kind_of? Integer + if stop != None + return ["", 0] if compare(start,'>=',stop) + txt = get(start,stop) + if (pos = txt.index(pat)) + pos = txt[0..(pos-1)].split('').length if pos > 0 + if pat.kind_of? String + return [index(start + " + #{pos} chars"), pat.split('').length] + else + return [index(start + " + #{pos} chars"), $&.split('').length] + end + else + return ["", 0] + end + else + txt = get(start,'end - 1 char') + if (pos = txt.index(pat)) + pos = txt[0..(pos-1)].split('').length if pos > 0 + if pat.kind_of? String + return [index(start + " + #{pos} chars"), pat.split('').length] + else + return [index(start + " + #{pos} chars"), $&.split('').length] + end + else + txt = get('1.0','end - 1 char') + if (pos = txt.index(pat)) + pos = txt[0..(pos-1)].split('').length if pos > 0 + if pat.kind_of? String + return [index("1.0 + #{pos} chars"), pat.split('').length] + else + return [index("1.0 + #{pos} chars"), $&.split('').length] + end + else + return ["", 0] + end + end + end + end + + def search(pat,start,stop=None) + search_with_length(pat,start,stop)[0] + end + + def rsearch_with_length(pat,start,stop=None) + pat = pat.char if pat.kind_of? Integer + if stop != None + return ["", 0] if compare(start,'<=',stop) + txt = get(stop,start) + if (pos = txt.rindex(pat)) + pos = txt[0..(pos-1)].split('').length if pos > 0 + if pat.kind_of? String + return [index(stop + " + #{pos} chars"), pat.split('').length] + else + return [index(stop + " + #{pos} chars"), $&.split('').length] + end + else + return ["", 0] + end + else + txt = get('1.0',start) + if (pos = txt.rindex(pat)) + pos = txt[0..(pos-1)].split('').length if pos > 0 + if pat.kind_of? String + return [index("1.0 + #{pos} chars"), pat.split('').length] + else + return [index("1.0 + #{pos} chars"), $&.split('').length] + end + else + txt = get('1.0','end - 1 char') + if (pos = txt.rindex(pat)) + pos = txt[0..(pos-1)].split('').length if pos > 0 + if pat.kind_of? String + return [index("1.0 + #{pos} chars"), pat.split('').length] + else + return [index("1.0 + #{pos} chars"), $&.split('').length] + end + else + return ["", 0] + end + end + end + end + + def rsearch(pat,start,stop=None) + rsearch_with_length(pat,start,stop)[0] + end end class TkTextTag<") if seq.kind_of? Array + if /,/ =~ seq + seq = seq.split(/\s*,\s*/).join("><") + end id = install_bind(cmd, args) tk_call @t.path, 'tag', 'bind', @id, "<#{seq}>", id - @t._addcmd cmd + # @t._addcmd cmd + end + + def bindinfo + tk_split_list(tk_call(@t.path, 'tag', 'bind', @id)).filter{|seq| + seq.tr('<>',' ').strip.gsub(/\s+/,',') + } end def raise(above=None) @@ -307,12 +495,23 @@ class TkTextWindow 0 + tk_call @t.path, 'window', 'configure', @index, *hash_kv(slot) + end else - tk_call @t.path, 'window', 'configure', @index, "-#{slot}", value + @id = value if slot == 'window' + if slot == 'create' + self.create=value + else + tk_call @t.path, 'window', 'configure', @index, "-#{slot}", value + end end end @@ -386,9 +585,16 @@ class TkTextImagedata, obj, &num)) { w_byte(TYPE_LINK, arg); w_long(num, arg); @@ -339,7 +339,7 @@ w_object(obj, arg, limit) Fatal("non-initialized struct"); } for (i=0; iptr[i]), arg); + w_symbol(FIX2LONG(RARRAY(mem)->ptr[i]), arg); w_object(RSTRUCT(obj)->ptr[i], arg, limit); } } @@ -456,7 +456,7 @@ r_byte(arg) struct load_arg *arg; { if (arg->fp) return getc(arg->fp); - if (arg->ptr < arg->end) return *arg->ptr++; + if (arg->ptr < arg->end) return *(unsigned char*)arg->ptr++; return EOF; } @@ -511,8 +511,9 @@ r_long(arg) return x; } +static long blen; /* hidden length register */ #define r_bytes(s, arg) \ - (s = (char*)r_long(arg), r_bytes0(&s,ALLOCA_N(char,(long)s),(long)s,arg)) + (blen = r_long(arg), r_bytes0(&s,ALLOCA_N(char,blen),blen,arg)) static int r_bytes0(sp, s, len, arg) diff --git a/missing/nt.h b/missing/nt.h index a571570c43..be8d61fc41 100644 --- a/missing/nt.h +++ b/missing/nt.h @@ -221,7 +221,7 @@ extern char *mystrerror(int); #define EWOULDBLOCK 10035 /* EBASEERR + 35 (winsock.h) */ #endif -#define O_BINMODE 0x8000 +#define O_BINARY 0x8000 #ifdef popen #undef popen diff --git a/numeric.c b/numeric.c index 58dbfe3742..58c3eaab80 100644 --- a/numeric.c +++ b/numeric.c @@ -100,7 +100,7 @@ num_uminus(num) VALUE zero; zero = INT2FIX(0); - do_coerce(&num, &zero); + do_coerce(&zero, &num); return rb_funcall(zero, '-', 1, num); } @@ -227,13 +227,11 @@ flo_plus(x, y) { switch (TYPE(y)) { case T_FIXNUM: - return float_new(RFLOAT(x)->value + (double)FIX2INT(y)); + return float_new(RFLOAT(x)->value + (double)FIX2LONG(y)); case T_BIGNUM: return float_new(RFLOAT(x)->value + big2dbl(y)); case T_FLOAT: return float_new(RFLOAT(x)->value + RFLOAT(y)->value); - case T_STRING: - return str_plus(obj_as_string(x), y); default: return num_coerce_bin(x, y); } @@ -245,7 +243,7 @@ flo_minus(x, y) { switch (TYPE(y)) { case T_FIXNUM: - return float_new(RFLOAT(x)->value - (double)FIX2INT(y)); + return float_new(RFLOAT(x)->value - (double)FIX2LONG(y)); case T_BIGNUM: return float_new(RFLOAT(x)->value - big2dbl(y)); case T_FLOAT: @@ -261,13 +259,11 @@ flo_mul(x, y) { switch (TYPE(y)) { case T_FIXNUM: - return float_new(RFLOAT(x)->value * (double)FIX2INT(y)); + return float_new(RFLOAT(x)->value * (double)FIX2LONG(y)); case T_BIGNUM: return float_new(RFLOAT(x)->value * big2dbl(y)); case T_FLOAT: return float_new(RFLOAT(x)->value * RFLOAT(y)->value); - case T_STRING: - return str_times(y, INT2FIX((int)RFLOAT(x)->value)); default: return num_coerce_bin(x, y); } @@ -282,7 +278,7 @@ flo_div(x, y) switch (TYPE(y)) { case T_FIXNUM: - f_y = FIX2INT(y); + f_y = FIX2LONG(y); if (f_y == 0) num_zerodiv(); return float_new(RFLOAT(x)->value / (double)f_y); case T_BIGNUM: @@ -306,7 +302,7 @@ flo_modulo(x, y, modulo) switch (TYPE(y)) { case T_FIXNUM: - value = (double)FIX2INT(y); + value = (double)FIX2LONG(y); break; case T_BIGNUM: value = big2dbl(y); @@ -356,7 +352,7 @@ flo_pow(x, y) { switch (TYPE(y)) { case T_FIXNUM: - return float_new(pow(RFLOAT(x)->value, (double)FIX2INT(y))); + return float_new(pow(RFLOAT(x)->value, (double)FIX2LONG(y))); case T_BIGNUM: return float_new(pow(RFLOAT(x)->value, big2dbl(y))); case T_FLOAT: @@ -389,7 +385,7 @@ flo_eq(x, y) { switch (TYPE(y)) { case T_FIXNUM: - if (RFLOAT(x)->value == FIX2INT(y)) return TRUE; + if (RFLOAT(x)->value == FIX2LONG(y)) return TRUE; return FALSE; case T_BIGNUM: return (RFLOAT(x)->value == big2dbl(y))?TRUE:FALSE; @@ -426,7 +422,7 @@ flo_cmp(x, y) a = RFLOAT(x)->value; switch (TYPE(y)) { case T_FIXNUM: - b = (double)FIX2INT(y); + b = (double)FIX2LONG(y); break; case T_BIGNUM: @@ -454,7 +450,7 @@ flo_gt(x, y) a = RFLOAT(x)->value; switch (TYPE(y)) { case T_FIXNUM: - b = (double)FIX2INT(y); + b = (double)FIX2LONG(y); break; case T_BIGNUM: @@ -480,7 +476,7 @@ flo_ge(x, y) a = RFLOAT(x)->value; switch (TYPE(y)) { case T_FIXNUM: - b = (double)FIX2INT(y); + b = (double)FIX2LONG(y); break; case T_BIGNUM: @@ -506,7 +502,7 @@ flo_lt(x, y) a = RFLOAT(x)->value; switch (TYPE(y)) { case T_FIXNUM: - b = (double)FIX2INT(y); + b = (double)FIX2LONG(y); break; case T_BIGNUM: @@ -532,7 +528,7 @@ flo_le(x, y) a = RFLOAT(x)->value; switch (TYPE(y)) { case T_FIXNUM: - b = (double)FIX2INT(y); + b = (double)FIX2LONG(y); break; case T_BIGNUM: @@ -668,7 +664,7 @@ num2long(val) switch (TYPE(val)) { case T_FIXNUM: - return FIX2INT(val); + return FIX2LONG(val); case T_FLOAT: if (RFLOAT(val)->value <= (double)LONG_MAX @@ -777,7 +773,7 @@ static VALUE fix_uminus(num) VALUE num; { - return int2inum(-FIX2INT(num)); + return int2inum(-FIX2LONG(num)); } VALUE @@ -814,18 +810,18 @@ fix_plus(x, y) long a, b, c; VALUE r; - a = FIX2INT(x); - b = FIX2INT(y); + a = FIX2LONG(x); + b = FIX2LONG(y); c = a + b; r = INT2FIX(c); - if (FIX2INT(r) != c) { + if (FIX2LONG(r) != c) { r = big_plus(int2big(a), int2big(b)); } return r; } case T_FLOAT: - return float_new((double)FIX2INT(x) + RFLOAT(y)->value); + return float_new((double)FIX2LONG(x) + RFLOAT(y)->value); default: return num_coerce_bin(x, y); } @@ -841,18 +837,18 @@ fix_minus(x, y) long a, b, c; VALUE r; - a = FIX2INT(x); - b = FIX2INT(y); + a = FIX2LONG(x); + b = FIX2LONG(y); c = a - b; r = INT2FIX(c); - if (FIX2INT(r) != c) { + if (FIX2LONG(r) != c) { r = big_minus(int2big(a), int2big(b)); } return r; } case T_FLOAT: - return float_new((double)FIX2INT(x) - RFLOAT(y)->value); + return float_new((double)FIX2LONG(x) - RFLOAT(y)->value); default: return num_coerce_bin(x, y); } @@ -868,20 +864,20 @@ fix_mul(x, y) long a, b, c; VALUE r; - a = FIX2INT(x); + a = FIX2LONG(x); if (a == 0) return x; - b = FIX2INT(y); + b = FIX2LONG(y); c = a * b; r = INT2FIX(c); - if (FIX2INT(r) != c || c/a != b) { + if (FIX2LONG(r) != c || c/a != b) { r = big_mul(int2big(a), int2big(b)); } return r; } case T_FLOAT: - return float_new((double)FIX2INT(x) * RFLOAT(y)->value); + return float_new((double)FIX2LONG(x) * RFLOAT(y)->value); default: return num_coerce_bin(x, y); } @@ -894,9 +890,9 @@ fix_div(x, y) long i; if (TYPE(y) == T_FIXNUM) { - i = FIX2INT(y); + i = FIX2LONG(y); if (i == 0) num_zerodiv(); - i = FIX2INT(x)/i; + i = FIX2LONG(x)/i; return INT2FIX(i); } return num_coerce_bin(x, y); @@ -909,13 +905,13 @@ fix_modulo(x, y, modulo) long i; if (TYPE(y) == T_FIXNUM) { - i = FIX2INT(y); + i = FIX2LONG(y); if (i == 0) num_zerodiv(); - i = FIX2INT(x)%i; + i = FIX2LONG(x)%i; if (modulo && - (FIX2INT(x) < 0) != (FIX2INT(y) < 0) && + (FIX2LONG(x) < 0) != (FIX2LONG(y) < 0) && i != 0) { - i += FIX2INT(y); + i += FIX2LONG(y); } return INT2FIX(i); } @@ -943,9 +939,9 @@ fix_pow(x, y) if (FIXNUM_P(y)) { long a, b; - b = FIX2INT(y); + b = FIX2LONG(y); if (b == 0) return INT2FIX(1); - a = FIX2INT(x); + a = FIX2LONG(x); if (b > 0) { return big_pow(int2big(a), y); } @@ -962,7 +958,7 @@ fix_equal(x, y) VALUE x, y; { if (FIXNUM_P(y)) { - return (FIX2INT(x) == FIX2INT(y))?TRUE:FALSE; + return (FIX2LONG(x) == FIX2LONG(y))?TRUE:FALSE; } else { return num_equal(x, y); @@ -974,7 +970,7 @@ fix_cmp(x, y) VALUE x, y; { if (FIXNUM_P(y)) { - long a = FIX2INT(x), b = FIX2INT(y); + long a = FIX2LONG(x), b = FIX2LONG(y); if (a == b) return INT2FIX(0); if (a > b) return INT2FIX(1); @@ -990,7 +986,7 @@ fix_gt(x, y) VALUE x, y; { if (FIXNUM_P(y)) { - long a = FIX2INT(x), b = FIX2INT(y); + long a = FIX2LONG(x), b = FIX2LONG(y); if (a > b) return TRUE; return FALSE; @@ -1005,7 +1001,7 @@ fix_ge(x, y) VALUE x, y; { if (FIXNUM_P(y)) { - long a = FIX2INT(x), b = FIX2INT(y); + long a = FIX2LONG(x), b = FIX2LONG(y); if (a >= b) return TRUE; return FALSE; @@ -1020,7 +1016,7 @@ fix_lt(x, y) VALUE x, y; { if (FIXNUM_P(y)) { - long a = FIX2INT(x), b = FIX2INT(y); + long a = FIX2LONG(x), b = FIX2LONG(y); if (a < b) return TRUE; return FALSE; @@ -1035,7 +1031,7 @@ fix_le(x, y) VALUE x, y; { if (FIXNUM_P(y)) { - long a = FIX2INT(x), b = FIX2INT(y); + long a = FIX2LONG(x), b = FIX2LONG(y); if (a <= b) return TRUE; return FALSE; @@ -1064,7 +1060,7 @@ fix_and(x, y) if (TYPE(y) == T_BIGNUM) { return big_and(y, x); } - val = FIX2INT(x) & NUM2INT(y); + val = FIX2LONG(x) & NUM2LONG(y); return int2inum(val); } @@ -1077,7 +1073,7 @@ fix_or(x, y) if (TYPE(y) == T_BIGNUM) { return big_or(y, x); } - val = FIX2INT(x) | NUM2INT(y); + val = FIX2LONG(x) | NUM2LONG(y); return int2inum(val); } @@ -1090,7 +1086,7 @@ fix_xor(x, y) if (TYPE(y) == T_BIGNUM) { return big_xor(y, x); } - val = FIX2INT(x) ^ NUM2INT(y); + val = FIX2LONG(x) ^ NUM2LONG(y); return int2inum(val); } @@ -1100,8 +1096,8 @@ fix_lshift(x, y) { long val, width; - val = NUM2INT(x); - width = NUM2INT(y); + val = NUM2LONG(x); + width = NUM2LONG(y); if (width > (sizeof(VALUE)*CHAR_BIT-1) || (unsigned)val>>(sizeof(VALUE)*CHAR_BIT-1-width) > 0) { return big_lshift(int2big(val), y); @@ -1116,9 +1112,9 @@ fix_rshift(x, y) { long i, val; - i = NUM2INT(y); + i = NUM2LONG(y); if (i < sizeof(long) * 8) { - val = RSHIFT(FIX2INT(x), i); + val = RSHIFT(FIX2LONG(x), i); return INT2FIX(val); } @@ -1129,8 +1125,8 @@ static VALUE fix_aref(fix, idx) VALUE fix, idx; { - unsigned long val = FIX2INT(fix); - int i = FIX2INT(idx); + unsigned long val = FIX2LONG(fix); + int i = FIX2LONG(idx); if (i < 0 || sizeof(VALUE)*CHAR_BIT-1 < i) return INT2FIX(0); @@ -1152,7 +1148,7 @@ fix_to_f(num) { double val; - val = (double)FIX2INT(num); + val = (double)FIX2LONG(num); return float_new(val); } @@ -1168,7 +1164,7 @@ static VALUE fix_abs(fix) VALUE fix; { - long i = FIX2INT(fix); + long i = FIX2LONG(fix); if (i < 0) i = -i; @@ -1188,7 +1184,7 @@ static VALUE fix_succ(fix) VALUE fix; { - long i = FIX2INT(fix) + 1; + long i = FIX2LONG(fix) + 1; return int2inum(i); } @@ -1274,8 +1270,8 @@ fix_upto(from, to) long i, end; if (!FIXNUM_P(to)) return num_upto(from, to); - end = FIX2INT(to); - for (i = FIX2INT(from); i <= end; i++) { + end = FIX2LONG(to); + for (i = FIX2LONG(from); i <= end; i++) { rb_yield(INT2FIX(i)); } @@ -1289,8 +1285,8 @@ fix_downto(from, to) long i, end; if (!FIXNUM_P(to)) return num_downto(from, to); - end = FIX2INT(to); - for (i=FIX2INT(from); i >= end; i--) { + end = FIX2LONG(to); + for (i=FIX2LONG(from); i >= end; i--) { rb_yield(INT2FIX(i)); } @@ -1306,19 +1302,19 @@ fix_step(from, to, step) if (!FIXNUM_P(to) || !FIXNUM_P(step)) return num_step(from, to, step); - end = FIX2INT(to); - diff = FIX2INT(step); + end = FIX2LONG(to); + diff = FIX2LONG(step); if (diff == 0) { ArgError("step cannot be 0"); } else if (diff > 0) { - for (i=FIX2INT(from); i <= end; i+=diff) { + for (i=FIX2LONG(from); i <= end; i+=diff) { rb_yield(INT2FIX(i)); } } else { - for (i=FIX2INT(from); i >= end; i+=diff) { + for (i=FIX2LONG(from); i >= end; i+=diff) { rb_yield(INT2FIX(i)); } } @@ -1331,7 +1327,7 @@ fix_dotimes(num) { long i, end; - end = FIX2INT(num); + end = FIX2LONG(num); for (i=0; i"bar"},2.5,fact(30)] +$y = Marshal.dump($x) +p $x +p Marshal.load($y) +ok($x == Marshal.load($y)) + check "pack" $format = "c2x5CCxsdila6"; diff --git a/sprintf.c b/sprintf.c index dac3659525..5bc530377c 100644 --- a/sprintf.c +++ b/sprintf.c @@ -311,13 +311,14 @@ f_sprintf(argc, argv) { volatile VALUE val = GETARG(); char fbuf[32], nbuf[64], *s, *t; - int v, base, bignum = 0; + long v; + int base, bignum = 0; int len, slen, pos; bin_retry: switch (TYPE(val)) { case T_FIXNUM: - v = FIX2INT(val); + v = FIX2LONG(val); break; case T_FLOAT: val = dbl2big(RFLOAT(val)->value); @@ -471,7 +472,7 @@ f_sprintf(argc, argv) int_retry: switch (TYPE(val)) { case T_FIXNUM: - v = FIX2INT(val); + v = FIX2LONG(val); break; case T_FLOAT: v = RFLOAT(val)->value; @@ -567,7 +568,7 @@ f_sprintf(argc, argv) switch (TYPE(val)) { case T_FIXNUM: - fval = FIX2INT(val); + fval = (double)FIX2LONG(val); break; case T_FLOAT: fval = RFLOAT(val)->value; diff --git a/version.h b/version.h index 39d4f69dcf..a4eeb9bd9b 100644 --- a/version.h +++ b/version.h @@ -1,2 +1,2 @@ -#define RUBY_VERSION "1.1b9_28" -#define VERSION_DATE "98/06/26" +#define RUBY_VERSION "1.1b9_29" +#define VERSION_DATE "98/07/03" -- cgit v1.2.3