Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement get_bool(), eof(), is_open() in Handle PMC, not its subclasses

  • Loading branch information...
commit 08b1e99e3e34c78b023d09f31078a65fe85ae453 1 parent ab3776e
@gerdr authored
View
56 src/pmc/filehandle.pmc
@@ -214,26 +214,6 @@ For internal usage only, subject to change without notice.
}
}
-
-/*
-
-=item C<INTVAL get_bool()>
-
-Return false if a previous read attempted to read past the end of the underlying
-filehandle. Note that this method may return true even if there are no bytes
-remaining if the most recent read requested the exact number of bytes remaining
-in the file.
-
-
-=cut
-
-*/
-
- VTABLE INTVAL get_bool() {
- return !Parrot_io_eof(INTERP, SELF);
- }
-
-
/*
=back
@@ -311,23 +291,6 @@ Returns a boolean value indicating whether C<SELF> is a console/tty.
RETURN(INTVAL isatty);
}
-
-/*
-
-=item C<METHOD is_closed()>
-
-Test if the filehandle is closed.
-
-=cut
-
-*/
-
- METHOD is_closed() {
- const INTVAL status = Parrot_io_is_closed(INTERP, SELF);
- RETURN(INTVAL status);
- }
-
-
/*
=item C<METHOD readline_interactive(STRING *prompt)>
@@ -553,25 +516,6 @@ Retrieve the read mode string for the filehandle.
/*
-=item C<METHOD eof()>
-
-Return true if a previous read attempted to read past the end of the underlying
-filehandle. Note that this method may return false even if there are no bytes
-remaining if the most recent read requested the exact number of bytes remaining
-in the file.
-
-=cut
-
-*/
-
- METHOD eof() {
- const INTVAL flags = Parrot_io_eof(INTERP, SELF);
- RETURN(INTVAL flags);
- }
-
-
-/*
-
=item C<METHOD handle()>
Returns the INTVAL used by the OS to identify this filehandle.
View
49 src/pmc/handle.pmc
@@ -94,6 +94,22 @@ pmclass Handle provides Handle manual_attrs {
/*
+=item C<INTVAL get_bool()>
+
+Returns whether the Handle is currently open.
+
+=cut
+
+*/
+
+ VTABLE INTVAL get_bool() {
+ const IO_VTABLE *io_vtable;
+ GET_ATTR_io_vtable(INTERP, SELF, io_vtable);
+ return io_vtable->is_open(INTERP, SELF);
+ }
+
+/*
+
=back
=head2 Methods
@@ -116,6 +132,39 @@ subtypes that are or can be tty.
/*
+=item C<METHOD eof()>
+
+Return true if a previous read attempted to read past the end of the underlying
+os handle. Note that this method may return false even if there are no bytes
+remaining if the most recent read requested the exact number of bytes remaining
+in the stream.
+
+=cut
+
+*/
+
+ METHOD eof() {
+ const INTVAL status = Parrot_io_eof(INTERP, SELF);
+ RETURN(INTVAL status);
+ }
+
+/*
+
+=item C<METHOD is_closed()>
+
+Test if the Handle is closed.
+
+=cut
+
+*/
+
+ METHOD is_closed() {
+ const INTVAL status = Parrot_io_is_closed(INTERP, SELF);
+ RETURN(INTVAL status);
+ }
+
+/*
+
=item C<METHOD get_fd()>
Retrieve the integer file descriptor for the Handle (only available on
View
31 src/pmc/socket.pmc
@@ -121,20 +121,6 @@ Free structures.
/*
-=item C<INTVAL get_bool()>
-
-Returns whether the Socket is currently open.
-
-=cut
-
-*/
-
- VTABLE INTVAL get_bool() {
- return !Parrot_io_is_closed(INTERP, SELF);
- }
-
-/*
-
=back
=head2 Methods
@@ -248,23 +234,6 @@ C<local_address> returns the local address of this socket PMC.
RETURN(PMC * res);
}
-
-/*
-
-=item C<METHOD is_closed()>
-
-Test if the socket is closed.
-
-=cut
-
-*/
-
- METHOD is_closed() {
- const INTVAL status = !VTABLE_get_bool(INTERP, SELF);
- RETURN(INTVAL status);
- }
-
-
/*
=item C<getprotobyname(STRING * name)>
View
55 src/pmc/stringhandle.pmc
@@ -143,27 +143,6 @@ Mark active stringhandle data as live.
/*
-=item C<INTVAL get_bool()>
-
-Returns whether the StringHandle has reached the end of the file.
-
-=cut
-
-*/
-
- VTABLE INTVAL get_bool() {
- STRING *stringhandle;
- GET_ATTR_stringhandle(INTERP, SELF, stringhandle);
-
- if (STRING_IS_NULL(stringhandle))
- return 0;
-
- return 1;
- }
-
-
-/*
-
=back
=head2 Methods
@@ -196,23 +175,6 @@ stored for mocking.
RETURN(PMC *handle);
}
-
-/*
-
-=item C<METHOD is_closed()>
-
-Check if the StringHandle is open.
-
-=cut
-
-*/
-
- METHOD is_closed() {
- const INTVAL closed = Parrot_io_is_closed(INTERP, SELF);
- RETURN(INTVAL closed);
- }
-
-
/*
=item METHOD readall(STRING *name);
@@ -366,23 +328,6 @@ Retrieve the read mode string for the stringhandle.
/*
-=item C<METHOD eof()>
-
-Check if the StringHandle is at end-of-file (if it has read to the end of the
-string data).
-
-=cut
-
-*/
-
- METHOD eof() {
- const INTVAL is_eof = Parrot_io_eof(INTERP, SELF);
- RETURN(INTVAL 0);
- }
-
-
-/*
-
=item C<METHOD get_fd()>
StringHandles do not use integer file descriptors, so always returns an error
Please sign in to comment.
Something went wrong with that request. Please try again.