From 64eba95e4076f0a66b41bddcc5c524151d5db729 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 20 Dec 2002 08:33:17 +0000 Subject: * parse.y (do_block): split "do" block and tLBRACE_ARG block. * parse.y (cmd_brace_block): new tLBRACE_ARG block rule * parse.y (command): can take optional cmd_brace_block; use %prec to resolve shift/reduce conflict. (ruby-bugs-ja PR#372) * eval.c (ruby_finalize): trace_func should be cleared here (after executing exit procs and finalizers). * eval.c (rb_define_alloc_func): new allocation framework, based on Nobu's work [ruby-dev:19116]. "allocate" method is no longer used for object allocation. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 6c8379802..8987fd305 100644 --- a/io.c +++ b/io.c @@ -275,6 +275,18 @@ ruby_dup(orig) return fd; } +static VALUE +io_alloc(klass) + VALUE klass; +{ + NEWOBJ(io, struct RFile); + OBJSETUP(io, klass, T_FILE); + + io->fptr = 0; + + return (VALUE)io; +} + static void io_fflush(f, fptr) FILE *f; @@ -1813,9 +1825,7 @@ VALUE rb_file_open(fname, mode) const char *fname, *mode; { - VALUE io = rb_obj_alloc(rb_cFile); - - return rb_file_open_internal(io, fname, mode); + return rb_file_open_internal(io_alloc(rb_cFile), fname, mode); } static VALUE @@ -1845,9 +1855,7 @@ rb_file_sysopen(fname, flags, mode) const char *fname; int flags, mode; { - VALUE io = rb_obj_alloc(rb_cFile); - - return rb_file_sysopen_internal(io, fname, flags, mode); + return rb_file_sysopen_internal(io_alloc(rb_cFile)); } #if defined (_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__VMS) @@ -1960,7 +1968,7 @@ pipe_open(pname, mode) if (!f) rb_sys_fail(pname); else { - VALUE port = rb_obj_alloc(rb_cIO); + VALUE port = io_alloc(rb_cIO); MakeOpenFile(port, fptr); fptr->finalize = pipe_finalize; @@ -1990,7 +1998,7 @@ retry: rb_sys_fail(pname); } else { - VALUE port = rb_obj_alloc(rb_cIO); + VALUE port = io_alloc(rb_cIO); MakeOpenFile(port, fptr); fptr->mode = modef; @@ -2067,7 +2075,7 @@ retry: default: /* parent */ if (pid < 0) rb_sys_fail(pname); else { - VALUE port = rb_obj_alloc(rb_cIO); + VALUE port = io_alloc(rb_cIO); MakeOpenFile(port, fptr); fptr->mode = modef; @@ -2758,7 +2766,7 @@ prep_stdio(f, mode, klass) VALUE klass; { OpenFile *fp; - VALUE io = rb_obj_alloc(klass); + VALUE io = io_alloc(klass); MakeOpenFile(io, fp); fp->f = f; @@ -2779,18 +2787,6 @@ prep_path(io, path) fptr->path = strdup(path); } -static VALUE -rb_io_s_alloc(klass) - VALUE klass; -{ - NEWOBJ(io, struct RFile); - OBJSETUP(io, klass, T_FILE); - - io->fptr = 0; - - return (VALUE)io; -} - static VALUE rb_io_initialize(argc, argv, io) int argc; @@ -3903,7 +3899,7 @@ Init_IO() rb_cIO = rb_define_class("IO", rb_cObject); rb_include_module(rb_cIO, rb_mEnumerable); - rb_define_singleton_method(rb_cIO, "allocate", rb_io_s_alloc, 0); + rb_define_alloc_func(rb_cIO, io_alloc); rb_define_singleton_method(rb_cIO, "new", rb_io_s_new, -1); rb_define_singleton_method(rb_cIO, "open", rb_io_s_open, -1); rb_define_singleton_method(rb_cIO, "sysopen", rb_io_s_sysopen, -1); -- cgit