summaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-30 09:36:41 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-30 09:36:41 +0000
commita607c82efe3be64a1822ca70ebdcb45cfd5000d2 (patch)
tree68dd6036eca5931bd9c70030d9df7bfbe1a1c6cd /io.c
parentc1f9b6b5159d4c40031ed7d6d3dea4dc6deef5a5 (diff)
downloadruby-a607c82efe3be64a1822ca70ebdcb45cfd5000d2.tar.gz
ruby-a607c82efe3be64a1822ca70ebdcb45cfd5000d2.tar.xz
ruby-a607c82efe3be64a1822ca70ebdcb45cfd5000d2.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@4865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/io.c b/io.c
index ee030e894..cac35eb7e 100644
--- a/io.c
+++ b/io.c
@@ -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)) {