1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

io.c: move RFile initialization

* io.c (rb_io_make_open_file): move from include/ruby/io.h, and
  hide too detailed implementations.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-10-10 02:34:24 +00:00
parent 0d3d17b907
commit b44c47d102
2 changed files with 59 additions and 35 deletions

View file

@ -119,49 +119,19 @@ typedef struct rb_io_t {
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
#define RB_IO_BUFFER_INIT(buf) do {\
(buf).ptr = NULL;\
(buf).off = 0;\
(buf).len = 0;\
(buf).capa = 0;\
[<"internal macro RB_IO_BUFFER_INIT() is used">];\
} while (0)
#define MakeOpenFile(obj, fp) do {\
if (RFILE(obj)->fptr) {\
rb_io_close(obj);\
rb_io_fptr_finalize(RFILE(obj)->fptr);\
RFILE(obj)->fptr = 0;\
}\
(fp) = 0;\
RB_IO_FPTR_NEW(fp);\
RFILE(obj)->fptr = (fp);\
(fp) = rb_io_make_open_file(obj);\
} while (0)
#define RB_IO_FPTR_NEW(fp) do {\
(fp) = ALLOC(rb_io_t);\
(fp)->fd = -1;\
(fp)->stdio_file = NULL;\
(fp)->mode = 0;\
(fp)->pid = 0;\
(fp)->lineno = 0;\
(fp)->pathv = Qnil;\
(fp)->finalize = 0;\
RB_IO_BUFFER_INIT((fp)->wbuf);\
RB_IO_BUFFER_INIT((fp)->rbuf);\
RB_IO_BUFFER_INIT((fp)->cbuf);\
(fp)->readconv = NULL;\
(fp)->writeconv = NULL;\
(fp)->writeconv_asciicompat = Qnil;\
(fp)->writeconv_pre_ecflags = 0;\
(fp)->writeconv_pre_ecopts = Qnil;\
(fp)->writeconv_initialized = 0;\
(fp)->tied_io_for_writing = 0;\
(fp)->encs.enc = NULL;\
(fp)->encs.enc2 = NULL;\
(fp)->encs.ecflags = 0;\
(fp)->encs.ecopts = Qnil;\
(fp)->write_lock = 0;\
[<"internal macro RB_IO_FPTR_NEW() is used">];\
} while (0)
rb_io_t *rb_io_make_open_file(VALUE obj);
FILE *rb_io_stdio_file(rb_io_t *fptr);
FILE *rb_fdopen(int, const char*);

54
io.c
View file

@ -7374,6 +7374,60 @@ rb_io_stdio_file(rb_io_t *fptr)
return fptr->stdio_file;
}
static inline void
rb_io_buffer_init(rb_io_buffer_t *buf)
{
buf->ptr = NULL;
buf->off = 0;
buf->len = 0;
buf->capa = 0;
}
static inline rb_io_t *
rb_io_fptr_new(void)
{
rb_io_t *fp = ALLOC(rb_io_t);
fp->fd = -1;
fp->stdio_file = NULL;
fp->mode = 0;
fp->pid = 0;
fp->lineno = 0;
fp->pathv = Qnil;
fp->finalize = 0;
rb_io_buffer_init(&fp->wbuf);
rb_io_buffer_init(&fp->rbuf);
rb_io_buffer_init(&fp->cbuf);
fp->readconv = NULL;
fp->writeconv = NULL;
fp->writeconv_asciicompat = Qnil;
fp->writeconv_pre_ecflags = 0;
fp->writeconv_pre_ecopts = Qnil;
fp->writeconv_initialized = 0;
fp->tied_io_for_writing = 0;
fp->encs.enc = NULL;
fp->encs.enc2 = NULL;
fp->encs.ecflags = 0;
fp->encs.ecopts = Qnil;
fp->write_lock = 0;
return fp;
}
rb_io_t *
rb_io_make_open_file(VALUE obj)
{
rb_io_t *fp = 0;
Check_Type(obj, T_FILE);
if (RFILE(obj)->fptr) {
rb_io_close(obj);
rb_io_fptr_finalize(RFILE(obj)->fptr);\
RFILE(obj)->fptr = 0;
}
fp = rb_io_fptr_new();
RFILE(obj)->fptr = fp;
return fp;
}
/*
* call-seq:
* IO.new(fd [, mode] [, opt]) -> io