diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-30 09:36:41 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-30 09:36:41 +0000 |
commit | 1a8ccefafc490875a90515907f05a565c4c8f7ba (patch) | |
tree | 68dd6036eca5931bd9c70030d9df7bfbe1a1c6cd /io.c | |
parent | cf22db8d6910a428b2bb51b3c78c34b86d83bf74 (diff) | |
download | ruby-1a8ccefafc490875a90515907f05a565c4c8f7ba.tar.gz |
* io.c (READ_DATA_BUFFERED): new macro to detect whether stdio
buffer filled.
* io.c (rb_io_fptr_cleanup): move path deallocation to
rb_io_fptr_finalize (finalizer called by GC).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -140,6 +140,10 @@ static VALUE lineno; /* requires systems own version of the ReadDataPending() */ extern int ReadDataPending(); # define READ_DATA_PENDING(fp) (!feof(fp)) +# define READ_DATA_BUFFERED(fp) 0 +#endif +#ifndef READ_DATA_BUFFERED +# define READ_DATA_BUFFERED(fp) READ_DATA_PENDING(fp) #endif #ifndef READ_DATA_PENDING_PTR @@ -1366,11 +1370,6 @@ rb_io_fptr_cleanup(fptr, noraise) else { fptr_finalize(fptr, noraise); } - - if (fptr->path) { - free(fptr->path); - fptr->path = 0; - } } void @@ -1378,6 +1377,9 @@ rb_io_fptr_finalize(fptr) OpenFile *fptr; { if (!fptr) return; + if (fptr->path) { + free(fptr->path); + } if (!fptr->f && !fptr->f2) return; if (fileno(fptr->f) < 3) return; @@ -1510,7 +1512,7 @@ rb_io_sysseek(argc, argv, io) } GetOpenFile(io, fptr); - if ((fptr->mode & FMODE_READABLE) && READ_DATA_PENDING(fptr->f)) { + if ((fptr->mode & FMODE_READABLE) && READ_DATA_BUFFERED(fptr->f)) { rb_raise(rb_eIOError, "sysseek for buffered IO"); } if ((fptr->mode & FMODE_WRITABLE) && (fptr->mode & FMODE_WBUF)) { @@ -1567,7 +1569,7 @@ rb_io_sysread(argc, argv, io) GetOpenFile(io, fptr); rb_io_check_readable(fptr); - if (READ_DATA_PENDING(fptr->f)) { + if (READ_DATA_BUFFERED(fptr->f)) { rb_raise(rb_eIOError, "sysread for buffered IO"); } if (NIL_P(str)) { |