summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-20 08:33:17 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-20 08:33:17 +0000
commitbc49bc7c6b6a16d725cd1279e9021465b1307f3d (patch)
tree023b7da77738e7e049de5002eade542b7f17e930 /io.c
parentb702ab5d6cf585ac0ff0cad3cd5aebbc40e82de0 (diff)
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@3188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/io.c b/io.c
index 6c8379802a..8987fd3057 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;
@@ -2780,18 +2788,6 @@ prep_path(io, 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;
VALUE *argv;
@@ -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);