なかだです。

StringIO.newの第二引数は今のところStringでしか指定できませんが、
これをIO.new同様Fixnumも使えるようにしようかと思います。という
ことで、rb_io_modenum_flagsをexternにしたいのですがどうでしょう
か。


* io.c, rubyio.h (rb_io_modenum_flags): exported.

* ext/stringio/stringio.c (strio_initialize): allow Fixnum as mode.


Index: io.c =================================================================== RCS file: /cvs/ruby/src/ruby/io.c,v retrieving revision 1.318 diff -U2 -p -d -r1.318 io.c --- io.c 10 Nov 2004 07:16:24 -0000 1.318 +++ io.c 16 Nov 2004 07:29:11 -0000 @@ -2390,5 +2390,5 @@ rb_io_mode_flags(mode) } -static int +int rb_io_modenum_flags(mode) int mode; Index: rubyio.h =================================================================== RCS file: /cvs/ruby/src/ruby/rubyio.h,v retrieving revision 1.29 diff -U2 -p -d -r1.29 rubyio.h --- rubyio.h 29 Oct 2004 12:28:04 -0000 1.29 +++ rubyio.h 16 Nov 2004 07:29:10 -0000 @@ -66,4 +66,5 @@ long rb_io_fread _((char *, long, FILE * long rb_io_fwrite _((const char *, long, FILE *)); int rb_io_mode_flags _((const char*)); +int rb_io_modenum_flags _((int)); void rb_io_check_writable _((OpenFile*)); void rb_io_check_readable _((OpenFile*)); Index: ext/stringio/stringio.c =================================================================== RCS file: /cvs/ruby/src/ruby/ext/stringio/stringio.c,v retrieving revision 1.32 diff -U2 -p -d -r1.32 stringio.c --- ext/stringio/stringio.c 16 Nov 2004 07:20:54 -0000 1.32 +++ ext/stringio/stringio.c 16 Nov 2004 07:24:27 -0000 @@ -202,5 +202,5 @@ strio_initialize(argc, argv, self) struct StringIO *ptr = check_strio(self); VALUE string, mode; - const char* m; + int trunc = Qfalse; if (!ptr) { @@ -210,19 +210,21 @@ strio_initialize(argc, argv, self) switch (rb_scan_args(argc, argv, "02", &string, &mode)) { case 2: - StringValue(mode); + if (FIXNUM_P(mode)) { + int flags = FIX2INT(mode); + ptr->flags = rb_io_modenum_flags(flags); + trunc = flags & O_TRUNC; + } + else { + const char *m = StringValueCStr(mode); + ptr->flags = rb_io_mode_flags(m); + trunc = *m == 'w'; + } StringValue(string); - if (!(m = RSTRING(mode)->ptr)) m = ""; - ptr->flags = rb_io_mode_flags(m); if ((ptr->flags & FMODE_WRITABLE) && OBJ_FROZEN(string)) { errno = EACCES; rb_sys_fail(0); } - switch (*m) { - case 'a': - ptr->flags |= FMODE_APPEND; - break; - case 'w': + if (trunc) { rb_str_resize(string, 0); - break; } break;
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦