[前][次][番号順一覧][スレッド一覧]

ruby-changes:35781

From: nobu <ko1@a...>
Date: Fri, 10 Oct 2014 11:34:30 +0900 (JST)
Subject: [ruby-changes:35781] nobu:r47863 (trunk): io.c: move RFile initialization

nobu	2014-10-10 11:34:24 +0900 (Fri, 10 Oct 2014)

  New Revision: 47863

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47863

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

  Modified files:
    trunk/include/ruby/io.h
    trunk/io.c
Index: include/ruby/io.h
===================================================================
--- include/ruby/io.h	(revision 47862)
+++ include/ruby/io.h	(revision 47863)
@@ -119,49 +119,19 @@ typedef struct rb_io_t { https://github.com/ruby/ruby/blob/trunk/include/ruby/io.h#L119
 #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*);
Index: io.c
===================================================================
--- io.c	(revision 47862)
+++ io.c	(revision 47863)
@@ -7374,6 +7374,60 @@ rb_io_stdio_file(rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/io.c#L7374
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]