ruby-changes:8464
From: usa <ko1@a...>
Date: Tue, 28 Oct 2008 21:01:03 +0900 (JST)
Subject: [ruby-changes:8464] Ruby:r19996 (trunk): * io.c (extract_binmode): new function to extract binmode/textmode
usa 2008-10-28 21:00:42 +0900 (Tue, 28 Oct 2008) New Revision: 19996 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19996 Log: * io.c (extract_binmode): new function to extract binmode/textmode options from hash. * io.c (rb_io_extract_modeenc): use above function. * io.c (rb_io_s_pipe): recognize binmode/textmode options. Modified files: trunk/ChangeLog trunk/io.c Index: ChangeLog =================================================================== --- ChangeLog (revision 19995) +++ ChangeLog (revision 19996) @@ -1,3 +1,12 @@ +Tue Oct 28 20:59:12 2008 NAKAMURA Usaku <usa@r...> + + * io.c (extract_binmode): new function to extract binmode/textmode + options from hash. + + * io.c (rb_io_extract_modeenc): use above function. + + * io.c (rb_io_s_pipe): recognize binmode/textmode options. + Tue Oct 28 20:15:49 2008 NAKAMURA Usaku <usa@r...> * io.c (make_readconv): now can specify the size of cbuf. Index: io.c =================================================================== --- io.c (revision 19995) +++ io.c (revision 19996) @@ -3923,6 +3923,23 @@ } static void +extract_binmode(VALUE opthash, int *fmode) +{ + if (!NIL_P(opthash)) { + VALUE v; + v = rb_hash_aref(opthash, sym_textmode); + if (!NIL_P(v) && RTEST(v)) + *fmode |= FMODE_TEXTMODE; + v = rb_hash_aref(opthash, sym_binmode); + if (!NIL_P(v) && RTEST(v)) + *fmode |= FMODE_BINMODE; + + if ((*fmode & FMODE_BINMODE) && (*fmode & FMODE_TEXTMODE)) + rb_raise(rb_eArgError, "both textmode and binmode specified"); + } +} + +static void rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, int *oflags_p, int *fmode_p, convconfig_t *convconfig_p) { @@ -3975,16 +3992,11 @@ } else { VALUE v; - v = rb_hash_aref(opthash, sym_textmode); - if (!NIL_P(v) && RTEST(v)) - fmode |= FMODE_TEXTMODE; - v = rb_hash_aref(opthash, sym_binmode); - if (!NIL_P(v) && RTEST(v)) { - fmode |= FMODE_BINMODE; + extract_binmode(opthash, &fmode); #ifdef O_BINARY + if (fmode & FMODE_BINMODE) oflags |= O_BINARY; #endif - } if (!has_vmode) { v = rb_hash_aref(opthash, sym_mode); if (!NIL_P(v)) { @@ -4017,9 +4029,6 @@ } } - if ((fmode & FMODE_BINMODE) && (fmode & FMODE_TEXTMODE)) - rb_raise(rb_eArgError, "both textmode and binmode specified"); - validate_enc_binmode(fmode, enc, enc2); *vmode_p = vmode; @@ -6825,7 +6834,8 @@ int pipes[2], state; VALUE r, w, args[3], v1, v2; VALUE opt; - rb_io_t *fptr; + rb_io_t *fptr, *fptr2; + int fmode = 0; opt = pop_last_hash(&argc, argv); rb_scan_args(argc, argv, "02", &v1, &v2); @@ -6851,8 +6861,13 @@ if (!NIL_P(r)) rb_io_close(r); rb_jump_tag(state); } - rb_io_synchronized(RFILE(w)->fptr); + GetOpenFile(w, fptr2); + rb_io_synchronized(fptr2); + extract_binmode(opt, &fmode); + fptr->mode |= fmode; + fptr2->mode |= fmode; + return rb_assoc_new(r, w); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/