ruby-changes:9061
From: nobu <ko1@a...>
Date: Tue, 9 Dec 2008 16:35:26 +0900 (JST)
Subject: [ruby-changes:9061] Ruby:r20598 (mvm): * merged from trunk r20561:20597.
nobu 2008-12-09 16:34:47 +0900 (Tue, 09 Dec 2008) New Revision: 20598 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20598 Log: * merged from trunk r20561:20597. Modified files: branches/mvm/.gdbinit branches/mvm/.merged-trunk-revision branches/mvm/ChangeLog branches/mvm/Makefile.in branches/mvm/compile.c branches/mvm/configure.in branches/mvm/cont.c branches/mvm/enc/Makefile.in branches/mvm/enc/depend branches/mvm/eval.c branches/mvm/ext/bigdecimal/bigdecimal.c branches/mvm/ext/curses/curses.c branches/mvm/ext/curses/extconf.rb branches/mvm/gc.c branches/mvm/id.h branches/mvm/include/ruby/intern.h branches/mvm/include/ruby/oniguruma.h branches/mvm/lib/open3.rb branches/mvm/mkconfig.rb branches/mvm/pack.c branches/mvm/parse.y branches/mvm/proc.c branches/mvm/regenc.h branches/mvm/regparse.h branches/mvm/ruby.c branches/mvm/template/id.h.tmpl branches/mvm/template/insns.inc.tmpl branches/mvm/template/insns_info.inc.tmpl branches/mvm/template/known_errors.inc.tmpl branches/mvm/template/minsns.inc.tmpl branches/mvm/template/opt_sc.inc.tmpl branches/mvm/template/optinsn.inc.tmpl branches/mvm/template/optunifs.inc.tmpl branches/mvm/template/vm.inc.tmpl branches/mvm/template/vmtc.inc.tmpl branches/mvm/template/yasmdata.rb.tmpl branches/mvm/test/ruby/test_pack.rb branches/mvm/test/test_open3.rb branches/mvm/thread.c branches/mvm/thread_pthread.c branches/mvm/tool/make-snapshot branches/mvm/version.h branches/mvm/vm.c branches/mvm/vm_core.h branches/mvm/vm_dump.c branches/mvm/vm_eval.c branches/mvm/vm_insnhelper.c branches/mvm/vm_insnhelper.h Index: mvm/regparse.h =================================================================== --- mvm/regparse.h (revision 20597) +++ mvm/regparse.h (revision 20598) @@ -192,7 +192,7 @@ AbsAddrType call_addr; /* for multiple call reference */ OnigDistance min_len; /* min length (byte) */ - OnigDistance max_len; /* max length (byte) */ + OnigDistance max_len; /* max length (byte) */ int char_len; /* character length */ int opt_count; /* referenced count in optimize_node_left() */ } EncloseNode; Index: mvm/.gdbinit =================================================================== --- mvm/.gdbinit (revision 20597) +++ mvm/.gdbinit (revision 20598) @@ -158,7 +158,7 @@ print (struct RStruct *)$arg0 x/xw (($flags & (RUBY_FL_USER1|RUBY_FL_USER2)) ? \ ((struct RStruct *)$arg0)->as.ary : \ - ((struct RStruct *)$arg0)->as.heap.len) + ((struct RStruct *)$arg0)->as.heap.ptr) else if ($flags & RUBY_T_MASK) == RUBY_T_BIGNUM printf "T_BIGNUM: sign=%d len=%ld ", \ Index: mvm/include/ruby/intern.h =================================================================== --- mvm/include/ruby/intern.h (revision 20597) +++ mvm/include/ruby/intern.h (revision 20598) @@ -28,7 +28,7 @@ #endif #include "ruby/st.h" -/* +/* * Functions and variables that are used by more than one source file of * the kernel. */ Index: mvm/include/ruby/oniguruma.h =================================================================== --- mvm/include/ruby/oniguruma.h (revision 20597) +++ mvm/include/ruby/oniguruma.h (revision 20598) @@ -146,7 +146,7 @@ OnigCodePoint one_or_more_time; OnigCodePoint anychar_anytime; } OnigMetaCharTableType; - + typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg); typedef struct OnigEncodingTypeST { @@ -495,7 +495,7 @@ #define ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED -21 #define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR -22 /* general error */ -#define ONIGERR_INVALID_ARGUMENT -30 +#define ONIGERR_INVALID_ARGUMENT -30 /* syntax error */ #define ONIGERR_END_PATTERN_AT_LEFT_BRACE -100 #define ONIGERR_END_PATTERN_AT_LEFT_BRACKET -101 Index: mvm/configure.in =================================================================== --- mvm/configure.in (revision 20597) +++ mvm/configure.in (revision 20598) @@ -214,6 +214,9 @@ ASFLAGS=$ASFLAGS AC_SUBST(ASFLAGS) +AC_CHECK_TOOL(OBJDUMP, objdump) +AC_CHECK_TOOL(OBJCOPY, objcopy) + case "$target_os" in cygwin*|mingw*) AC_CHECK_TOOL(NM, nm) @@ -223,7 +226,6 @@ case "$target_os" in mingw*) test "$rb_cv_msvcrt" = "" && unset rb_cv_msvcrt - AC_CHECK_TOOL(OBJDUMP, objdump) AC_CACHE_CHECK(for mingw32 runtime DLL, rb_cv_msvcrt, [ AC_TRY_LINK([#include <stdio.h>], [FILE* volatile f = stdin; return 0;], @@ -1315,7 +1317,6 @@ AC_SUBST(LIBEXT)dnl STATIC= -: ${LIBPATHFLAG=' -L%s'} : ${PATHFLAG=''} if test "$with_dln_a_out" != yes; then @@ -1345,7 +1346,6 @@ [ --disable-rpath embed run path into extension libraries.], [enable_rpath=$enableval], [enable_rpath="$rb_cv_binary_elf"]) if test "$enable_rpath" = yes; then - LIBPATHFLAG=" -L%1\$-s" RPATHFLAG=" ${linker_flag}-R%1\$-s" fi @@ -1496,6 +1496,12 @@ ;; esac fi +case ${RPATHFLAG} in +*'%1$'*) + : ${LIBPATHFLAG=' -L%1$-s'};; +*) + : ${LIBPATHFLAG=' -L%s'};; +esac AC_SUBST(LINK_SO) AC_SUBST(LIBPATHFLAG) Index: mvm/ChangeLog =================================================================== --- mvm/ChangeLog (revision 20597) +++ mvm/ChangeLog (revision 20598) @@ -1,3 +1,124 @@ +Tue Dec 9 13:33:53 2008 Nobuyoshi Nakada <nobu@r...> + + * compile.c (iseq_compile_each), gc.c (assign_heap_slot), + (gc_mark_children), parse.y (vtable_alloc, vtable_free, vtable_add), + proc.c (proc_to_s), thread.c (terminate_i, rb_thread_terminate_all), + (thread_start_func_2, blocking_region_begin, blocking_region_end), + (rb_thread_kill), thread_pthread.c (native_thread_create), + (ubf_pthread_cond_signal), vm.c (check_env, thread_free), vm_dump.c + (vm_env_dump_raw, vm_stack_dump_each, vm_thread_dump_state), + (vm_call0): use void pointer for %p. + + * cont.c (fiber_status), template/insns.inc.tmpl (ruby_vminsn_type), + vm_insnhelper.h (BOP): ISO C forbids comma at end of enumerator + list. + + * vm_insnhelper.c (check_cfunc): use function pointer. + +Tue Dec 9 13:23:55 2008 Yukihiro Matsumoto <matz@r...> + + * ext/curses/curses.c (curses_use_default_colors): add new + method. a patch from Giancarlo F Bellido + <support at coaxialhost.com> in [ruby-core:20434]. + + * ext/curses/curses.c (curses_tabsize_set): ditto. + + * ext/curses/curses.c (curses_tabsize_get): ditto. + +Tue Dec 9 12:08:47 2008 Nobuyoshi Nakada <nobu@r...> + + * .gdbinit (rp): fixed typo for T_STRUCT. + +Tue Dec 9 11:50:46 2008 Yuki Sonoda (Yugui) <yugui@y...> + + * pack.c (pack_pck): fixed [ruby-dev:37295]. + Array#pack always has returned an US-ASCII string when + the given format ended with 'u', 'M' or 'm'. + +Tue Dec 9 03:21:37 2008 Nobuyoshi Nakada <nobu@r...> + + * mkconfig.rb: fix for continued lines. based on a patch from + Marcus Rueckert <darix AT opensu.se> at [ruby-core:20420]. + +Tue Dec 9 00:54:01 2008 Nobuyoshi Nakada <nobu@r...> + + * tool/make-snapshot (package): enc.mk in snapshot is dummy and should + not deal with objects. [ruby-core:20422] + +Tue Dec 9 00:17:50 2008 Nobuyoshi Nakada <nobu@r...> + + * enc/depend (clean-srcs): split out from clean. + +Mon Dec 8 23:34:18 2008 Yuki Sonoda (Yugui) <yugui@y...> + + * pack.c (pack_pack): fixed odd act of 'm*', 'M*', and 'P*'. + just ignores '*' in these cases. + [ruby-dev:37289] + +Mon Dec 8 18:31:41 2008 Nobuyoshi Nakada <nobu@r...> + + * pack.c (pack_pack): fixed length for odd length string. + [ruby-dev:37283] + +Mon Dec 8 11:28:14 2008 Nobuyoshi Nakada <nobu@r...> + + * ruby.c (proc_options): added version, copyright, usage, yydebug, + syntax to --dump option. + +Mon Dec 8 11:15:45 2008 Nobuyoshi Nakada <nobu@r...> + + * ruby.c (proc_options): source-encoding option. + +Mon Dec 8 10:32:33 2008 Nobuyoshi Nakada <nobu@r...> + + * ruby.c (set_option_encoding_once): dry. + + * ruby.c (proc_options): checks extra argument for -E/--encoding. + +Sun Dec 7 23:47:37 2008 Nobuyoshi Nakada <nobu@r...> + + * configure.in (LIBPATHFLAG): use numbered specifier if RPATHFLAG + is set. [ruby-talk:322136] + +Sun Dec 7 23:17:33 2008 Nobuyoshi Nakada <nobu@r...> + + * Makefile.in (LIBRUBY_SO): localizes non-public symbols. + + * configure.in (OBJDUMP, OBJCOPY): for dealing with binary files. + +Sun Dec 7 17:44:06 2008 Tanaka Akira <akr@f...> + + * lib/open3.rb (Open3.capture3): renamed from Open3.poutput3. + (Open3.capture2): renamed from Open3.poutput2. + (lOpen3.capture2e): renamed from Open3.poutput2e. + +Sun Dec 7 11:48:04 2008 Tanaka Akira <akr@f...> + + * lib/open3.rb (Open3.poutput3): :binmode option implemented. + (Open3.poutput2): ditto. + (Open3.poutput2e): ditto. + +Sat Dec 6 18:33:16 2008 Nobuyoshi Nakada <nobu@r...> + + * tool/make-snapshot (package): added RM and CP. [ruby-dev:37288] + +Sat Dec 6 17:51:35 2008 Yuki Sonoda (Yugui) <yugui@y...> + + * pack.c (pack_pack): 'u0' is not special differently from 'm0'. + +Sat Dec 6 14:35:06 2008 NARUSE, Yui <naruse@r...> + + * pack.c (pack_pack): set US-ASCII and CODERANGE_7BIT + when quoted-printable ('M') and base64 ('m'). + [ruby-dev:37284] + + * pack.c (pack_unpack): ditto. + +Fri Dec 5 22:56:24 2008 Yukihiro Matsumoto <matz@r...> + + * eval.c (rb_make_exception): single argument to raise may be + string compatible object. + Fri Dec 5 21:45:45 2008 Tadayoshi Funaba <tadf@d...> * rational.c (nurat_{to_s,inspect}): performance improvement. @@ -6,6 +127,15 @@ * complex.c: inpsect should not depend on to_s. +Fri Dec 5 21:18:31 2008 Yukihiro Matsumoto <matz@r...> + + * ext/bigdecimal/bigdecimal.c (BigDecimal_truncate): return + integer if no optional argument given. [incompatible] + + * ext/bigdecimal/bigdecimal.c (BigDecimal_floor): ditto. + + * ext/bigdecimal/bigdecimal.c (BigDecimal_ceil): ditto. + Fri Dec 5 19:06:04 2008 Tanaka Akira <akr@f...> * lib/open3.rb (Open3.pipeline_start): new method. Index: mvm/regenc.h =================================================================== --- mvm/regenc.h (revision 20597) +++ mvm/regenc.h (revision 20598) @@ -181,7 +181,7 @@ #define ONIGENC_IS_ASCII_CODE_CASE_AMBIG(code) \ (ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_UPPER) ||\ ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_LOWER)) - + #ifdef ONIG_ENC_REGISTER extern int ONIG_ENC_REGISTER(const char *, OnigEncodingType*); #define OnigEncodingName(n) encoding_##n Index: mvm/thread_pthread.c =================================================================== --- mvm/thread_pthread.c (revision 20597) +++ mvm/thread_pthread.c (revision 20598) @@ -513,7 +513,7 @@ int err = 0; if (use_cached_thread(th)) { - thread_debug("create (use cached thread): %p\n", th); + thread_debug("create (use cached thread): %p\n", (void *)th); } else { pthread_attr_t attr; @@ -543,7 +543,7 @@ CHECK_ERR(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)); err = pthread_create(&th->thread_id, &attr, thread_start_func_1, th); - thread_debug("create: %p (%d)", th, err); + thread_debug("create: %p (%d)", (void *)th, err); CHECK_ERR(pthread_attr_destroy(&attr)); if (!err) { @@ -602,7 +602,7 @@ ubf_pthread_cond_signal(void *ptr) { rb_thread_t *th = (rb_thread_t *)ptr; - thread_debug("ubf_pthread_cond_signal (%p)\n", th); + thread_debug("ubf_pthread_cond_signal (%p)\n", (void *)th); pthread_cond_signal(&th->native_thread_data.sleep_cond); } Index: mvm/mkconfig.rb =================================================================== --- mvm/mkconfig.rb (revision 20597) +++ mvm/mkconfig.rb (revision 20598) @@ -56,14 +56,13 @@ continued_name = name next end - when /^"(.+)"\s*(\\)?$/ + when /^"(.*)"\s*(\\)?$/ if continued_line continued_line << $1 - unless $2 - val = continued_line.join("") - name = continued_name - continued_line = nil - end + next if $2 + val = continued_line.join("") + name = continued_name + continued_line = nil end when /^(?:ac_given_)?INSTALL=(.*)/ v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n" Index: mvm/enc/Makefile.in =================================================================== --- mvm/enc/Makefile.in (revision 20597) +++ mvm/enc/Makefile.in (revision 20598) @@ -59,5 +59,5 @@ clean: -distclean: clean +distclean: clean clean-srcs @$(RM) enc.mk Index: mvm/enc/depend =================================================================== --- mvm/enc/depend (revision 20597) +++ mvm/enc/depend (revision 20598) @@ -128,9 +128,15 @@ enc/trans/transdb.$(OBJEXT): transdb.h clean: -% %w[$(ENCSOS) $(ENCOBJS) $(ENCCLEANOBJS) $(ENCCLEANLIBS) $(TRANSSOS) $(TRANSOBJS) $(TRANSCLEANOBJS) $(TRANSCLEANLIBS) $(TRANSCSRCS)].each do |clean| +% %w[$(ENCSOS) $(ENCOBJS) $(ENCCLEANOBJS) $(ENCCLEANLIBS) $(TRANSSOS) $(TRANSOBJS) $(TRANSCLEANOBJS) $(TRANSCLEANLIBS)].each do |clean| @$(RM) <%=pathrep[clean]%> % end -% %w[$(ENCSODIR)/trans $(ENCSODIR) enc/trans enc].each do|dir| +% %w[$(TRANSSODIR) $(ENCSODIR)].each do|dir| @-rmdir <%=pathrep[dir]%> % end + +clean-srcs: + @$(RM) <%=pathrep['$(TRANSCSRCS)']%> +% %w[enc/trans enc].each do|dir| + @-rmdir <%=pathrep[dir]%> +% end Index: mvm/vm_core.h =================================================================== --- mvm/vm_core.h (revision 20597) +++ mvm/vm_core.h (revision 20598) @@ -1,6 +1,6 @@ /********************************************************************** - vm_core.h - + vm_core.h - $Author$ created at: 04/01/01 19:41:38 JST @@ -144,7 +144,7 @@ int local_table_size; /* method, class frame: sizeof(vars) + 1, block frame: sizeof(vars) */ - int local_size; + int local_size; /** * argument information @@ -197,7 +197,7 @@ VALUE orig; /* non-NULL if its data have origin */ /* block inlining */ - /* + /* * NODE *node; * void *special_block_builder; * void *cached_special_block_builder; @@ -385,7 +385,7 @@ int safe_level; int raised_flag; VALUE last_status; /* $? */ - + /* passing state */ int state; Index: mvm/pack.c =================================================================== --- mvm/pack.c (revision 20597) +++ mvm/pack.c (revision 20598) @@ -492,7 +492,9 @@ } } if (*p == '*') { /* set data length */ - len = strchr("@Xxu", type) ? 0 : items; + len = strchr("@Xxu", type) ? 0 + : strchr("PMm", type) ? 1 + : items; p++; } else if (ISDIGIT(*p)) { @@ -621,7 +623,7 @@ long i, j = 0; if (len > plen) { - j = (len - plen + 1)/2; + j = (len + 1) / 2 - (plen + 1) / 2; len = plen; } for (i=0; i++ < len; ptr++) { @@ -652,7 +654,7 @@ long i, j = 0; if (len > plen) { - j = (len - plen + 1)/2; + j = (len + 1) / 2 - (plen + 1) / 2; len = plen; } for (i=0; i++ < len; ptr++) { @@ -897,12 +899,14 @@ case 'u': /* uuencoded string */ case 'm': /* base64 encoded string */ + enc = rb_enc_compatible(res, rb_enc_from_encoding(rb_usascii_encoding())); + rb_enc_associate(res, enc); from = NEXTFROM; StringValue(from); ptr = RSTRING_PTR(from); plen = RSTRING_LEN(from); - if (len == 0) { + if (len == 0 && type == 'm') { encodes(res, ptr, plen, type, 0); ptr += plen; break; @@ -925,6 +929,8 @@ break; case 'M': /* quoted-printable encoded string */ + enc = rb_enc_compatible(res, rb_enc_from_encoding(rb_usascii_encoding())); + rb_enc_associate(res, enc); from = rb_obj_as_string(NEXTFROM); if (len <= 1) len = 72; @@ -1903,6 +1909,7 @@ } } rb_str_set_len(buf, ptr - RSTRING_PTR(buf)); + ENCODING_CODERANGE_SET(buf, rb_usascii_encindex(), ENC_CODERANGE_7BIT); UNPACK_PUSH(buf); } break; @@ -1931,6 +1938,7 @@ s++; } rb_str_set_len(buf, ptr - RSTRING_PTR(buf)); + ENCODING_CODERANGE_SET(buf, rb_usascii_encindex(), ENC_CODERANGE_7BIT); UNPACK_PUSH(buf); } break; Index: mvm/lib/open3.rb =================================================================== --- mvm/lib/open3.rb (revision 20597) +++ mvm/lib/open3.rb (revision 20598) @@ -15,9 +15,9 @@ # - Open3.popen3 : pipes for stdin, stdout, stderr # - Open3.popen2 : pipes for stdin, stdout # - Open3.popen2e : pipes for stdin, merged stdout and stderr -# - Open3.poutput3 : give a string for stdin. get strings for stdout, stderr -# - Open3.poutput2 : give a string for stdin. get a string for stdout -# - Open3.poutput2e : give a string for stdin. get a string for merged stdout and stderr +# - Open3.capture3 : give a string for stdin. get strings for stdout, stderr +# - Open3.capture2 : give a string for stdin. get a string for stdout +# - Open3.capture2e : give a string for stdin. get a string for merged stdout and stderr # - Open3.pipeline_rw : pipes for first stdin and last stdout of a pipeline # - Open3.pipeline_r : pipe for last stdout of a pipeline # - Open3.pipeline_w : pipe for first stdin of a pipeline @@ -34,7 +34,7 @@ # # Block form: # - # Open3.popen3(cmd... [, opts]) {|stdin, stdout, stderr, wait_thr| + # Open3.popen3([env,] cmd... [, opts]) {|stdin, stdout, stderr, wait_thr| # pid = wait_thr.pid # pid of the started process. # ... # exit_status = wait_thr.value # Process::Status object returned. @@ -42,7 +42,7 @@ # # Non-block form: # - # stdin, stdout, stderr, wait_thr = Open3.popen3(cmd... [, opts]) + # stdin, stdout, stderr, wait_thr = Open3.popen3([env,] cmd... [, opts]) # pid = wait_thr[:pid] # pid of the started process. # ... # stdin.close # stdin, stdout and stderr should be closed explicitly in this form. @@ -94,7 +94,7 @@ # # Block form: # - # Open3.popen2(cmd... [, opts]) {|stdin, stdout, wait_thr| + # Open3.popen2([env,] cmd... [, opts]) {|stdin, stdout, wait_thr| # pid = wait_thr.pid # pid of the started process. # ... # exit_status = wait_thr.value # Process::Status object returned. @@ -102,7 +102,7 @@ # # Non-block form: # - # stdin, stdout, wait_thr = Open3.popen2(cmd... [, opts]) + # stdin, stdout, wait_thr = Open3.popen2([env,] cmd... [, opts]) # ... # stdin.close # stdin and stdout should be closed explicitly in this form. # stdout.close @@ -150,7 +150,7 @@ # # Block form: # - # Open3.popen2e(cmd... [, opts]) {|stdin, stdout_and_stderr, wait_thr| + # Open3.popen2e([env,] cmd... [, opts]) {|stdin, stdout_and_stderr, wait_thr| # pid = wait_thr.pid # pid of the started process. # ... # exit_status = wait_thr.value # Process::Status object returned. @@ -158,11 +158,22 @@ # # Non-block form: # - # stdin, stdout_and_stderr, wait_thr = Open3.popen2e(cmd... [, opts]) + # stdin, stdout_and_stderr, wait_thr = Open3.popen2e([env,] cmd... [, opts]) # ... # stdin.close # stdin and stdout_and_stderr should be closed explicitly in this form. # stdout_and_stderr.close # + # Example: + # # check gcc warnings + # source = "foo.c" + # Open3.popen2e("gcc", "-Wall", source) {|i,oe,t| + # oe.each {|line| + # if /warning/ =~ line + # ... + # end + # } + # } + # def popen2e(*cmd, &block) if Hash === cmd.last opts = cmd.pop.dup @@ -201,14 +212,16 @@ private :popen_run end - # Open3.poutput3 captures the standard output and the standard error of a command. + # Open3.capture3 captures the standard output and the standard error of a command. # - # stdout_str, stderr_str, status = Open3.poutput3(cmd... [, opts]) + # stdout_str, stderr_str, status = Open3.capture3([env,] cmd... [, opts]) # # The arguments cmd and opts are passed to Open3.popen3 except opts[:stdin_data]. # # If opts[:stdin_data] is specified, it is sent to the command's standard input. # + # If opts[:binmode] is true, internal pipes are set to binary mode. + # # Example: # # # dot is a command of graphviz. @@ -217,14 +230,27 @@ # a -> b # } # End - # layouted_graph, dot_log = Open3.poutput3("dot -v", :stdin_data=>graph) + # layouted_graph, dot_log = Open3.capture3("dot -v", :stdin_data=>graph) # - # o, e, s = Open3.poutput3("echo a; sort >&2", :stdin_data=>"foo\nbar\nbaz\n") + # o, e, s = Open3.capture3("echo a; sort >&2", :stdin_data=>"foo\nbar\nbaz\n") # p o #=> "a\n" # p e #=> "bar\nbaz\nfoo\n" # p s #=> #<Process::Status: pid 32682 exit 0> # - def poutput3(*cmd, &block) + # # generate a thumnail image using the convert command of ImageMagick. + # # However, if the image stored really in a file, + # # system("convert", "-thumbnail", "80", "png:#{filename}", "png:-") is better + # # because memory consumption. + # # But if the image is stored in a DB or generated by gnuplot Open3.capture2 example, + # # Open3.capture3 is considerable. + # # + # image = File.read("/usr/share/openclipart/png/animals/mammals/sheep-md-v0.1.png", :binmode=>true) + # thumnail, err, s = Open3.capture3("convert -thumbnail 80 png:- png:-", :stdin_data=>image, :binmode=>true) + # if s.success? + # STDOUT.binmode; print thumnail + # end + # + def capture3(*cmd, &block) if Hash === cmd.last opts = cmd.pop.dup else @@ -232,8 +258,14 @@ end stdin_data = opts.delete(:stdin_data) || '' + binmode = opts.delete(:binmode) popen3(*cmd, opts) {|i, o, e, t| + if binmode + i.binmode + o.binmode + e.binmode + end out_reader = Thread.new { o.read } err_reader = Thread.new { e.read } i.write stdin_data @@ -241,21 +273,37 @@ [out_reader.value, err_reader.value, t.value] } end - module_function :poutput3 + module_function :capture3 - # Open3.poutput2 captures the standard output of a command. + # Open3.capture2 captures the standard output of a command. # - # stdout_str, status = Open3.poutput2(cmd... [, opts]) + # stdout_str, status = Open3.capture2([env,] cmd... [, opts]) # # The arguments cmd and opts are passed to Open3.popen2 except opts[:stdin_data]. # # If opts[:stdin_data] is specified, it is sent to the command's standard input. # - # # factor is a command for integer factorization - # o, s = Open3.poutput2("factor", :stdin_data=>"42") + # If opts[:binmode] is true, internal pipes are set to binary mode. + # + # Example: + # + # # factor is a command for integer factorization. + # o, s = Open3.capture2("factor", :stdin_data=>"42") # p o #=> "42: 2 3 7\n" # - def poutput2(*cmd, &block) + # # generate x**2 graph in png using gnuplot. + # gnuplot_commands = <<"End" + # set terminal png + # plot x**2, "-" with lines + # 1 14 + # 2 1 + # 3 8 + # 4 5 + # e + # End + # image, s = Open3.capture2("gnuplot", :stdin_data=>gnuplot_commands, :binmode=>true) + # + def capture2(*cmd, &block) if Hash === cmd.last opts = cmd.pop.dup else @@ -263,25 +311,37 @@ end stdin_data = opts.delete(:stdin_data) || '' + binmode = opts.delete(:binmode) popen2(*cmd, opts) {|i, o, t| + if binmode + i.binmode + o.binmode + end out_reader = Thread.new { o.read } i.write stdin_data i.close [out_reader.value, t.value] } end - module_function :poutput2 + module_function :capture2 - # Open3.poutput2e captures the standard output and the standard error of a command. + # Open3.capture2e captures the standard output and the standard error of a command. # - # stdout_and_stderr_str, status = Open3.poutput2e(cmd... [, opts]) + # stdout_and_stderr_str, status = Open3.capture2e([env,] cmd... [, opts]) # # The arguments cmd and opts are passed to Open3.popen2e except opts[:stdin_data]. # # If opts[:stdin_data] is specified, it is sent to the command's standard input. # - def poutput2e(*cmd, &block) + # If opts[:binmode] is true, internal pipes are set to binary mode. + # + # Example: + # + # # capture make log + # make_log, s = Open3.capture2e("make") + # + def capture2e(*cmd, &block) if Hash === cmd.last opts = cmd.pop.dup else @@ -289,17 +349,22 @@ end stdin_data = opts.delete(:stdin_data) || '' + binmode = opts.delete(:binmode) popen2e(*cmd, opts) {|i, oe, t| + if binmode + i.binmode + oe.binmode + end outerr_reader = Thread.new { oe.read } i.write stdin_data i.close [outerr_reader.value, t.value] } end - module_function :poutput2e + module_function :capture2e - # Open3.pipeline_rw starts list of commands as a pipeline with pipes + # Open3.pipeline_rw starts a list of commands as a pipeline with pipes # which connects stdin of the first command and stdout of the last command. # # Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) {|first_stdin, last_stdout, wait_threads| @@ -351,7 +416,7 @@ end module_function :pipeline_rw - # Open3.pipeline_r starts list of commands as a pipeline with a pipe + # Open3.pipeline_r starts a list of commands as a pipeline with a pipe # which connects stdout of the last command. # # Open3.pipeline_r(cmd1, cmd2, ... [, opts]) {|last_stdout, wait_threads| @@ -364,11 +429,6 @@ # # Example: # - # fname = "/usr/share/man/man1/ls.1.gz" - # Open3.pipeline_r(["zcat", fname], "nroff -man", "colcrt") {|r, ts| - # IO.copy_stream(r, STDOUT) - # } - # # Open3.pipeline_r("zcat /var/log/apache2/access.log.*.gz", # [{"LANG"=>"C"}, "grep", "GET /favicon.ico"], # "logresolve") {|r, ts| @@ -397,7 +457,7 @@ end module_function :pipeline_r - # Open3.pipeline_w starts list of commands as a pipeline with a pipe + # Open3.pipeline_w starts a list of commands as a pipeline with a pipe # which connects stdin of the first command. # # Open3.pipeline_w(cmd1, cmd2, ... [, opts]) {|first_stdin, wait_threads| @@ -429,7 +489,7 @@ end module_function :pipeline_w - # Open3.pipeline_start starts list of commands as a pipeline. + # Open3.pipeline_start starts a list of commands as a pipeline. # No pipe made for stdin of the first command and # stdout of the last command. # @@ -440,6 +500,16 @@ # wait_threads = Open3.pipeline_start(cmd1, cmd2, ... [, opts]) # ... # + # Example: + # + # # run xeyes in 10 seconds. + # Open3.pipeline_start("xeyes") {|ts| + # sleep 10 + # t = ts[0] + # Process.kill("TERM", t.pid) + # p t.value #=> #<Process::Status: pid 911 SIGTERM (signal 15)> + # } + # def pipeline_start(*cmds, &block) if Hash === cmds.last opts = cmds.pop.dup @@ -451,7 +521,7 @@ end module_function :pipeline_start - # Open3.pipeline starts list of commands as a pipeline. + # Open3.pipeline starts a list of commands as a pipeline. # It waits the finish of the commands. # No pipe made for stdin of the first command and # stdout of the last command. @@ -466,9 +536,32 @@ # # #<Process::Status: pid 11820 exit 0>, # # #<Process::Status: pid 11828 exit 0>] # + # fname = "/usr/share/man/man1/ls.1.gz" + # Open3.pipeline(["zcat", fname], "nroff -man", "colcrt") + # + # # convert PDF to PS and send to a printer by lpr + # pdf_file = "paper.pdf" + # printer = "printer-name" + # Open3.pipeline(["pdftops", pdf_file, "-"], + # ["lpr", "-P#{printer}"]) + # # # count lines # Open3.pipeline("sort", "uniq -c", :in=>"names.txt", :out=>"count") # + # # cyclic pipeline + # r,w = IO.pipe + # w.print "ibase=14\n10\n" + # Open3.pipeline("bc", "tee /dev/tty", :in=>r, :out=>w) + # #=> 14 + # # 18 + # # 22 + # # 30 + # # 42 + # # 58 + # # 78 + # # 106 + # # 202 + # def pipeline(*cmds) if Hash === cmds.last opts = cmds.pop.dup Index: mvm/compile.c =================================================================== --- mvm/compile.c (revision 20597) +++ mvm/compile.c (revision 20598) @@ -4629,7 +4629,7 @@ LABEL *lfin = NEW_LABEL(nd_line(node)); LABEL *ltrue = NEW_LABEL(nd_line(node)); VALUE key = rb_sprintf("flipflag/%s-%p-%d", - RSTRING_PTR(iseq->name), iseq, + RSTRING_PTR(iseq->name), (void *)iseq, iseq->compile_data->flip_cnt++); iseq_add_mark_object_compile_time(iseq, key); Index: mvm/vm_eval.c =================================================================== --- mvm/vm_eval.c (revision 20597) +++ mvm/vm_eval.c (revision 20598) @@ -29,7 +29,7 @@ if (0) printf("id: %s, nd: %s, argc: %d, passed: %p\n", rb_id2name(id), ruby_node_name(nd_type(body)), - argc, th->passed_block); + argc, (void *)th->passed_block); if (th->passed_block) { blockptr = th->passed_block; Index: mvm/proc.c =================================================================== --- mvm/proc.c (revision 20597) +++ mvm/proc.c (revision 20598) @@ -776,7 +776,7 @@ line_no, is_lambda); } else { - str = rb_sprintf("#<%s:%p%s>", cname, proc->block.iseq, + str = rb_sprintf("#<%s:%p%s>", cname, (void *)proc->block.iseq, is_lambda); } Index: mvm/thread.c =================================================================== --- mvm/thread.c (revision 20597) +++ mvm/thread.c (revision 20598) @@ -271,13 +271,13 @@ GetThreadPtr(thval, th); if (th != main_thread) { - thread_debug("terminate_i: %p\n", th); + thread_debug("terminate_i: %p\n", (void *)th); rb_thread_interrupt(th); th->thrown_errinfo = eTerminateSignal; th->status = THREAD_TO_KILL; } else { - thread_debug("terminate_i: main thread (%p)\n", th); + thread_debug("terminate_i: main thread (%p)\n", (void *)th); } return ST_CONTINUE; } @@ -300,7 +300,8 @@ rb_vm_t *vm = GET_VM(); if (vm->main_thread != th) { - rb_bug("rb_thread_terminate_all: called by child thread (%p, %p)", vm->main_thread, th); + rb_bug("rb_thread_terminate_all: called by child thread (%p, %p)", + (void *)vm->main_thread, (void *)th); } rb_vm_thread_terminate_all(vm); } @@ -315,7 +316,7 @@ rb_mutex_unlock_all(th->keeping_mutexes); } - thread_debug("rb_thread_terminate_all (main thread: %p)\n", th); + thread_debug("rb_thread_terminate_all (main thread: %p)\n", (void *)th); st_foreach(vm->living_threads, terminate_i, (st_data_t)th); while (!rb_thread_alone()) { @@ -380,11 +381,11 @@ #ifdef __ia64 th->machine_register_stack_start = register_stack_start; #endif - thread_debug("thread start: %p\n", th); + thread_debug("thread start: %p\n", (void *)th); native_mutex_lock(&th->vm->global_vm_lock); { - thread_debug("thread start (get lock): %p\n", th); + thread_debug("thread start (get lock): %p\n", (void *)th); rb_thread_set_current(th); TH_PUSH_TAG(th); @@ -428,7 +429,7 @@ } th->status = THREAD_KILLED; - thread_debug("thread end: %p\n", th); + thread_debug("thread end: %p\n", (void *)th); main_th = th->vm->main_thread; if (th != main_th) { @@ -442,7 +443,7 @@ /* locking_mutex must be Qfalse */ if (th->locking_mutex != Qfalse) { rb_bug("thread_start_func_2: locking_mutex must not be set (%p:%"PRIxVALUE")", - th, th->locking_mutex); + (void *)th, th->locking_mutex); } /* unlock all locking mutexes */ @@ -969,7 +970,7 @@ region->prev_status = th->status; set_unblock_function(th, func, arg, ®ion->oldubf); th->status = THREAD_STOPPED; - thread_debug("enter blocking region (%p)\n", th); + thread_debug("enter blocking region (%p)\n", (void *)th); rb_gc_save_machine_context(th); native_mutex_unlock(&th->vm->global_vm_lock); } @@ -979,7 +980,7 @@ { native_mutex_lock(&th->vm->global_vm_lock); rb_thread_set_current(th); - thread_debug("leave blocking region (%p)\n", th); + thread_debug("leave blocking region (%p)\n", (void *)th); remove_signal_thread_list(th); reset_unblock_function(th, ®ion->oldubf); if (th->status == THREAD_STOPPED) { @@ -1360,7 +1361,7 @@ rb_exit(EXIT_SUCCESS); } - thread_debug("rb_thread_kill: %p (%p)\n", th, (void *)th->thread_id); + thread_debug("rb_thread_kill: %p (%p)\n", (void *)th, (void *)th->thread_id); rb_thread_interrupt(th); th->thrown_errinfo = eKillSignal; Index: mvm/eval.c =================================================================== --- mvm/eval.c (revision 20597) +++ mvm/eval.c (revision 20598) @@ -514,13 +514,13 @@ mesg = Qnil; switch (argc) { case 0: - mesg = Qnil; break; case 1: if (NIL_P(argv[0])) break; - if (TYPE(argv[0]) == T_STRING) { - mesg = rb_exc_new3(rb_eRuntimeError, argv[0]); + mesg = rb_check_string_type(argv[0]); + if (!NIL_P(mesg)) { + mesg = rb_exc_new3(rb_eRuntimeError, mesg); break; } n = 0; Index: mvm/gc.c =================================================================== --- mvm/gc.c (revision 20597) +++ mvm/gc.c (revision 20598) @@ -825,7 +825,7 @@ hi = mid; } else { - rb_bug("same heap slot is allocated: %p at %"PRIuVALUE, membase, (VALUE)mid); + rb_bug("same heap slot is allocated: %p at %"PRIuVALUE, (void *)membase, (VALUE)mid); } } if (hi < heaps_used) { @@ -1570,7 +1570,7 @@ default: rb_bug("rb_gc_mark(): unknown data type 0x%lx(%p) %s", - BUILTIN_TYPE(obj), obj, + BUILTIN_TYPE(obj), (void *)obj, is_pointer_to_heap(objspace, obj) ? "corrupted object" : "non object"); } } Index: mvm/parse.y =================================================================== --- mvm/parse.y (revision 20597) +++ mvm/parse.y (revision 20598) @@ -131,14 +131,14 @@ tbl->capa = 8; tbl->tbl = ALLOC_N(ID, tbl->capa); tbl->prev = prev; - if (VTBL_DEBUG) printf("vtable_alloc: %p\n", tbl); + if (VTBL_DEBUG) printf("vtable_alloc: %p\n", (void *)tbl); return tbl; } static void vtable_free(struct vtable *tbl) { - if (VTBL_DEBUG)printf("vtable_free: %p\n", tbl); + if (VTBL_DEBUG)printf("vtable_free: %p\n", (void *)tbl); if (POINTER_P(tbl)) { if (tbl->tbl) { xfree(tbl->tbl); @@ -151,9 +151,9 @@ vtable_add(struct vtable *tbl, ID id) { if (!POINTER_P(tbl)) { - rb_bug("vtable_add: vtable is not allocated (%p)", tbl); + rb_bug("vtable_add: vtable is not allocated (%p)", (void *)tbl); } - if (VTBL_DEBUG) printf("vtable_add: %p, %s\n", tbl, rb_id2name(id)); + if (VTBL_DEBUG) printf("vtable_add: %p, %s\n", (void *)tbl, rb_id2name(id)); if (tbl->pos == tbl->capa) { tbl->capa = tbl->capa * 2; Index: mvm/Makefile.in =================================================================== --- mvm/Makefile.in (revision 20597) +++ mvm/Makefile.in (revision 20598) @@ -102,6 +102,8 @@ ASFLAGS = @ASFLAGS@ IFCHANGE = $(srcdir)/tool/ifchange SET_LC_MESSAGES = env LC_MESSAGES=C +OBJDUMP = @OBJDUMP@ +OBJCOPY = @OBJCOPY@ OBJEXT = @OBJEXT@ ASMEXT = S @@ -137,6 +139,9 @@ $(LIBRUBY_SO): @-$(PRE_LIBRUBY_UPDATE) $(LDSHARED) $(DLDFLAGS) $(OBJS) $(DLDOBJS) $(SOLIBS) $(OUTFLAG)$@ + @-test "$(OBJDUMP)" = "" || test "$(OBJCOPY)" = "" || { \ + set dummy `$(OBJDUMP) -t $@ | sed '/^[^ ]* g/!d;s/.* //;/^\(Init_\|vm_\)/!d;s/^/-L /'`; \ + shift; test "$$#" = 0 || $(OBJCOPY) "$$@" $@; } @-$(MINIRUBY) -e 'ARGV.each{|link| File.delete link if File.exist? link; \ File.symlink "$(LIBRUBY_SO)", link}' \ $(LIBRUBY_ALIASES) || true Index: mvm/id.h =================================================================== --- mvm/id.h (revision 20597) +++ mvm/id.h (revision 20598) @@ -1,7 +1,7 @@ /* DO NOT EDIT THIS FILE DIRECTLY */ /********************************************************************** - id.h - + id.h - $Author: ko1 $ created at: Thu Jul 12 04:38:07 2007 Index: mvm/ext/bigdecimal/bigdecimal.c =================================================================== --- mvm/ext/bigdecimal/bigdecimal.c (revision 20597) +++ mvm/ext/bigdecimal/bigdecimal.c (revision 20598) @@ -1413,6 +1413,9 @@ GUARD_OBJ(c,VpCreateRbObject(mx, "0")); VpSetPrecLimit(pl); VpActiveRound(c,a,VP_ROUND_DOWN,iLoc); /* 0: truncate */ + if (argc == 0) { + return BigDecimal_to_i(ToValue(c)); + } return ToValue(c); } @@ -1473,6 +1476,9 @@ GUARD_OBJ(c,VpCreateRbObject(mx, "0")); VpSetPrecLimit(pl); VpActiveRound(c,a,VP_ROUND_FLOOR,iLoc); + if (argc == 0) { + return BigDecimal_to_i(ToValue(c)); + } return ToValue(c); } @@ -1517,6 +1523,9 @@ GUARD_OBJ(c,VpCreateRbObject(mx, "0")); VpSetPrecLimit(pl); VpActiveRound(c,a,VP_ROUND_CEIL,iLoc); + if (argc == 0) { + return BigDecimal_to_i(ToValue(c)); + } return ToValue(c); } Index: mvm/ext/curses/curses.c =================================================================== --- mvm/ext/curses/curses.c (revision 20597) +++ mvm/ext/curses/curses.c (revision 20598) @@ -2,7 +2,7 @@ * $Id$ * * ext/curses/curses.c - * + * * by MAEDA Shugo (ender@p...) * modified by Yukihiro Matsumoto (matz@n...), * Toki Yoshinori, @@ -110,8 +110,8 @@ obj = rb_obj_alloc(class); Data_Get_Struct(obj, struct windata, winp); winp->window = window; - - return obj; + + return obj; } /*-------------------------- module Curses --------------------------*/ @@ -499,87 +499,125 @@ return INT2FIX(COLS); } +/** + * Sets Cursor Visibility. + * 0: invisible + * 1: visible + * 2: very visible + */ static VALUE curses_curs_set(VALUE obj, VALUE visibility) { #ifdef HAVE_CURS_SET - int n; - return (n = curs_set(NUM2INT(visibility)) != ERR) ? INT2FIX(n) : Qnil; + int n; + return (n = curs_set(NUM2INT(visibility)) != ERR) ? INT2FIX(n) : Qnil; #else - return Qnil; + return Qnil; #endif } static VALUE curses_scrl(VALUE obj, VALUE n) { - /* may have to raise exception on ERR */ + /* may have to raise exception on ERR */ #ifdef HAVE_SCRL - return (scrl(NUM2INT(n)) == OK) ? Qtrue : Qfalse; + return (scrl(NUM2INT(n)) == OK) ? Qtrue : Qfalse; #else - return Qfalse; + return Qfalse; #endif } static VALUE curses_setscrreg(VALUE obj, VALUE top, VALUE bottom) { - /* may have to raise exception on ERR */ + /* may have to raise exception on ERR */ #ifdef HAVE_SETSCRREG - return (setscrreg(NUM2INT(top), NUM2INT(bottom)) == OK) ? Qtrue : Qfalse; + return (setscrreg(NUM2INT(top), NUM2INT(bottom)) == OK) ? Qtrue : Qfalse; #else - return Qfalse; + return Qfalse; #endif } static VALUE curses_attroff(VALUE obj, VALUE attrs) { - return window_attroff(rb_stdscr,attrs); - /* return INT2FIX(attroff(NUM2INT(attrs))); */ + return window_attroff(rb_stdscr,attrs); + /* return INT2FIX(attroff(NUM2INT(attrs))); */ } static VALUE curses_attron(VALUE obj, VALUE attrs) { - return window_attron(rb_stdscr,attrs); - /* return INT2FIX(attroff(NUM2INT(attrs))); */ + return window_attron(rb_stdscr,attrs); + /* return INT2FIX(attroff(NUM2INT(attrs))); */ } static VALUE curses_attrset(VALUE obj, VALUE attrs) { - return window_attrset(rb_stdscr,attrs); - /* return INT2FIX(attroff(NUM2INT(attrs))); */ + return window_attrset(rb_stdscr,attrs); + /* return INT2FIX(attroff(NUM2INT(attrs))); */ } static VALUE curses_bkgdset(VALUE obj, VALUE ch) { #ifdef HAVE_BKGDSET - bkgdset(NUM2CH(ch)); + bkgdset(NUM2CH(ch)); #endif - return Qnil; + return Qnil; } static VALUE curses_bkgd(VALUE obj, VALUE ch) { #ifdef HAVE_BKGD - return (bkgd(NUM2CH(ch)) == OK) ? Qtrue : Qfalse; + return (bkgd(NUM2CH(ch)) == OK) ? Qtrue : Qfalse; #else - return Qfalse; + return Qfalse; #endif } static VALUE +curses_use_default_colors(VALUE obj) +{ +#if defined(HAVE_USE_DEFAULT_COLORS) + use_default_colors(); + return Qnil; +#else + rb_notimplement(); +#endif +} + +static VALUE +curses_tabsize_set(VALUE obj, VALUE val) +{ +#if defined(HAVE_TABSIZE) + TABSIZE = NUM2INT(val); + return INT2NUM(TABSIZE); +#else + rb_notimplement(); +#endif +} + +static VALUE +curses_tabsize_get(VALUE ojb) +{ +#if defined(HAVE_TABSIZE) + return INT2NUM(TABSIZE); +#else + rb_notimplement(); +#endif +} + +static VALUE curses_escdelay_set(VALUE obj, VALUE val) { #if defined(HAVE_ESCDELAY) - ESCDELAY=NUM2INT(val); - return INT2NUM(ESCDELAY); + ESCDELAY = NUM2INT(val); + return INT2NUM(ESCDELAY); #else - rb_notimplement(); + rb_notimplement(); #endif } @@ -587,9 +625,9 @@ curses_escdelay_get(VALUE obj) { #if defined(HAVE_ESCDELAY) - return INT2NUM(ESCDELAY); + return INT2NUM(ESCDELAY); #else - rb_notimplement(); + rb_notimplement(); #endif } @@ -597,9 +635,9 @@ curses_resizeterm(VALUE obj, VALUE lin, VALUE col) { #if defined(HAVE_RESIZETERM) - return (resizeterm(NUM2INT(lin),NUM2INT(col)) == OK) ? Qtrue : Qfalse; + return (resizeterm(NUM2INT(lin),NUM2INT(col)) == OK) ? Qtrue : Qfalse; #else - return Qnil; + return Qnil; #endif } @@ -607,77 +645,77 @@ static VALUE curses_start_color(VALUE obj) { - /* may have to raise exception on ERR */ - return (start_color() == OK) ? Qtrue : Qfalse; + /* may have to raise exception on ERR */ + return (start_color() == OK) ? Qtrue : Qfalse; } static VALUE curses_init_pair(VALUE obj, VALUE pair, VALUE f, VALUE b) { - /* may have to raise exception on ERR */ - return (init_pair(NUM2INT(pair),NUM2INT(f),NUM2INT(b)) == OK) ? Qtrue : Qfalse; + /* may have to raise exception on ERR */ + return (init_pair(NUM2INT(pair),NUM2INT(f),NUM2INT(b)) == OK) ? Qtrue : Qfalse; } static VALUE curses_init_color(VALUE obj, VALUE color, VALUE r, VALUE g, VALUE b) { - /* may have to raise exception on ERR */ - return (init_color(NUM2INT(color),NUM2INT(r), - NUM2INT(g),NUM2INT(b)) == OK) ? Qtrue : Qfalse; + /* may have to raise exception on ERR */ + return (init_color(NUM2INT(color),NUM2INT(r), + NUM2INT(g),NUM2INT(b)) == OK) ? Qtrue : Qfalse; } static VALUE curses_has_colors(VALUE obj) { - return has_colors() ? Qtrue : Qfalse; + return has_colors() ? Qtrue : Qfalse; } static VALUE curses_can_change_color(VALUE obj) { - return can_change_color() ? Qtrue : Qfalse; + return can_change_color() ? Qtrue : Qfalse; } static VALUE curses_color_content(VALUE obj, VALUE color) { - short r,g,b; + short r,g,b; - color_content(NUM2INT(color),&r,&g,&b); - return rb_ary_new3(3,INT2FIX(r),INT2FIX(g),INT2FIX(b)); + color_content(NUM2INT(color),&r,&g,&b); + return rb_ary_new3(3,INT2FIX(r),INT2FIX(g),INT2FIX(b)); } static VALUE curses_pair_content(VALUE obj, VALUE pair) { - short f,b; + short f,b; - pair_content(NUM2INT(pair),&f,&b); - return rb_ary_new3(2,INT2FIX(f),INT2FIX(b)); + pair_content(NUM2INT(pair),&f,&b); + return rb_ary_new3(2,INT2FIX(f),INT2FIX(b)); } static VALUE curses_color_pair(VALUE obj, VALUE attrs) { - return INT2FIX(COLOR_PAIR(NUM2INT(attrs))); + return INT2FIX(COLOR_PAIR(NUM2INT(attrs))); } static VALUE curses_pair_number(VALUE obj, VALUE attrs) { - return INT2FIX(PAIR_NUMBER(NUM2INT(attrs))); + return INT2FIX(PAIR_NUMBER(NUM2INT(attrs))); } #endif /* USE_COLOR */ #ifdef USE_MOUSE struct mousedata { - MEVENT *mevent; + MEVENT *mevent; }; static void no_mevent(void) { - rb_raise(rb_eRuntimeError, "no such mouse event"); + rb_raise(rb_eRuntimeError, "no such mouse event"); } #define GetMOUSE(obj, data) do {\ @@ -690,49 +728,49 @@ static void curses_mousedata_free(struct mousedata *mdata) { - if (mdata->mevent) - xfree(mdata->mevent); + if (mdata->mevent) + xfree(mdata->mevent); } static VALUE curses_getmouse(VALUE obj) { - struct mousedata *mdata; - VALUE val; + struct mousedata *mdata; + VALUE val; - val = Data_Make_Struct(cMouseEvent,struct mousedata, - 0,curses_mousedata_free,mdata); - mdata->mevent = (MEVENT*)xmalloc(sizeof(MEVENT)); - return (getmouse(mdata->mevent) == OK) ? val : Qnil; + val = Data_Make_Struct(cMouseEvent,struct mousedata, + 0,curses_mousedata_free,mdata); + mdata->mevent = (MEVENT*)xmalloc(sizeof(MEVENT)); + return (getmouse(mdata->mevent) == OK) ? val : Qnil; } static VALUE curses_ungetmouse(VALUE obj, VALUE mevent) { - struct mousedata *mdata; + struct mousedata *mdata; - GetMOUSE(mevent,mdata); - return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse; + GetMOUSE(mevent,mdata); + return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse; } static VALUE curses_mouseinterval(VALUE obj, VALUE interval) { - return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse; + return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse; } static VALUE curses_mousemask(VALUE obj, VALUE mask) { - return INT2NUM(mousemask(NUM2UINT(mask),NULL)); + return INT2NUM(mousemask(NUM2UINT(mask),NULL)); } #define DEFINE_MOUSE_GET_MEMBER(func_name,mem) \ static VALUE func_name (VALUE mouse) \ { \ - struct mousedata *mdata; \ - GetMOUSE(mouse, mdata); \ - return (UINT2NUM(mdata->mevent -> mem)); \ + struct mousedata *mdata; \ + GetMOUSE(mouse, mdata); \ + return (UINT2NUM(mdata->mevent -> mem)); \ } DEFINE_MOUSE_GET_MEMBER(curs_mouse_id, id) @@ -747,8 +785,8 @@ curses_timeout(VALUE obj, VALUE delay) { #ifdef HAVE_TIMEOUT - timeout(NUM2INT(delay)); - return Qnil; + timeout(NUM2INT(delay)); + return Qnil; #else rb_notimplement(); #endif @@ -758,7 +796,7 @@ curses_def_prog_mode(VALUE obj) { #ifdef HAVE_DEF_PROG_MODE - return def_prog_mode() == OK ? Qtrue : Qfalse; + return def_prog_mode() == OK ? Qtrue : Qfalse; #else rb_notimplement(); #endif @@ -768,7 +806,7 @@ curses_reset_prog_mode(VALUE obj) { #ifdef HAVE_RESET_PROG_MODE - return reset_prog_mode() == OK ? Qtrue : Qfalse; + return reset_prog_mode() == OK ? Qtrue : Qfalse; #else rb_notimplement(); #endif @@ -828,7 +866,7 @@ window_close(VALUE obj) { struct windata *winp; - + GetWINDOW(obj, winp); delwin(winp->window); winp->window = 0; @@ -841,10 +879,10 @@ window_clear(VALUE obj) { struct windata *winp; - + GetWINDOW(obj, winp); wclear(winp->window); - + return Qnil; } @@ -853,10 +891,10 @@ window_clrtoeol(VALUE obj) { struct windata *winp; - + GetWINDOW(obj, winp); wclrtoeol(winp->window); - + return Qnil; } @@ -865,10 +903,10 @@ window_refresh(VALUE obj) { struct windata *winp; - + GetWINDOW(obj, winp); wrefresh(winp->window); - + return Qnil; } @@ -893,7 +931,7 @@ window_move(VALUE obj, VALUE y, VALUE x) { struct windata *winp; - + GetWINDOW(obj, winp); mvwin(winp->window, NUM2INT(y), NUM2INT(x)); @@ -905,7 +943,7 @@ window_setpos(VALUE obj, VALUE y, VALUE x) { struct windata *winp; - + GetWINDOW(obj, winp); wmove(winp->window, NUM2INT(y), NUM2INT(x)); return Qnil; @@ -1011,7 +1049,7 @@ static VALUE window_box(int argc, VALUE *argv, VALUE self) { - struct windata *winp; + struct windata *winp; VALUE vert, hor, corn; rb_scan_args(argc, argv, "21", &vert, &hor, &corn); @@ -1020,24 +1058,24 @@ box(winp->window, NUM2CH(vert), NUM2CH(hor)); if (!NIL_P(corn)) { - int cur_x, cur_y, x, y; - chtype c; + int cur_x, cur_y, x, y; + chtype c; - c = NUM2CH(corn); - getyx(winp->window, cur_y, cur_x); - x = NUM2INT(window_maxx(self)) - 1; - y = NUM2INT(window_maxy(self)) - 1; - wmove(winp->window, 0, 0); - waddch(winp->window, c); - wmove(winp->window, y, 0); - waddch(winp->window, c); - wmove(winp->window, y, x); - waddch(winp->window, c); - wmove(winp->window, 0, x); - waddch(winp->window, c); - wmove(winp->window, cur_y, cur_x); + c = NUM2CH(corn); + getyx(winp->window, cur_y, cur_x); + x = NUM2INT(window_maxx(self)) - 1; + y = NUM2INT(window_maxy(self)) - 1; + wmove(winp->window, 0, 0); + waddch(winp->window, c); + wmove(winp->window, y, 0); + waddch(winp->window, c); + wmove(winp->window, y, x); + waddch(winp->window, c); + wmove(winp->window, 0, x); + waddch(winp->window, c); + wmove(winp->window, cur_y, cur_x); } - + return Qnil; } @@ -1046,7 +1084,7 @@ window_standout(VALUE obj) { struct windata *winp; - + GetWINDOW(obj, winp); wstandout(winp->window); return Qnil; @@ -1057,7 +1095,7 @@ window_standend(VALUE obj) { struct windata *winp; - + GetWINDOW(obj, winp); wstandend(winp->window); return Qnil; @@ -1068,7 +1106,7 @@ window_inch(VALUE obj) { struct windata *winp; - + GetWINDOW(obj, winp); return CH2FIX(winch(winp->window)); } @@ -1078,10 +1116,10 @@ window_addch(VALUE obj, VALUE ch) { struct windata *winp; - + GetWINDOW(obj, winp); waddch(winp->window, NUM2CH(ch)); - + return Qnil; } @@ -1090,10 +1128,10 @@ window_insch(VALUE obj, VALUE ch) { struct windata *winp; - + GetWINDOW(obj, winp); winsch(winp->window, NUM2CH(ch)); - + return Qnil; } @@ -1145,7 +1183,7 @@ { struct windata *winp; char rtn[1024]; /* This should be big enough.. I hope */ - + GetWINDOW(obj, winp); rb_read_check(stdin); #if defined(HAVE_WGETNSTR) @@ -1161,7 +1199,7 @@ window_delch(VALUE obj) { struct windata *winp; - + GetWINDOW(obj, winp); wdelch(winp->window); return Qnil; @@ -1173,7 +1211,7 @@ { #if defined(HAVE_WDELETELN) || defined(wdeleteln) struct windata *winp; - + GetWINDOW(obj, winp); wdeleteln(winp->window); #endif @@ -1186,7 +1224,7 @@ { #if defined(HAVE_WINSERTLN) || defined(winsertln) struct windata *winp; - + GetWINDOW(obj, winp); winsertln(winp->window); #endif @@ -1196,73 +1234,73 @@ static VALUE window_scrollok(VALUE obj, VALUE bf) { - struct windata *winp; + struct windata *winp; - GetWINDOW(obj, winp); - scrollok(winp->window, RTEST(bf) ? TRUE : FALSE); - return Qnil; + GetWINDOW(obj, winp); + scrollok(winp->window, RTEST(bf) ? TRUE : FALSE); + return Qnil; } static VALUE window_idlok(VALUE obj, VALUE bf) { - struct windata *winp; + struct windata *winp; - GetWINDOW(obj, winp); - idlok(winp->window, RTEST(bf) ? TRUE : FALSE); - return Qnil; + GetWINDOW(obj, winp); + idlok(winp->window, RTEST(bf) ? TRUE : FALSE); + return Qnil; } static VALUE window_setscrreg(VALUE obj, VALUE top, VALUE bottom) { #ifdef HAVE_WSETSCRREG - struct windata *winp; - int res; + struct windata *winp; + int res; - GetWINDOW(obj, winp); - res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom)); - /* may have to raise exception on ERR */ - return (res == OK) ? Qtrue : Qfalse; + GetWINDOW(obj, winp); + res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom)); + /* may have to raise exception on ERR */ + return (res == OK) ? Qtrue : Qfalse; #else - return Qfalse; + return Qfalse; #endif } #if defined(USE_COLOR) && defined(HAVE_WCOLOR_SET) static VALUE -window_color_set(VALUE obj, VALUE col) +window_color_set(VALUE obj, VALUE col) { - struct windata *winp; - int res; + struct windata *winp; + int res; - GetWINDOW(obj, winp); - res = wcolor_set(winp->window, NUM2INT(col), NULL); - return (res == OK) ? Qtrue : Qfalse; + GetWINDOW(obj, winp); + res = wcolor_set(winp->window, NUM2INT(col), NULL); + return (res == OK) ? Qtrue : Qfalse; } #endif /* defined(USE_COLOR) && defined(HAVE_WCOLOR_SET) */ static VALUE window_scroll(VALUE obj) { - struct windata *winp; + struct windata *winp; - GetWINDOW(obj, winp); - /* may have to raise exception on ERR */ - return (scroll(winp->window) == OK) ? Qtrue : Qfalse; + GetWINDOW(obj, winp); + /* may have to raise exception on ERR */ + return (scroll(winp->window) == OK) ? Qtrue : Qfalse; } static VALUE window_scrl(VALUE obj, VALUE n) { #ifdef HAVE_WSCRL - struct windata *winp; + struct windata *winp; - GetWINDOW(obj, winp); - /* may have to raise exception on ERR */ - return (wscrl(winp->window,NUM2INT(n)) == OK) ? Qtrue : Qfalse; + GetWINDOW(obj, winp); + /* may have to raise exception on ERR */ + return (wscrl(winp->window,NUM2INT(n)) == OK) ? Qtrue : Qfalse; #else - return Qfalse; + return Qfalse; #endif } @@ -1270,12 +1308,12 @@ window_attroff(VALUE obj, VALUE attrs) { #ifdef HAVE_WATTROFF - struct windata *winp; + struct windata *winp; - GetWINDOW(obj,winp); - return INT2FIX(wattroff(winp->window,NUM2INT(attrs))); + GetWINDOW(obj,winp); + return INT2FIX(wattroff(winp->window,NUM2INT(attrs))); #else - return Qtrue; + return Qtrue; #endif } @@ -1283,21 +1321,21 @@ window_attron(VALUE obj, VALUE attrs) { #ifdef HAVE_WATTRON - struct windata *winp; - VALUE val; + struct windata *winp; + VALUE val; - GetWINDOW(obj,winp); - val = INT2FIX(wattron(winp->window,NUM2INT(attrs))); - if( rb_block_given_p() ){ - rb_yield(val); - wattroff(winp->window,NUM2INT(attrs)); - return val; - } - else{ - return val; - } + GetWINDOW(obj,winp); + val = INT2FIX(wattron(winp->window,NUM2INT(attrs))); + if (rb_block_given_p()) { + rb_yield(val); + wattroff(winp->window,NUM2INT(attrs)); + return val; + } + else{ + return val; + } #else - return Qtrue; + return Qtrue; #endif } @@ -1305,12 +1343,12 @@ window_attrset(VALUE obj, VALUE attrs) { #ifdef HAVE_WATTRSET - struct windata *winp; + struct windata *winp; - GetWINDOW(obj,winp); - return INT2FIX(wattrset(winp->window,NUM2INT(attrs))); + GetWINDOW(obj,winp); + return INT2FIX(wattrset(winp->window,NUM2INT(attrs))); #else - return Qtrue; + return Qtrue; #endif } @@ -1318,24 +1356,24 @@ window_bkgdset(VALUE obj, VALUE ch) { #ifdef HAVE_WBKGDSET - struct windata *winp; + struct windata *winp; - GetWINDOW(obj,winp); - wbkgdset(winp->window, NUM2CH(ch)); + GetWINDOW(obj,winp); + wbkgdset(winp->window, NUM2CH(ch)); #endif - return Qnil; + return Qnil; } static VALUE window_bkgd(VALUE obj, VALUE ch) { #ifdef HAVE_WBKGD - struct windata *winp; + struct windata *winp; - GetWINDOW(obj,winp); - return (wbkgd(winp->window, NUM2CH(ch)) == OK) ? Qtrue : Qfalse; + GetWINDOW(obj,winp); + return (wbkgd(winp->window, NUM2CH(ch)) == OK) ? Qtrue : Qfalse; #else - return Qfalse; + return Qfalse; #endif } @@ -1343,13 +1381,13 @@ window_getbkgd(VALUE obj) { #ifdef HAVE_WGETBKGD - chtype c; - struct windata *winp; + chtype c; + struct windata *winp; - GetWINDOW(obj,winp); - return (c = getbkgd(winp->window) != ERR) ? CH2FIX(c) : Qnil; + GetWINDOW(obj,winp); + return (c = getbkgd(winp->window) != ERR) ? CH2FIX(c) : Qnil; #else - return Qnil; + return Qnil; #endif } @@ -1357,12 +1395,12 @@ window_resize(VALUE obj, VALUE lin, VALUE col) { #if defined(HAVE_WRESIZE) - struct windata *winp; + struct windata *winp; - GetWINDOW(obj,winp); - return wresize(winp->window, NUM2INT(lin), NUM2INT(col)) == OK ? Qtrue : Qfalse; + GetWINDOW(obj,winp); + return wresize(winp->window, NUM2INT(lin), NUM2INT(col)) == OK ? Qtrue : Qfalse; #else - return Qnil; + return Qnil; #endif } @@ -1371,17 +1409,17 @@ window_keypad(VALUE obj, VALUE val) { #ifdef HAVE_KEYPAD - struct windata *winp; + struct windata *winp; - GetWINDOW(obj,winp); - /* keypad() of NetBSD's libcurses returns no value */ + GetWINDOW(obj,winp); + /* keypad() of NetBSD's libcurses returns no value */ #if defined(__NetBSD__) && !defined(NCURSES_VERSION) - keypad(winp->window,(RTEST(val) ? TRUE : FALSE)); - return Qnil; + keypad(winp->window,(RTEST(val) ? TRUE : FALSE)); + return Qnil; #else - /* may have to raise exception on ERR */ - return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ? - Qtrue : Qfalse; + /* may have to raise exception on ERR */ + return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ? + Qtrue : Qfalse; #endif #else rb_notimplement(); @@ -1392,15 +1430,15 @@ window_nodelay(VALUE obj, VALUE val) { #ifdef HAVE_NODELAY - struct windata *winp; - GetWINDOW(obj,winp); + struct windata *winp; + GetWINDOW(obj,winp); - /* nodelay() of NetBSD's libcurses returns no value */ + /* nodelay() of NetBSD's libcurses returns no value */ #if defined(__NetBSD__) && !defined(NCURSES_VERSION) - nodelay(winp->window, RTEST(val) ? TRUE : FALSE); - return Qnil; + nodelay(winp->window, RTEST(val) ? TRUE : FALSE); + return Qnil; #else - return nodelay(winp->window,RTEST(val) ? TRUE : FALSE) == OK ? Qtrue : Qfalse; + return nodelay(winp->window,RTEST(val) ? TRUE : FALSE) == OK ? Qtrue : Qfalse; #endif #else rb_notimplement(); @@ -1411,11 +1449,11 @@ window_timeout(VALUE obj, VALUE delay) { #ifdef HAVE_WTIMEOUT - struct windata *winp; - GetWINDOW(obj,winp); + struct windata *winp; + GetWINDOW(obj,winp); - wtimeout(winp->window,NUM2INT(delay)); - return Qnil; + wtimeout(winp->window,NUM2INT(delay)); + return Qnil; #else rb_notimplement(); #endif @@ -1442,6 +1480,10 @@ rb_define_module_function(mCurses, "ESCDELAY=", curses_escdelay_set, 1); rb_define_module_function(mCurses, "ESCDELAY", curses_escdelay_get, 0); + rb_define_module_function(mCurses, "TABSIZE", curses_tabsize_get, 0); + rb_define_module_function(mCurses, "TABSIZE=", curses_tabsize_set, 1); + + rb_define_module_function(mCurses, "use_default_colors", curses_use_default_colors, 0); rb_define_module_function(mCurses, "init_screen", curses_init_screen, 0); rb_define_module_function(mCurses, "close_screen", curses_close_screen, 0); rb_define_module_function(mCurses, "closed?", curses_closed, 0); @@ -1731,14 +1773,14 @@ #ifdef KEY_F /* KEY_F(n) : 0 <= n <= 63 */ { - int i; - char c[8]; - for( i=0; i<64; i++ ){ - sprintf(c, "KEY_F%d", i); - rb_define_const(mCurses, c, INT2NUM(KEY_F(i))); - sprintf(c, "F%d", i); - rb_define_const(mKey, c, INT2NUM(KEY_F(i))); - } + int i; + char c[8]; + for (i=0; i<64; i++) { + sprintf(c, "KEY_F%d", i); + rb_define_const(mCurses, c, INT2NUM(KEY_F(i))); + sprintf(c, "F%d", i); + rb_define_const(mKey, c, INT2NUM(KEY_F(i))); + } } #endif #ifdef KEY_DL @@ -2074,12 +2116,12 @@ rb_define_const(mKey, "MAX", INT2NUM(KEY_MAX)); #endif { - int c; - char name[] = "KEY_CTRL_x"; - for( c = 'A'; c <= 'Z'; c++ ){ - sprintf(name, "KEY_CTRL_%c", c); - rb_define_const(mCurses, name, INT2FIX(c - 'A' + 1)); - } + int c; + char name[] = "KEY_CTRL_x"; + for (c = 'A'; c <= 'Z'; c++) { + name[sizeof(name) - 2] = c; + rb_define_const(mCurses, name, INT2FIX(c - 'A' + 1)); + } } #undef rb_curses_define_const Index: mvm/ext/curses/extconf.rb =================================================================== --- mvm/ext/curses/extconf.rb (revision 20597) +++ mvm/ext/curses/extconf.rb (revision 20598) @@ -21,7 +21,7 @@ end if make - for f in %w(beep bkgd bkgdset curs_set deleteln doupdate flash getbkgd getnstr init isendwin keyname keypad resizeterm scrl set setscrreg ungetch wattroff wattron wattrset wbkgd wbkgdset wdeleteln wgetnstr wresize wscrl wsetscrreg def_prog_mode reset_prog_mode timeout wtimeout nodelay init_color wcolor_set) + for f in %w(beep bkgd bkgdset curs_set deleteln doupdate flash getbkgd getnstr init isendwin keyname keypad resizeterm scrl set setscrreg ungetch wattroff wattron wattrset wbkgd wbkgdset wdeleteln wgetnstr wresize wscrl wsetscrreg def_prog_mode reset_prog_mode timeout wtimeout nodelay init_color wcolor_set use_default_colors) have_func(f) || (have_macro(f, curses) && $defs.push(format("-DHAVE_%s", f.upcase))) end flag = "-D_XOPEN_SOURCE_EXTENDED" @@ -29,5 +29,6 @@ $defs << flag end have_var("ESCDELAY", curses) + have_var("TABSIZE", curses) create_makefile("curses") end Index: mvm/.merged-trunk-revision =================================================================== --- mvm/.merged-trunk-revision (revision 20597) +++ mvm/.merged-trunk-revision (revision 20598) @@ -1 +1 @@ -20561 +20597 Index: mvm/cont.c =================================================================== --- mvm/cont.c (revision 20597) +++ mvm/cont.c (revision 20598) @@ -47,7 +47,7 @@ enum fiber_status { CREATED, RUNNING, - TERMINATED, + TERMINATED }; typedef struct rb_fiber_struct { Index: mvm/vm.c =================================================================== --- mvm/vm.c (revision 20597) +++ mvm/vm.c (revision 20598) @@ -198,15 +198,15 @@ check_env(rb_env_t * const env) { printf("---\n"); - printf("envptr: %p\n", &env->block.dfp[0]); + printf("envptr: %p\n", (void *)&env->block.dfp[0]); printf("orphan: %p\n", (void *)env->block.dfp[1]); printf("inheap: %p\n", (void *)env->block.dfp[2]); printf("envval: %10p ", (void *)env->block.dfp[3]); dp(env->block.dfp[3]); printf("penvv : %10p ", (void *)env->block.dfp[4]); dp(env->block.dfp[4]); - printf("lfp: %10p\n", env->block.lfp); - printf("dfp: %10p\n", env->block.dfp); + printf("lfp: %10p\n", (void *)env->block.lfp); + printf("dfp: %10p\n", (void *)env->block.dfp); if (env->block.dfp[4]) { printf(">>\n"); check_env_value(env->block.dfp[4]); @@ -1453,10 +1453,10 @@ } if (th->locking_mutex != Qfalse) { - rb_bug("thread_free: locking_mutex must be NULL (%p:%ld)", th, th->locking_mutex); + rb_bug("thread_free: locking_mutex must be NULL (%p:%ld)", (void *)th, th->locking_mutex); } if (th->keeping_mutexes != NULL) { - rb_bug("thread_free: keeping_mutexes must be NULL (%p:%ld)", th, th->locking_mutex); + rb_bug("thread_free: keeping_mutexes must be NULL (%p:%ld)", (void *)th, th->locking_mutex); } if (th->local_storage) { Index: mvm/version.h =================================================================== --- mvm/version.h (revision 20597) +++ mvm/version.h (revision 20598) @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_RELEASE_DATE "2008-12-06" +#define RUBY_RELEASE_DATE "2008-12-09" #define RUBY_VERSION_CODE 191 -#define RUBY_RELEASE_CODE 20081206 +#define RUBY_RELEASE_CODE 20081209 #define RUBY_PATCHLEVEL 5000 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_YEAR 2008 #define RUBY_RELEASE_MONTH 12 -#define RUBY_RELEASE_DAY 6 +#define RUBY_RELEASE_DAY 9 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; Index: mvm/vm_dump.c =================================================================== --- mvm/vm_dump.c (revision 20597) +++ mvm/vm_dump.c (revision 20598) @@ -196,7 +196,7 @@ fprintf(stderr, "--\n"); for (i = 0; i < env->env_size; i++) { fprintf(stderr, "%04d: %08lx (%p)", -env->local_size + i, env->env[i], - &env->env[i]); + (void *)&env->env[i]); if (&env->env[i] == lfp) fprintf(stderr, " <- lfp"); if (&env->env[i] == dfp) @@ -295,12 +295,12 @@ for (i = 0; i < argc; i++) { rstr = rb_inspect(*ptr); fprintf(stderr, " arg %2d: %8s (%p)\n", i, StringValueCStr(rstr), - ptr++); + (void *)ptr++); } for (; i < local_size - 1; i++) { rstr = rb_inspect(*ptr); fprintf(stderr, " local %2d: %8s (%p)\n", i, StringValueCStr(rstr), - ptr++); + (void *)ptr++); } ptr = cfp->bp; @@ -562,8 +562,8 @@ cfp = th->cfp; fprintf(stderr, "Thread state dump:\n"); - fprintf(stderr, "pc : %p, sp : %p\n", cfp->pc, cfp->sp); - fprintf(stderr, "cfp: %p, lfp: %p, dfp: %p\n", cfp, cfp->lfp, cfp->dfp); + fprintf(stderr, "pc : %p, sp : %p\n", (void *)cfp->pc, (void *)cfp->sp); + fprintf(stderr, "cfp: %p, lfp: %p, dfp: %p\n", (void *)cfp, (void *)cfp->lfp, (void *)cfp->dfp); return Qnil; } Index: mvm/vm_insnhelper.c =================================================================== --- mvm/vm_insnhelper.c (revision 20597) +++ mvm/vm_insnhelper.c (revision 20598) @@ -1441,7 +1441,7 @@ } static inline int -check_cfunc(const NODE *mn, const void *func) +check_cfunc(const NODE *mn, VALUE (*func)()) { if (mn && nd_type(mn->nd_body) == NODE_CFUNC && mn->nd_body->nd_cfnc == func) { Index: mvm/vm_insnhelper.h =================================================================== --- mvm/vm_insnhelper.h (revision 20597) +++ mvm/vm_insnhelper.h (revision 20598) @@ -53,7 +53,7 @@ BOP_NOT, BOP_NEQ, - BOP_LAST_, + BOP_LAST_ }; #define ruby_vm_redefined_flag GET_VM()->redefined_flag Index: mvm/ruby.c =================================================================== --- mvm/ruby.c (revision 20597) +++ mvm/ruby.c (revision 20598) @@ -54,25 +54,28 @@ #define DISABLE_BIT(bit) (1U << disable_##bit) enum disable_flag_bits { disable_gems, - disable_rubyopt + disable_rubyopt, + disable_flag_count }; #define DUMP_BIT(bit) (1U << dump_##bit) enum dump_flag_bits { - dump_insns + dump_version, + dump_copyright, + dump_usage, + dump_yydebug, + dump_syntax, + dump_insns, + dump_flag_count }; struct cmdline_options { int sflag, xflag; int do_loop, do_print; - int do_check, do_line; - int do_split, do_search; - int usage; - int version; - int copyright; + int do_line, do_split; + int do_search; unsigned int disable; int verbose; - int yydebug; int safe_level; unsigned int setids; unsigned int dump; @@ -615,45 +618,42 @@ dump_option(const char *str, int len, void *arg) { #define SET_WHEN_DUMP(bit) SET_WHEN(#bit, DUMP_BIT(bit), str, len) + SET_WHEN_DUMP(version); + SET_WHEN_DUMP(copyright); + SET_WHEN_DUMP(usage); + SET_WHEN_DUMP(yydebug); + SET_WHEN_DUMP(syntax); SET_WHEN_DUMP(insns); - rb_warn("don't know how to dump `%.*s', (insns)", len, str); + rb_warn("don't know how to dump `%.*s',", len, str); + rb_warn("but only [version, copyright, usage, yydebug, syntax, insns]."); } #define RUBY_VM_OBJECT(vm, name) \ (*((VALUE *)ruby_vm_specific_ptr(vm, rb_vmkey_##name))) static void -set_internal_encoding_once(struct cmdline_options *opt, const char *e, int elen) +set_option_encoding_once(const char *type, VALUE *name, const char *e, int elen) { VALUE ename; if (!elen) elen = strlen(e); ename = rb_str_new(e, elen); - if (opt->intern.enc.name && - rb_funcall(ename, rb_intern("casecmp"), 1, opt->intern.enc.name) != INT2FIX(0)) { + if (*name && + rb_funcall(ename, rb_intern("casecmp"), 1, *name) != INT2FIX(0)) { rb_raise(rb_eRuntimeError, - "default_internal already set to %s", RSTRING_PTR(opt->intern.enc.name)); + "%s already set to %s", type, RSTRING_PTR(*name)); } - opt->intern.enc.name = ename; + *name = ename; } -static void -set_external_encoding_once(struct cmdline_options *opt, const char *e, int elen) -{ - VALUE ename; +#define set_internal_encoding_once(opt, e, elen) \ + set_option_encoding_once("default_intenal", &opt->intern.enc.name, e, elen) +#define set_external_encoding_once(opt, e, elen) \ + set_option_encoding_once("default_extenal", &opt->ext.enc.name, e, elen) +#define set_source_encoding_once(opt, e, elen) \ + set_option_encoding_once("source", &opt->src.enc.name, e, elen) - if (!elen) elen = strlen(e); - ename = rb_str_new(e, elen); - - if (opt->ext.enc.name && - rb_funcall(ename, rb_intern("casecmp"), 1, opt->ext.enc.name) != INT2FIX(0)) { - rb_raise(rb_eRuntimeError, - "default_external already set to %s", RSTRING_PTR(opt->ext.enc.name)); - } - opt->ext.enc.name = ename; -} - static int proc_options(rb_vm_t *vm, int argc, char **argv, struct cmdline_options *opt, int envopt) { @@ -664,10 +664,11 @@ return 0; for (argc--, argv++; argc > 0; argc--, argv++) { - if (argv[0][0] != '-' || !argv[0][1]) + const char *const arg = argv[0]; + if (arg[0] != '-' || !arg[1]) break; - s = argv[0] + 1; + s = arg + 1; reswitch: switch (*s) { case 'a': @@ -694,7 +695,7 @@ case 'y': if (envopt) goto noenvopt; - opt->yydebug = 1; + opt->dump |= DUMP_BIT(yydebug); s++; goto reswitch; @@ -737,7 +738,7 @@ case 'c': if (envopt) goto noenvopt; - opt->do_check = Qtrue; + opt->dump |= DUMP_BIT(syntax); s++; goto reswitch; @@ -750,9 +751,8 @@ case 'h': if (envopt) goto noenvopt; - usage(origarg.argv[0]); - rb_exit(EXIT_SUCCESS); - break; + opt->dump |= DUMP_BIT(usage); + goto switch_end; case 'l': if (envopt) goto noenvopt; @@ -941,7 +941,7 @@ if (strcmp("copyright", s) == 0) { if (envopt) goto noenvopt_long; - opt->copyright = 1; + opt->dump |= DUMP_BIT(copyright); } else if (strcmp("debug", s) == 0) { RUBY_VM_OBJECT(vm, debug) = Qtrue; @@ -956,19 +956,42 @@ else if (is_option_with_arg("encoding", Qfalse, Qtrue)) { char *p; encoding: - p = strchr(s, ':'); - if (p) { - if (p > s) - set_external_encoding_once(opt, s, p-s); - if (*++p) - set_internal_encoding_once(opt, p, 0); - } - else - set_external_encoding_once(opt, s, 0); + do { +# define set_encoding_part(type) \ + if (!(p = strchr(s, ':'))) { \ + set_##type##_encoding_once(opt, s, 0); \ + break; \ + } \ + else if (p > s) { \ + set_##type##_encoding_once(opt, s, p-s); \ + } + set_encoding_part(external); + if (!*(s = ++p)) break; + set_encoding_part(internal); + if (!*(s = ++p)) break; +#if ALLOW_DEFAULT_SOURCE_ENCODING + set_encoding_part(source); + if (!*(s = ++p)) break; +#endif + rb_raise(rb_eRuntimeError, "extra argument for %s: %s", + (arg[1] == '-' ? "--encoding" : "-E"), s); +# undef set_encoding_part + } while (0); } + else if (is_option_with_arg("internal-encoding", Qfalse, Qtrue)) { + set_internal_encoding_once(opt, s, 0); + } + else if (is_option_with_arg("external-encoding", Qfalse, Qtrue)) { + set_external_encoding_once(opt, s, 0); + } +#if ALLOW_DEFAULT_SOURCE_ENCODING + else if (is_option_with_arg("source-encoding", Qfalse, Qtrue)) { + set_source_encoding_once(opt, s, 0); + } +#endif else if (strcmp("version", s) == 0) { if (envopt) goto noenvopt_long; - opt->version = 1; + opt->dump |= DUMP_BIT(version); } else if (strcmp("verbose", s) == 0) { opt->verbose = 1; @@ -976,15 +999,15 @@ } else if (strcmp("yydebug", s) == 0) { if (envopt) goto noenvopt_long; - opt->yydebug = 1; + opt->dump |= DUMP_BIT(yydebug); } else if (is_option_with_arg("dump", Qfalse, Qfalse)) { ruby_each_words(s, dump_option, &opt->dump); } else if (strcmp("help", s) == 0) { if (envopt) goto noenvopt_long; - usage(origarg.argv[0]); - rb_exit(EXIT_SUCCESS); + opt->dump |= DUMP_BIT(usage); + goto switch_end; } else { rb_raise(rb_eRuntimeError, @@ -1061,6 +1084,21 @@ VALUE rb_argv0; static VALUE +false_value(void) +{ + return Qfalse; +} + +static VALUE +true_value(void) +{ + return Qtrue; +} + +#define rb_define_readonly_boolean(name, val) \ + rb_define_virtual_variable((name), (val) ? true_value : false_value, 0) + +static VALUE process_options(VALUE arg) { struct cmdline_arguments *argp = (struct cmdline_arguments *)arg; @@ -1079,6 +1117,11 @@ argc -= i; argv += i; + if (opt->dump & DUMP_BIT(usage)) { + usage(origarg.argv[0]); + return Qtrue; + } + if (!(opt->disable & DISABLE_BIT(rubyopt)) && opt->safe_level == 0 && (s = getenv("RUBYOPT"))) { VALUE src_enc_name = opt->src.enc.name; @@ -1095,11 +1138,11 @@ opt->intern.enc.name = int_enc_name; } - if (opt->version) { + if (opt->dump & DUMP_BIT(version)) { ruby_show_version(); return Qtrue; } - if (opt->copyright) { + if (opt->dump & DUMP_BIT(copyright)) { ruby_show_copyright(); } @@ -1151,7 +1194,9 @@ rb_enc_associate(rb_progname, lenc); opt->script_name = rb_str_new4(rb_progname); parser = rb_parser_new(); - if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue); + if (opt->dump & DUMP_BIT(yydebug)) { + rb_parser_set_yydebug(parser, Qtrue); + } if (opt->ext.enc.name != 0) { opt->ext.enc.index = opt_enc_index(opt->ext.enc.name); } @@ -1195,6 +1240,7 @@ } tree = load_file(vm, parser, opt->script, 1, opt); } + if (opt->dump & DUMP_BIT(yydebug)) return Qtrue; if (opt->intern.enc.index >= 0) { /* Set in the shebang line */ @@ -1215,7 +1261,7 @@ FL_UNSET(GET_VM()->load_path, FL_TAINT); } - if (opt->do_check) { + if (opt->dump & DUMP_BIT(syntax)) { printf("Syntax OK\n"); return Qtrue; } @@ -1236,6 +1282,10 @@ return Qtrue; } + rb_define_readonly_boolean("$-p", opt->do_print); + rb_define_readonly_boolean("$-l", opt->do_line); + rb_define_readonly_boolean("$-a", opt->do_split); + rb_set_safe_level(opt->safe_level); return iseq; @@ -1629,21 +1679,6 @@ #endif } -static VALUE -false_value(void) -{ - return Qfalse; -} - -static VALUE -true_value(void) -{ - return Qtrue; -} - -#define rb_define_readonly_boolean(name, val) \ - rb_define_virtual_variable((name), (val) ? true_value : false_value, 0) - VALUE ruby_vm_process_options(rb_vm_t *vm, int argc, char **argv) { @@ -1664,10 +1699,6 @@ tree = rb_vm_call_cfunc(vm->top_self, process_options, (VALUE)&args, 0, RUBY_VM_OBJECT(vm, progname)); - - rb_define_readonly_boolean("$-p", opt.do_print); - rb_define_readonly_boolean("$-l", opt.do_line); - rb_define_readonly_boolean("$-a", opt.do_split); return tree; } Index: mvm/tool/make-snapshot =================================================================== --- mvm/tool/make-snapshot (revision 20597) +++ mvm/tool/make-snapshot (revision 20598) @@ -151,6 +151,8 @@ f.puts "s,@OBJEXT@,|#_!!_#|o,g" f.puts "s,@LIBRUBY@,|#_!!_#|liburyb.a,g" f.puts "s,@LIBRUBY_A@,|#_!!_#|liburyb.a,g" + f.puts "s,@RM@,|#_!!_#|rm -f,g" + f.puts "s,@CP@,|#_!!_#|cp,g" } FileUtils.mkpath(hdrdir = "#{extout}/include/ruby") File.open("#{hdrdir}/config.h", "w") {} @@ -159,6 +161,14 @@ f.puts(IO.read("Makefile.in")[/^lex\.c.*?^$/m]) f.puts(commonmk.gsub(/\{[^{}]*\}/, "")) end + File.open("enc.mk", "r+b") do |f| + data = f.read + data.gsub!(/^((?:ENC|TRANS)(?:OBJ|SO)(?:S|DIR)\s*=)(?:.*\\\n)*.*/, '\1') + data.sub!(/^(clean:.*)(?:\n\t.*)+/, '\1') + f.rewind + f.truncate(0) + f.print data + end clean.push("rbconfig.rb", ".rbconfig.time") print "prerequisites" else Index: mvm/test/ruby/test_pack.rb =================================================================== --- mvm/test/ruby/test_pack.rb (revision 20597) +++ mvm/test/ruby/test_pack.rb (revision 20598) @@ -179,11 +179,23 @@ assert_equal("", ["10ef"].pack("h0")) assert_equal("\x01\x0e", ["10ef"].pack("h3")) assert_equal("\x01\xfe\x0", ["10ef"].pack("h5")) + assert_equal("\xff\x0f", ["fff"].pack("h3")) + assert_equal("\xff\x0f", ["fff"].pack("h4")) + assert_equal("\xff\x0f\0", ["fff"].pack("h5")) + assert_equal("\xff\x0f\0", ["fff"].pack("h6")) + assert_equal("\xff\x0f\0\0", ["fff"].pack("h7")) + assert_equal("\xff\x0f\0\0", ["fff"].pack("h8")) assert_equal("\x10\xef", ["10ef"].pack("H*")) assert_equal("", ["10ef"].pack("H0")) assert_equal("\x10\xe0", ["10ef"].pack("H3")) assert_equal("\x10\xef\x0", ["10ef"].pack("H5")) + assert_equal("\xff\xf0", ["fff"].pack("H3")) + assert_equal("\xff\xf0", ["fff"].pack("H4")) + assert_equal("\xff\xf0\0", ["fff"].pack("H5")) + assert_equal("\xff\xf0\0", ["fff"].pack("H6")) + assert_equal("\xff\xf0\0\0", ["fff"].pack("H7")) + assert_equal("\xff\xf0\0\0", ["fff"].pack("H8")) assert_equal(["10ef"], "\x01\xfe".unpack("h*")) assert_equal([""], "\x01\xfe".unpack("h0")) @@ -349,6 +361,10 @@ assert_equal("M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n!80``\n", ["a"*46].pack("u")) assert_equal("&86)C9&5F\n#9VAI\n", ["abcdefghi"].pack("u6")) + assert_equal("M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n!80``\n", ["a"*46].pack("u0")) + assert_equal("M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n!80``\n", ["a"*46].pack("u1")) + assert_equal("M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n!80``\n", ["a"*46].pack("u2")) + assert_equal([""], "".unpack("u")) assert_equal(["a"], "!80``\n".unpack("u")) assert_equal(["abc"], "#86)C\n".unpack("u")) Index: mvm/test/test_open3.rb =================================================================== --- mvm/test/test_open3.rb (revision 20597) +++ mvm/test/test_open3.rb (revision 20598) @@ -123,28 +123,28 @@ } end - def test_poutput3 - o, e, s = Open3.poutput3(RUBY, '-e', 'i=STDIN.read; print i+"o"; STDOUT.flush; STDERR.print i+"e"', :stdin_data=>"i") + def test_capture3 + o, e, s = Open3.capture3(RUBY, '-e', 'i=STDIN.read; print i+"o"; STDOUT.flush; STDERR.print i+"e"', :stdin_data=>"i") assert_equal("io", o) assert_equal("ie", e) assert(s.success?) end - def test_poutput3_flip - o, e, s = Open3.poutput3(RUBY, '-e', 'STDOUT.sync=true; 1000.times { print "o"*1000; STDERR.print "e"*1000 }') + def test_capture3_flip + o, e, s = Open3.capture3(RUBY, '-e', 'STDOUT.sync=true; 1000.times { print "o"*1000; STDERR.print "e"*1000 }') assert_equal("o"*1000000, o) assert_equal("e"*1000000, e) assert(s.success?) end - def test_poutput2 - o, s = Open3.poutput2(RUBY, '-e', 'i=STDIN.read; print i+"o"', :stdin_data=>"i") + def test_capture2 + o, s = Open3.capture2(RUBY, '-e', 'i=STDIN.read; print i+"o"', :stdin_data=>"i") assert_equal("io", o) assert(s.success?) end - def test_poutput2e - oe, s = Open3.poutput2e(RUBY, '-e', 'i=STDIN.read; print i+"o"; STDOUT.flush; STDERR.print i+"e"', :stdin_data=>"i") + def test_capture2e + oe, s = Open3.capture2e(RUBY, '-e', 'i=STDIN.read; print i+"o"; STDOUT.flush; STDERR.print i+"e"', :stdin_data=>"i") assert_equal("ioie", oe) assert(s.success?) end Index: mvm/template/yasmdata.rb.tmpl =================================================================== --- mvm/template/yasmdata.rb.tmpl (revision 20597) +++ mvm/template/yasmdata.rb.tmpl (revision 20598) @@ -7,7 +7,7 @@ InsnID2NO = { <%= insn_id2no %> } - + def self.id2insn_no id if InsnID2NO.has_key? id InsnID2NO[id] Index: mvm/template/vm.inc.tmpl =================================================================== --- mvm/template/vm.inc.tmpl (revision 20597) +++ mvm/template/vm.inc.tmpl (revision 20598) @@ -3,7 +3,7 @@ /*******************************************************************/ /** This file is VM main loop. - + ---- This file is auto generated by insns2vm.rb DO NOT TOUCH! Index: mvm/template/insns_info.inc.tmpl =================================================================== --- mvm/template/insns_info.inc.tmpl (revision 20597) +++ mvm/template/insns_info.inc.tmpl (revision 20598) @@ -1,10 +1,10 @@ /** -*-c-*- This file contains instruction information for yarv instruction sequence. - + ---- This file is auto generated by insns2vm.rb DO NOT TOUCH! - + If you want to fix something, you must edit 'template/insns_info.inc.tmpl' or insns2vm.rb */ Index: mvm/template/minsns.inc.tmpl =================================================================== --- mvm/template/minsns.inc.tmpl (revision 20597) +++ mvm/template/minsns.inc.tmpl (revision 20598) @@ -1,6 +1,6 @@ /** -*-c-*- This file contains YARV instructions list, to define YARVCore::Instructions. - + ---- This file is auto generated by insns2vm.rb DO NOT TOUCH! Index: mvm/template/opt_sc.inc.tmpl =================================================================== --- mvm/template/opt_sc.inc.tmpl (revision 20597) +++ mvm/template/opt_sc.inc.tmpl (revision 20598) @@ -3,7 +3,7 @@ /*******************************************************************/ /** This file is for threaded code. - + ---- This file is auto generated by insns2vm.rb DO NOT TOUCH! Index: mvm/template/optunifs.inc.tmpl =================================================================== --- mvm/template/optunifs.inc.tmpl (revision 20597) +++ mvm/template/optunifs.inc.tmpl (revision 20598) @@ -3,7 +3,7 @@ /*******************************************************************/ /** This file is for threaded code. - + ---- This file is auto generated by insns2vm.rb DO NOT TOUCH! @@ -21,7 +21,7 @@ UNIFIED_insn_name_1, UNIFIED_insn_name_2, ...}; ... - + static const int *const *const unified_insns_data[] = { UNIFIED_insn_nameA, UNIFIED_insn_nameB, ...}; Index: mvm/template/known_errors.inc.tmpl =================================================================== --- mvm/template/known_errors.inc.tmpl (revision 20597) +++ mvm/template/known_errors.inc.tmpl (revision 20598) @@ -1,4 +1,4 @@ -/** -*-c-*- +/** -*-c-*- * DO NOT EDIT * This file is automatically generated by tools/generic_erb.rb from * template/known_errors.inc.tmpl and defs/known_errors.def. Index: mvm/template/vmtc.inc.tmpl =================================================================== --- mvm/template/vmtc.inc.tmpl (revision 20597) +++ mvm/template/vmtc.inc.tmpl (revision 20598) @@ -3,7 +3,7 @@ /*******************************************************************/ /** This file is for threaded code. - + ---- This file is auto generated by insns2vm.rb DO NOT TOUCH! Index: mvm/template/id.h.tmpl =================================================================== --- mvm/template/id.h.tmpl (revision 20597) +++ mvm/template/id.h.tmpl (revision 20598) @@ -2,7 +2,7 @@ /* DO NOT EDIT THIS FILE DIRECTLY */ /********************************************************************** - id.h - + id.h - $Author$ created at: Sun Oct 19 21:12:51 2008 Index: mvm/template/insns.inc.tmpl =================================================================== --- mvm/template/insns.inc.tmpl (revision 20597) +++ mvm/template/insns.inc.tmpl (revision 20598) @@ -1,6 +1,6 @@ /** -*-c-*- This file contains YARV instructions list. - + ---- This file is auto generated by insns2vm.rb DO NOT TOUCH! @@ -15,7 +15,6 @@ enum ruby_vminsn_type { <%= insns %> + VM_INSTRUCTION_SIZE = <%= @insns.size %> }; -#define VM_INSTRUCTION_SIZE <%= @insns.size %> - Index: mvm/template/optinsn.inc.tmpl =================================================================== --- mvm/template/optinsn.inc.tmpl (revision 20597) +++ mvm/template/optinsn.inc.tmpl (revision 20598) @@ -3,7 +3,7 @@ /*******************************************************************/ /** This file is for threaded code. - + ---- This file is auto generated by insns2vm.rb DO NOT TOUCH! -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/