summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-18 13:58:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-18 13:58:47 +0000
commitc6e4767068df673200351c23c203c22731e6102a (patch)
treedb8ab886397ae2326a203223c6009196e7b39ae9 /include
parent9be87b1eb6b320e027919079f6e050f042347205 (diff)
* include/ruby/io.h (rb_io_buffer_t): extract from rb_io_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include')
-rw-r--r--include/ruby/io.h51
1 files changed, 25 insertions, 26 deletions
diff --git a/include/ruby/io.h b/include/ruby/io.h
index 0b1235ec6b..97fb7c6f54 100644
--- a/include/ruby/io.h
+++ b/include/ruby/io.h
@@ -31,6 +31,13 @@ extern "C" {
#pragma GCC visibility push(default)
#endif
+typedef struct {
+ char *ptr; /* off + len <= capa */
+ int off;
+ int len;
+ int capa;
+} rb_io_buffer_t;
+
typedef struct rb_io_t {
int fd; /* file descriptor */
FILE *stdio_file; /* stdio ptr for read/write if available */
@@ -40,15 +47,7 @@ typedef struct rb_io_t {
VALUE pathv; /* pathname for file */
void (*finalize)(struct rb_io_t*,int); /* finalize proc */
- char *wbuf; /* wbuf_off + wbuf_len <= wbuf_capa */
- int wbuf_off;
- int wbuf_len;
- int wbuf_capa;
-
- char *rbuf; /* rbuf_off + rbuf_len <= rbuf_capa */
- int rbuf_off;
- int rbuf_len;
- int rbuf_capa;
+ rb_io_buffer_t wbuf, rbuf;
VALUE tied_io_for_writing;
@@ -66,10 +65,7 @@ typedef struct rb_io_t {
} encs;
rb_econv_t *readconv;
- char *cbuf; /* cbuf_off + cbuf_len <= cbuf_capa */
- int cbuf_off;
- int cbuf_len;
- int cbuf_capa;
+ rb_io_buffer_t cbuf;
rb_econv_t *writeconv;
VALUE writeconv_asciicompat;
@@ -101,6 +97,13 @@ 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;\
+} while (0)
+
#define MakeOpenFile(obj, fp) do {\
if (RFILE(obj)->fptr) {\
rb_io_close(obj);\
@@ -108,7 +111,12 @@ typedef struct rb_io_t {
RFILE(obj)->fptr = 0;\
}\
fp = 0;\
- fp = RFILE(obj)->fptr = ALLOC(rb_io_t);\
+ RB_IO_FPTR_NEW(fp);\
+ RFILE(obj)->fptr = fp;\
+} while (0)
+
+#define RB_IO_FPTR_NEW(fp) do {\
+ fp = ALLOC(rb_io_t);\
fp->fd = -1;\
fp->stdio_file = NULL;\
fp->mode = 0;\
@@ -116,19 +124,10 @@ typedef struct rb_io_t {
fp->lineno = 0;\
fp->pathv = Qnil;\
fp->finalize = 0;\
- fp->wbuf = NULL;\
- fp->wbuf_off = 0;\
- fp->wbuf_len = 0;\
- fp->wbuf_capa = 0;\
- fp->rbuf = NULL;\
- fp->rbuf_off = 0;\
- fp->rbuf_len = 0;\
- fp->rbuf_capa = 0;\
+ RB_IO_BUFFER_INIT(fp->wbuf);\
+ RB_IO_BUFFER_INIT(fp->rbuf);\
+ RB_IO_BUFFER_INIT(fp->cbuf);\
fp->readconv = NULL;\
- fp->cbuf = NULL;\
- fp->cbuf_off = 0;\
- fp->cbuf_len = 0;\
- fp->cbuf_capa = 0;\
fp->writeconv = NULL;\
fp->writeconv_asciicompat = Qnil;\
fp->writeconv_pre_ecflags = 0;\