Skip to content

Commit

Permalink
Implement get_bool(), eof(), is_open() in Handle PMC, not its subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
gerdr committed Mar 13, 2013
1 parent ab3776e commit 08b1e99
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 142 deletions.
56 changes: 0 additions & 56 deletions src/pmc/filehandle.pmc
Expand Up @@ -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
Expand Down Expand Up @@ -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)>
Expand Down Expand Up @@ -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.
Expand Down
49 changes: 49 additions & 0 deletions src/pmc/handle.pmc
Expand Up @@ -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
Expand All @@ -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
Expand Down
31 changes: 0 additions & 31 deletions src/pmc/socket.pmc
Expand Up @@ -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
Expand Down Expand Up @@ -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)>
Expand Down
55 changes: 0 additions & 55 deletions src/pmc/stringhandle.pmc
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 08b1e99

Please sign in to comment.